fog-sakuracloud 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +65 -0
  3. data/.gitmodules +3 -0
  4. data/.travis.yml +9 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +35 -0
  8. data/Rakefile +113 -0
  9. data/fog-sakuracloud.gemspec +41 -0
  10. data/gemfiles/Gemfile.1.8.7 +6 -0
  11. data/lib/fog/sakuracloud.rb +16 -0
  12. data/lib/fog/sakuracloud/compute.rb +65 -0
  13. data/lib/fog/sakuracloud/models/compute/plan.rb +15 -0
  14. data/lib/fog/sakuracloud/models/compute/plans.rb +22 -0
  15. data/lib/fog/sakuracloud/models/compute/server.rb +40 -0
  16. data/lib/fog/sakuracloud/models/compute/servers.rb +63 -0
  17. data/lib/fog/sakuracloud/models/compute/ssh_key.rb +13 -0
  18. data/lib/fog/sakuracloud/models/compute/ssh_keys.rb +22 -0
  19. data/lib/fog/sakuracloud/models/compute/zone.rb +13 -0
  20. data/lib/fog/sakuracloud/models/compute/zones.rb +22 -0
  21. data/lib/fog/sakuracloud/models/volume/archive.rb +14 -0
  22. data/lib/fog/sakuracloud/models/volume/archives.rb +22 -0
  23. data/lib/fog/sakuracloud/models/volume/disk.rb +37 -0
  24. data/lib/fog/sakuracloud/models/volume/disks.rb +27 -0
  25. data/lib/fog/sakuracloud/models/volume/plan.rb +12 -0
  26. data/lib/fog/sakuracloud/models/volume/plans.rb +22 -0
  27. data/lib/fog/sakuracloud/requests/compute/boot_server.rb +31 -0
  28. data/lib/fog/sakuracloud/requests/compute/create_server.rb +41 -0
  29. data/lib/fog/sakuracloud/requests/compute/delete_server.rb +33 -0
  30. data/lib/fog/sakuracloud/requests/compute/list_plans.rb +46 -0
  31. data/lib/fog/sakuracloud/requests/compute/list_servers.rb +44 -0
  32. data/lib/fog/sakuracloud/requests/compute/list_ssh_keys.rb +40 -0
  33. data/lib/fog/sakuracloud/requests/compute/list_zones.rb +40 -0
  34. data/lib/fog/sakuracloud/requests/compute/stop_server.rb +37 -0
  35. data/lib/fog/sakuracloud/requests/volume/attach_disk.rb +30 -0
  36. data/lib/fog/sakuracloud/requests/volume/configure_disk.rb +35 -0
  37. data/lib/fog/sakuracloud/requests/volume/create_disk.rb +43 -0
  38. data/lib/fog/sakuracloud/requests/volume/delete_disk.rb +30 -0
  39. data/lib/fog/sakuracloud/requests/volume/list_archives.rb +46 -0
  40. data/lib/fog/sakuracloud/requests/volume/list_disks.rb +50 -0
  41. data/lib/fog/sakuracloud/requests/volume/list_plans.rb +40 -0
  42. data/lib/fog/sakuracloud/version.rb +5 -0
  43. data/lib/fog/sakuracloud/volume.rb +88 -0
  44. data/tests/helper.rb +8 -0
  45. data/tests/sakuracloud/helper.rb +7 -0
  46. data/tests/sakuracloud/requests/compute/plans_tests.rb +32 -0
  47. data/tests/sakuracloud/requests/compute/servers_tests.rb +46 -0
  48. data/tests/sakuracloud/requests/compute/ssh_keys_tests.rb +30 -0
  49. data/tests/sakuracloud/requests/compute/zones_tests.rb +30 -0
  50. data/tests/sakuracloud/requests/volume/archives_tests.rb +31 -0
  51. data/tests/sakuracloud/requests/volume/disks_tests.rb +47 -0
  52. data/tests/sakuracloud/requests/volume/plans_tests.rb +30 -0
  53. metadata +326 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ed75288a350cf5fddfb7be6b8cec20c719c57e7e
4
+ data.tar.gz: 30c74a9708e0ebbc50c80b701acda8dc90b78694
5
+ SHA512:
6
+ metadata.gz: dde3f7b5d2c726eb5e02cf697927bd095ba13aa675a2e955601770e737ea8f557245b4b4c637b424c93afe5b7b975615697cea3432cc1b19002e23b0329de70e
7
+ data.tar.gz: 2add386c08124e45fd673dbe57c5ea177063b8ae68a663c697ed87b82f013b7ff615bc637c5f3b201bf216b3e81a6a8e2d3239e45aedea48029c03ab872cdc90
data/.gitignore ADDED
@@ -0,0 +1,65 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ # Created by http://www.gitignore.io
16
+
17
+ ### Ruby ###
18
+ *.gem
19
+ *.rbc
20
+ /.config
21
+ /coverage/
22
+ /InstalledFiles
23
+ /pkg/
24
+ /spec/reports/
25
+ /test/tmp/
26
+ /test/version_tmp/
27
+ /tmp/
28
+
29
+ ## Specific to RubyMotion:
30
+ .dat*
31
+ .repl_history
32
+ build/
33
+
34
+ ## Documentation cache and generated files:
35
+ /.yardoc/
36
+ /_yardoc/
37
+ /doc/
38
+ /rdoc/
39
+
40
+ ## Environment normalisation:
41
+ /.bundle/
42
+ /lib/bundler/man/
43
+
44
+ # for a library or gem, you might want to ignore these files since the code is
45
+ # intended to run in multiple environments; otherwise, check them in:
46
+ # Gemfile.lock
47
+ # .ruby-version
48
+ # .ruby-gemset
49
+
50
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
51
+ .rvmrc
52
+
53
+
54
+ ### vim ###
55
+ [._]*.s[a-w][a-z]
56
+ [._]s[a-w][a-z]
57
+ *.un~
58
+ Session.vim
59
+ .netrwhist
60
+ *~
61
+
62
+ .fog
63
+ /vendor/
64
+ /bbin/
65
+
data/.gitmodules ADDED
@@ -0,0 +1,3 @@
1
+ [submodule "fog"]
2
+ path = fog
3
+ url = https://github.com/fog/fog.git
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+
3
+ script: bundle exec rake travis
4
+
5
+ rvm:
6
+ - 2.1.2
7
+ - 2.1.1
8
+ - 2.0.0
9
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fog-sakuracloud.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 sawanoboly
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Fog::Sakuracloud
2
+
3
+ [![Build Status](https://travis-ci.org/higanworks/fog-sakuracloud.svg?branch=master)](https://travis-ci.org/higanworks/fog-sakuracloud)
4
+
5
+ This gem is a module for the fog gem that allows you to manage resources in the Sakura no Cloud.
6
+
7
+ (unstable)
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'fog-sakuracloud'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install fog-sakuracloud
24
+
25
+ ## Usage
26
+
27
+ See [Getting started](https://github.com/higanworks/fog-sakuracloud/wiki/Getting-started-for-SakuraCloud)
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it ( https://github.com/[my-github-username]/fog-sakuracloud/fork )
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,113 @@
1
+ require 'bundler/setup'
2
+ require "bundler/gem_tasks"
3
+ require 'rake/testtask'
4
+ require 'date'
5
+ require 'rubygems'
6
+ require 'rubygems/package_task'
7
+ require 'yard'
8
+ require 'fog'
9
+ # require File.dirname(__FILE__) + '/fog/lib/fog'
10
+
11
+ #############################################################################
12
+ #
13
+ # Helper functions
14
+ #
15
+ #############################################################################
16
+
17
+ def name
18
+ @name ||= Dir['*.gemspec'].first.split('.').first
19
+ end
20
+
21
+ def version
22
+ Fog::VERSION
23
+ end
24
+
25
+ def date
26
+ Date.today.to_s
27
+ end
28
+
29
+ def rubyforge_project
30
+ name
31
+ end
32
+
33
+ def gemspec_file
34
+ "#{name}.gemspec"
35
+ end
36
+
37
+ def gem_file
38
+ "#{name}-#{version}.gem"
39
+ end
40
+
41
+ def replace_header(head, header_name)
42
+ head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
43
+ end
44
+
45
+ #############################################################################
46
+ #
47
+ # Standard tasks
48
+ #
49
+ #############################################################################
50
+
51
+ GEM_NAME = "#{name}"
52
+ task :default => :test
53
+ task :travis => ['test', 'test:travis']
54
+
55
+ Rake::TestTask.new do |t|
56
+ t.pattern = File.join("spec", "**", "*_spec.rb")
57
+ end
58
+
59
+ namespace :test do
60
+ mock = ENV['FOG_MOCK'] || 'true'
61
+ task :travis do
62
+ sh("export FOG_MOCK=#{mock} && bundle exec shindont")
63
+ end
64
+ task :vsphere do
65
+ sh("export FOG_MOCK=#{mock} && bundle exec shindont tests/vsphere")
66
+ end
67
+ task :openvz do
68
+ sh("export FOG_MOCK=#{mock} && bundle exec shindont tests/openvz")
69
+ end
70
+ end
71
+
72
+ desc 'Run mocked tests for a specific provider'
73
+ task :mock, :provider do |t, args|
74
+ if args.to_a.size != 1
75
+ fail 'USAGE: rake mock[<provider>]'
76
+ end
77
+ provider = args[:provider]
78
+ sh("export FOG_MOCK=true && bundle exec shindont tests/#{provider}")
79
+ end
80
+
81
+ desc 'Run live tests against a specific provider'
82
+ task :live, :provider do |t, args|
83
+ if args.to_a.size != 1
84
+ fail 'USAGE: rake live[<provider>]'
85
+ end
86
+ provider = args[:provider]
87
+ sh("export FOG_MOCK=false PROVIDER=#{provider} && bundle exec shindont tests/#{provider}")
88
+ end
89
+
90
+ task :nuke do
91
+ Fog.providers.each do |provider|
92
+ next if ['Vmfusion'].include?(provider)
93
+ begin
94
+ compute = Fog::Compute.new(:provider => provider)
95
+ for server in compute.servers
96
+ Formatador.display_line("[#{provider}] destroying server #{server.identity}")
97
+ server.destroy rescue nil
98
+ end
99
+ rescue
100
+ end
101
+ begin
102
+ dns = Fog::DNS.new(:provider => provider)
103
+ for zone in dns.zones
104
+ for record in zone.records
105
+ record.destroy rescue nil
106
+ end
107
+ Formatador.display_line("[#{provider}] destroying zone #{zone.identity}")
108
+ zone.destroy rescue nil
109
+ end
110
+ rescue
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,41 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fog/sakuracloud/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fog-sakuracloud"
8
+ spec.version = Fog::Sakuracloud::VERSION
9
+ spec.authors = ["sawanoboly"]
10
+ spec.email = ["sawanoboriyu@higanworks.com"]
11
+ spec.summary = %q{Module for the 'fog' gem to support Sakura no Cloud}
12
+ spec.description = %q{Module for the 'fog' gem to support Sakura no Cloud}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "fog-core"
22
+ spec.add_dependency "fog-json"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.5"
25
+ ## List your development dependencies here. Development dependencies are
26
+ ## those that are only needed during development
27
+ spec.add_development_dependency('fog')
28
+ spec.add_development_dependency('minitest')
29
+ spec.add_development_dependency('rake')
30
+ spec.add_development_dependency('rbvmomi')
31
+ spec.add_development_dependency('yard')
32
+ spec.add_development_dependency('thor')
33
+ spec.add_development_dependency('rbovirt', '0.0.24')
34
+ spec.add_development_dependency('shindo', '~> 0.3.4')
35
+ spec.add_development_dependency('fission')
36
+ spec.add_development_dependency('pry')
37
+ spec.add_development_dependency('opennebula', '>=4.4.0')
38
+ spec.add_development_dependency('google-api-client', '~> 0.6', '>= 0.6.2')
39
+ spec.add_development_dependency('rubocop') if RUBY_VERSION > "1.9"
40
+
41
+ end
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "fog-core", :github => "fog/fog-core"
4
+ gem "mime-types", "~> 1.22"
5
+
6
+ gemspec :path => ".."
@@ -0,0 +1,16 @@
1
+ require 'fog/core'
2
+ require 'fog/sakuracloud/compute'
3
+ require 'fog/sakuracloud/volume'
4
+
5
+ module Fog
6
+ module SakuraCloud
7
+ extend Fog::Provider
8
+
9
+ SAKURACLOUD_API_VERSION = '1.1' unless defined? SAKURACLOUD_API_VERSION
10
+ SAKURACLOUD_API_ZONE = "is1b" unless defined? SAKURACLOUD_API_ZONE
11
+ SAKURACLOUD_API_ENDPOINT = "/cloud/zone/#{SAKURACLOUD_API_ZONE}/api/cloud/#{SAKURACLOUD_API_VERSION}/"
12
+
13
+ service(:compute, 'Compute')
14
+ service(:volume, 'Volume')
15
+ end
16
+ end
@@ -0,0 +1,65 @@
1
+ require 'fog/sakuracloud'
2
+ require 'fog/compute'
3
+
4
+ module Fog
5
+ module Compute
6
+ class SakuraCloud < Fog::Service
7
+ requires :sakuracloud_api_token
8
+ requires :sakuracloud_api_token_secret
9
+
10
+ recognizes :sakuracloud_api_url
11
+
12
+ model_path 'fog/sakuracloud/models/compute'
13
+ model :server
14
+ collection :servers
15
+ model :plan
16
+ collection :plans
17
+ model :ssh_key
18
+ collection :ssh_keys
19
+ model :zone
20
+ collection :zones
21
+
22
+ request_path 'fog/sakuracloud/requests/compute'
23
+ request :list_servers
24
+ request :create_server
25
+ request :delete_server
26
+ request :boot_server
27
+ request :stop_server
28
+ request :list_plans
29
+ request :list_ssh_keys
30
+ request :list_zones
31
+
32
+ class Real
33
+ def initialize(options = {})
34
+ @auth_encord = Base64.strict_encode64([
35
+ options[:sakuracloud_api_token],
36
+ options[:sakuracloud_api_token_secret]
37
+ ].join(':'))
38
+ Fog.credentials[:sakuracloud_api_token] = options[:sakuracloud_api_token]
39
+ Fog.credentials[:sakuracloud_api_token_secret] = options[:sakuracloud_api_token_secret]
40
+
41
+ @sakuracloud_api_url = options[:sakuracloud_api_url] || 'https://secure.sakura.ad.jp'
42
+
43
+ @connection = Fog::Core::Connection.new(@sakuracloud_api_url)
44
+ end
45
+
46
+ def request(params)
47
+ response = parse @connection.request(params)
48
+ response
49
+ end
50
+
51
+ private
52
+ def parse(response)
53
+ return response if response.body.empty?
54
+ response.body = Fog::JSON.decode(response.body)
55
+ response
56
+ end
57
+ end
58
+
59
+ class Mock
60
+ def initialize(options = {})
61
+ end
62
+ end
63
+ end #SakuraCloud
64
+ end #Compute
65
+ end
@@ -0,0 +1,15 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module Compute
5
+ class SakuraCloud
6
+ class Plan < Fog::Model
7
+ identity :id, :aliases => 'ID'
8
+ attribute :name, :aliases => 'Name'
9
+ attribute :server_class, :aliases => 'ServiceClass'
10
+ attribute :cpu, :aliases => 'CPU'
11
+ attribute :memory_mb, :aliases => 'MemoryMB'
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,22 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/sakuracloud/models/compute/plan'
3
+
4
+ module Fog
5
+ module Compute
6
+ class SakuraCloud
7
+ class Plans < Fog::Collection
8
+ model Fog::Compute::SakuraCloud::Plan
9
+
10
+ def all
11
+ load service.list_plans.body['ServerPlans']
12
+ end
13
+
14
+ def get(id)
15
+ all.find { |f| f.id == id }
16
+ rescue Fog::Errors::NotFound
17
+ nil
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end