vagrant-sakura 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,77 @@
1
+ require 'net/https'
2
+ require 'json'
3
+
4
+ module VagrantPlugins
5
+ module Sakura
6
+ module Driver
7
+ APIHOST = "secure.sakura.ad.jp"
8
+ APIPREFIX = "/cloud/api/cloud/1.0"
9
+ CERTFILE = File.expand_path("../cert.pem", __FILE__)
10
+
11
+ class API
12
+ def initialize(access_token, access_token_secret)
13
+ @logger = Log4r::Logger.new("vagrant::provider::sakura")
14
+
15
+ @access_token = access_token
16
+ @access_token_secret = access_token_secret
17
+
18
+ @https = Net::HTTP.new(APIHOST, 443)
19
+ @https.use_ssl = true
20
+ @https.ca_file = CERTFILE
21
+ @https.verify_mode = OpenSSL::SSL::VERIFY_PEER
22
+ @https.verify_depth = 2
23
+ end
24
+
25
+ def delete(resource, data = nil)
26
+ request = Net::HTTP::Delete.new(APIPREFIX + resource)
27
+ request.body = data.to_json if data
28
+ do_request request
29
+ end
30
+
31
+ def get(resource, data = nil)
32
+ request = Net::HTTP::Get.new(APIPREFIX + resource)
33
+ request.body = data.to_json if data
34
+ do_request request
35
+ end
36
+
37
+ def post(resource, data)
38
+ request = Net::HTTP::Post.new(APIPREFIX + resource)
39
+ request.body = data.to_json
40
+ do_request request
41
+ end
42
+
43
+ def put(resource, data = nil)
44
+ request = Net::HTTP::Put.new(APIPREFIX + resource)
45
+ request.body = if data then data.to_json else '' end
46
+ do_request request
47
+ end
48
+
49
+ def do_request(request)
50
+ request.basic_auth @access_token, @access_token_secret
51
+ response = @https.request(request)
52
+ @logger.debug("#{request.method} #{request.path} #{request.body} "+
53
+ "=> #{response.code} : #{response.body}")
54
+
55
+ emsg = "#{response.code} (#{request.method} #{request.path})"
56
+ case response.code
57
+ when /2../
58
+ # Success
59
+ when "404"
60
+ raise NotFoundError, emsg
61
+ when "409"
62
+ raise ConflictError, emsg
63
+ else
64
+ raise GenericError, emsg
65
+ end
66
+
67
+ JSON.parse response.body
68
+ end
69
+ private :do_request
70
+ end
71
+
72
+ class ConflictError < RuntimeError; end
73
+ class GenericError < RuntimeError; end
74
+ class NotFoundError < RuntimeError; end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,76 @@
1
+ Certificate:
2
+ Data:
3
+ Version: 3 (0x2)
4
+ Serial Number: 0 (0x0)
5
+ Signature Algorithm: sha1WithRSAEncryption
6
+ Issuer: C=JP, O=SECOM Trust.net, OU=Security Communication RootCA1
7
+ Validity
8
+ Not Before: Sep 30 04:20:49 2003 GMT
9
+ Not After : Sep 30 04:20:49 2023 GMT
10
+ Subject: C=JP, O=SECOM Trust.net, OU=Security Communication RootCA1
11
+ Subject Public Key Info:
12
+ Public Key Algorithm: rsaEncryption
13
+ RSA Public Key: (2048 bit)
14
+ Modulus (2048 bit):
15
+ 00:b3:b3:fe:7f:d3:6d:b1:ef:16:7c:57:a5:0c:6d:
16
+ 76:8a:2f:4b:bf:64:fb:4c:ee:8a:f0:f3:29:7c:f5:
17
+ ff:ee:2a:e0:e9:e9:ba:5b:64:22:9a:9a:6f:2c:3a:
18
+ 26:69:51:05:99:26:dc:d5:1c:6a:71:c6:9a:7d:1e:
19
+ 9d:dd:7c:6c:c6:8c:67:67:4a:3e:f8:71:b0:19:27:
20
+ a9:09:0c:a6:95:bf:4b:8c:0c:fa:55:98:3b:d8:e8:
21
+ 22:a1:4b:71:38:79:ac:97:92:69:b3:89:7e:ea:21:
22
+ 68:06:98:14:96:87:d2:61:36:bc:6d:27:56:9e:57:
23
+ ee:c0:c0:56:fd:32:cf:a4:d9:8e:c2:23:d7:8d:a8:
24
+ f3:d8:25:ac:97:e4:70:38:f4:b6:3a:b4:9d:3b:97:
25
+ 26:43:a3:a1:bc:49:59:72:4c:23:30:87:01:58:f6:
26
+ 4e:be:1c:68:56:66:af:cd:41:5d:c8:b3:4d:2a:55:
27
+ 46:ab:1f:da:1e:e2:40:3d:db:cd:7d:b9:92:80:9c:
28
+ 37:dd:0c:96:64:9d:dc:22:f7:64:8b:df:61:de:15:
29
+ 94:52:15:a0:7d:52:c9:4b:a8:21:c9:c6:b1:ed:cb:
30
+ c3:95:60:d1:0f:f0:ab:70:f8:df:cb:4d:7e:ec:d6:
31
+ fa:ab:d9:bd:7f:54:f2:a5:e9:79:fa:d9:d6:76:24:
32
+ 28:73
33
+ Exponent: 65537 (0x10001)
34
+ X509v3 extensions:
35
+ X509v3 Subject Key Identifier:
36
+ A0:73:49:99:68:DC:85:5B:65:E3:9B:28:2F:57:9F:BD:33:BC:07:48
37
+ X509v3 Key Usage:
38
+ Certificate Sign, CRL Sign
39
+ X509v3 Basic Constraints: critical
40
+ CA:TRUE
41
+ Signature Algorithm: sha1WithRSAEncryption
42
+ 68:40:a9:a8:bb:e4:4f:5d:79:b3:05:b5:17:b3:60:13:eb:c6:
43
+ 92:5d:e0:d1:d3:6a:fe:fb:be:9b:6d:bf:c7:05:6d:59:20:c4:
44
+ 1c:f0:b7:da:84:58:02:63:fa:48:16:ef:4f:a5:0b:f7:4a:98:
45
+ f2:3f:9e:1b:ad:47:6b:63:ce:08:47:eb:52:3f:78:9c:af:4d:
46
+ ae:f8:d5:4f:cf:9a:98:2a:10:41:39:52:c4:dd:d9:9b:0e:ef:
47
+ 93:01:ae:b2:2e:ca:68:42:24:42:6c:b0:b3:3a:3e:cd:e9:da:
48
+ 48:c4:15:cb:e9:f9:07:0f:92:50:49:8a:dd:31:97:5f:c9:e9:
49
+ 37:aa:3b:59:65:97:94:32:c9:b3:9f:3e:3a:62:58:c5:49:ad:
50
+ 62:0e:71:a5:32:aa:2f:c6:89:76:43:40:13:13:67:3d:a2:54:
51
+ 25:10:cb:f1:3a:f2:d9:fa:db:49:56:bb:a6:fe:a7:41:35:c3:
52
+ e0:88:61:c9:88:c7:df:36:10:22:98:59:ea:b0:4a:fb:56:16:
53
+ 73:6e:ac:4d:f7:22:a1:4f:ad:1d:7a:2d:45:27:e5:30:c1:5e:
54
+ f2:da:13:cb:25:42:51:95:47:03:8c:6c:21:cc:74:42:ed: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72
+ Uj94nK9NrvjVT8+amCoQQTlSxN3Zmw7vkwGusi7KaEIkQmywszo+zenaSMQVy+n5
73
+ Bw+SUEmK3TGXX8npN6o7WWWXlDLJs58+OmJYxUmtYg5xpTKqL8aJdkNAExNnPaJU
74
+ JRDL8Try2frbSVa7pv6nQTXD4IhhyYjH3zYQIphZ6rBK+1YWc26sTfcioU+tHXot
75
+ RSflMMFe8toTyyVCUZVHA4xsIcx0Qu1T/zOLjw9XARYvz6buyXAiFL39vmwLAw==
76
+ -----END CERTIFICATE-----
@@ -0,0 +1,19 @@
1
+ require "vagrant"
2
+
3
+ module VagrantPlugins
4
+ module Sakura
5
+ module Errors
6
+ class VagrantSakuraError < Vagrant::Errors::VagrantError
7
+ error_namespace("vagrant_sakura.errors")
8
+ end
9
+
10
+ class InstanceReadyTimeout < VagrantSakuraError
11
+ error_key(:instance_ready_timeout)
12
+ end
13
+
14
+ class RsyncError < VagrantSakuraError
15
+ error_key(:rsync_error)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,53 @@
1
+ require "log4r"
2
+ require "vagrant"
3
+
4
+ module VagrantPlugins
5
+ module Sakura
6
+ class Plugin < Vagrant.plugin("2")
7
+ name "Sakura"
8
+ description <<-DESC
9
+ This plugin installs a provider that allows Vagrant to manage
10
+ server instances in Sakura Cloud.
11
+ DESC
12
+
13
+ config(:sakura, :provider) do
14
+ require_relative "config"
15
+ Config
16
+ end
17
+
18
+ provider(:sakura) do
19
+ setup_i18n
20
+ setup_logging
21
+
22
+ require_relative "provider"
23
+ Provider
24
+ end
25
+
26
+ # command(:'sakura-plans') do
27
+ # require_relative "command"
28
+ # Command
29
+ # end
30
+
31
+ def self.setup_i18n
32
+ I18n.load_path << File.expand_path("locales/en.yml", Sakura.source_root)
33
+ I18n.reload!
34
+ end
35
+
36
+ def self.setup_logging
37
+ level = nil
38
+ begin
39
+ level = Log4r.const_get(ENV["VAGRANT_LOG"].upcase)
40
+ level = nil if !level.is_a?(Integer)
41
+ rescue NameError
42
+ end
43
+
44
+ if level
45
+ logger = Log4r::Logger.new("vagrant_sakura")
46
+ logger.outputters = Log4r::Outputter.stderr
47
+ logger.level = level
48
+ logger = nil
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,31 @@
1
+ require "log4r"
2
+ require "vagrant"
3
+
4
+ module VagrantPlugins
5
+ module Sakura
6
+ class Provider < Vagrant.plugin("2", :provider)
7
+ def initialize(machine)
8
+ @machine = machine
9
+ end
10
+
11
+ def action(name)
12
+ action_method = "action_#{name}"
13
+ return Action.send(action_method) if Action.respond_to?(action_method)
14
+ nil
15
+ end
16
+
17
+ def ssh_info
18
+ env = @machine.action("read_ssh_info")
19
+ env[:machine_ssh_info]
20
+ end
21
+
22
+ def state
23
+ env = @machine.action("read_state")
24
+ state_id = env[:machine_state_id]
25
+ short = state_id.to_s
26
+ long = I18n.t("vagrant_sakura.state_#{short}")
27
+ Vagrant::MachineState.new(state_id.to_sym, short, long)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,5 @@
1
+ module VagrantPlugins
2
+ module Sakura
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,39 @@
1
+ en:
2
+ vagrant_sakura:
3
+ already_created: |-
4
+ The server is already created.
5
+ creating_instance: |-
6
+ Creating a server with the following settings...
7
+ down: |-
8
+ The server is down.
9
+ not_created: |-
10
+ Server is not created. Please run `vagrant up` first.
11
+ power_off: |-
12
+ Turning off power...
13
+ power_on: |-
14
+ Turning on power.
15
+ ready: |-
16
+ Server is booted and ready for use!
17
+ reset: |-
18
+ The server was reloaded.
19
+ state_cleaning: |-
20
+ The server is terminated and cleaning up.
21
+ state_down: |-
22
+ The server is down.
23
+ state_not_created: |-
24
+ The server has not been created yet, or destroyed.
25
+ state_up: |-
26
+ The server is up and running.
27
+ terminating: |-
28
+ Terminating the server...
29
+ will_not_destroy: |-
30
+ The server '%{name}' will not be destroyed, since the confirmation
31
+ was declined.
32
+ waiting_for_ssh: |-
33
+ Waiting for SSH to become available...
34
+
35
+ config:
36
+ access_token_required: |-
37
+ An access token is required via "access_token"
38
+ access_token_secret_required: |-
39
+ An access token secret is required via "access_token_secret"
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-sakura
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tomoyuki Sahara
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Enables Vagrant to manage machines in Sakura Cloud.
42
+ email:
43
+ - sahara@surt.net
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - CHANGELOG.md
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - dummy.box
55
+ - example_box/Vagrantfile
56
+ - example_box/metadata.json
57
+ - lib/vagrant-sakura.rb
58
+ - lib/vagrant-sakura/action.rb
59
+ - lib/vagrant-sakura/action/connect_sakura.rb
60
+ - lib/vagrant-sakura/action/delete_server.rb
61
+ - lib/vagrant-sakura/action/halt.rb
62
+ - lib/vagrant-sakura/action/is_created.rb
63
+ - lib/vagrant-sakura/action/message_already_created.rb
64
+ - lib/vagrant-sakura/action/message_down.rb
65
+ - lib/vagrant-sakura/action/message_not_created.rb
66
+ - lib/vagrant-sakura/action/message_will_not_destroy.rb
67
+ - lib/vagrant-sakura/action/power_on.rb
68
+ - lib/vagrant-sakura/action/read_ssh_info.rb
69
+ - lib/vagrant-sakura/action/read_state.rb
70
+ - lib/vagrant-sakura/action/reset.rb
71
+ - lib/vagrant-sakura/action/run_instance.rb
72
+ - lib/vagrant-sakura/command.rb
73
+ - lib/vagrant-sakura/config.rb
74
+ - lib/vagrant-sakura/driver/api.rb
75
+ - lib/vagrant-sakura/driver/cert.pem
76
+ - lib/vagrant-sakura/errors.rb
77
+ - lib/vagrant-sakura/plugin.rb
78
+ - lib/vagrant-sakura/provider.rb
79
+ - lib/vagrant-sakura/version.rb
80
+ - locales/en.yml
81
+ homepage: ''
82
+ licenses:
83
+ - MIT
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.0.3
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Enables Vagrant to manage machines in Sakura Cloud.
105
+ test_files: []