vagrant-simplecloud 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ee9a4564941ef8ce9b473405f36bf0662c7642b9
4
- data.tar.gz: a16b8b5ea3051cb949c783d552f32a2b83873d99
3
+ metadata.gz: 1747f26a1363d6a480ab95dbe76eca402d220244
4
+ data.tar.gz: d0e56b5a130f84efac577a98b83cc1cf0dc8443b
5
5
  SHA512:
6
- metadata.gz: 653be2c3117f57c4acbc89f35a75a83a76749c89736102819d5a1bfbf816570426682b5ad26f636e129e48ed8ed8a2e51265723c1cf36cae811ac70e6fd0915b
7
- data.tar.gz: 695217d7c25b73c41d565544703e6a849649be4b4f35cc9fda6a26862e8337fc6652d49ab9ca616852cbd8f655a2c1b28c8dd0a8d4929da43bd45507b717020c
6
+ metadata.gz: ddf115270f85be9f4e5bef934b6822504494290e50f4a6bfcc2a6aa561cce87bab864e38e2923d52fc7f26aa336da3b0a7bf9f3c7c79bf526459542f25140d99
7
+ data.tar.gz: 851dd9518b0bd49ae3c406a2cd04134732a5e8ab8364a6ac319f3738d2848f8193ea44a0f205b6125c92be9494a958d39d8a2068e5fbf3aa19f37cff5634744c
@@ -1,6 +1,10 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ 0.0.5
5
+ -----
6
+ - remove dropletkit dependence
7
+
4
8
  0.0.2
5
9
  -----
6
10
  - first version that pass test
@@ -10,7 +10,6 @@ module VagrantPlugins
10
10
  def initialize(app, env)
11
11
  @app = app
12
12
  @machine = env[:machine]
13
- @client = client
14
13
  @simple_client = simple_client
15
14
  @logger = Log4r::Logger.new('vagrant::simplecloud::create')
16
15
  end
@@ -19,16 +18,16 @@ module VagrantPlugins
19
18
  ssh_key_id = [env[:ssh_key_id]]
20
19
 
21
20
  # submit new droplet request
22
- droplet = DropletKit::Droplet.new(name: @machine.config.vm.hostname || @machine.name, \
23
- region: @machine.provider_config.region,\
24
- size: @machine.provider_config.size, image: @machine.provider_config.image)
25
- result = JSON.parse(@simple_client.droplets.create(droplet))
21
+ result = @simple_client.post("/v2/droplets", {:name => @machine.config.vm.hostname || @machine.name, \
22
+ :region => @machine.provider_config.region,\
23
+ :size => @machine.provider_config.size, \
24
+ :image => @machine.provider_config.image})
26
25
 
27
26
  # wait for request to complete
28
27
  env[:ui].info I18n.t('vagrant_simple_cloud.info.creating')
29
28
 
30
29
  raise 'droplet not ready, no actions_ids' unless result['droplet'].has_key?('action_ids')
31
- @client.wait_for_event(env, result['droplet']['action_ids'].first)
30
+ @simple_client.wait_for_event(env, result['droplet']['action_ids'].first)
32
31
 
33
32
  # assign the machine id for reference in other commands
34
33
  @machine.id = result['droplet']['id'].to_s
@@ -9,15 +9,13 @@ module VagrantPlugins
9
9
  def initialize(app, env)
10
10
  @app = app
11
11
  @machine = env[:machine]
12
- @client = client
13
12
  @simple_client = simple_client
14
13
  @logger = Log4r::Logger.new('vagrant::simplecloud::destroy')
15
14
  end
16
15
 
17
16
  def call(env)
18
17
  # submit destroy droplet request
19
- @simple_client.droplets.delete(id: @machine.id)
20
- #@client.delete("/v2/droplets/#{@machine.id}")
18
+ @simple_client.delete("/v2/droplets/#{@machine.id}")
21
19
 
22
20
  env[:ui].info I18n.t('vagrant_simple_cloud.info.destroying')
23
21
 
@@ -9,7 +9,6 @@ module VagrantPlugins
9
9
  def initialize(app, env)
10
10
  @app = app
11
11
  @machine = env[:machine]
12
- @client = client
13
12
  @simple_client = simple_client
14
13
  @logger = Log4r::Logger.new('vagrant::simplecloud::power_off')
15
14
  end
@@ -20,7 +19,7 @@ module VagrantPlugins
20
19
 
21
20
  # wait for request to complete
22
21
  env[:ui].info I18n.t('vagrant_simple_cloud.info.powering_off')
23
- @client.wait_for_event(env, result['action']['id'])
22
+ @simple_client.wait_for_event(env, result['action']['id'])
24
23
 
25
24
  # refresh droplet state with provider
26
25
  Provider.droplet(@machine, :refresh => true)
@@ -9,7 +9,6 @@ module VagrantPlugins
9
9
  def initialize(app, env)
10
10
  @app = app
11
11
  @machine = env[:machine]
12
- @client = client
13
12
  @simple_client = simple_client
14
13
  @logger = Log4r::Logger.new('vagrant::simplecloud::power_on')
15
14
  end
@@ -20,7 +19,7 @@ module VagrantPlugins
20
19
 
21
20
  # wait for request to complete
22
21
  env[:ui].info I18n.t('vagrant_simple_cloud.info.powering_on')
23
- @client.wait_for_event(env, result['action']['id'])
22
+ @simple_client.wait_for_event(env, result['action']['id'])
24
23
 
25
24
  # refresh droplet state with provider
26
25
  Provider.droplet(@machine, :refresh => true)
@@ -10,28 +10,24 @@ module VagrantPlugins
10
10
  def initialize(app, env)
11
11
  @app = app
12
12
  @machine = env[:machine]
13
- @client = client
14
13
  @simple_client = simple_client
15
14
  @logger = Log4r::Logger.new('vagrant::simplecloud::rebuild')
16
15
  end
17
16
 
18
17
  def call(env)
19
- # look up image id
20
- image_id = @simple_client.images.find(id: @machine.provider_config.image).id
18
+ # look up image id
19
+ image_id = @simple_client.request('/v2/images').fetch('images').select \
20
+ {|a| a['slug'] == @machine.provider_config.image}.first['id']
21
21
 
22
22
  # submit rebuild request
23
23
  result = @simple_client.post("/v2/droplets/#{@machine.id}/actions", {
24
24
  :type => 'rebuild',
25
25
  :image => image_id
26
26
  })
27
- # simple cloud api has not return region_slug in response
28
- #image_id = @simple_client.images.find(id: @machine.provider_config.image).id
29
- #env[:ui].info "#{@machine.id.to_s}, #{image_id}"
30
- #result = JSON.parse(@simple_client.droplet_actions.rebuild(droplet_id: @machine.id, image: image_id))
31
27
 
32
28
  # wait for request to complete
33
29
  env[:ui].info I18n.t('vagrant_simple_cloud.info.rebuilding')
34
- @client.wait_for_event(env, result['action']['id'])
30
+ @simple_client.wait_for_event(env, result['action']['id'])
35
31
 
36
32
  # refresh droplet state with provider
37
33
  Provider.droplet(@machine, :refresh => true)
@@ -9,7 +9,6 @@ module VagrantPlugins
9
9
  def initialize(app, env)
10
10
  @app = app
11
11
  @machine = env[:machine]
12
- @client = client
13
12
  @simple_client = simple_client
14
13
  @logger = Log4r::Logger.new('vagrant::simplecloud::reload')
15
14
  end
@@ -20,7 +19,7 @@ module VagrantPlugins
20
19
 
21
20
  # wait for request to complete
22
21
  env[:ui].info I18n.t('vagrant_simple_cloud.info.reloading')
23
- @client.wait_for_event(env, result['action']['id'])
22
+ @simple_client.wait_for_event(env, result['action']['id'])
24
23
 
25
24
  @app.call(env)
26
25
  end
@@ -9,7 +9,6 @@ module VagrantPlugins
9
9
  def initialize(app, env)
10
10
  @app = app
11
11
  @machine = env[:machine]
12
- @client = client
13
12
  @simple_client = simple_client
14
13
  @logger = Log4r::Logger.new('vagrant::simplecloud::setup_key')
15
14
  end
@@ -18,17 +17,14 @@ module VagrantPlugins
18
17
  def call(env)
19
18
  ssh_key_name = @machine.provider_config.ssh_key_name
20
19
  # assigns existing ssh key id to env for use by other commands
21
- @simple_client.ssh_keys.all().each do |key|
22
- if key["name"] == ssh_key_name
23
- env[:ssh_key_id] = key["id"]
24
- env[:ui].info I18n.t('vagrant_simple_cloud.info.using_key', {
25
- :name => ssh_key_name
26
- })
27
- @app.call(env)
28
- return
29
- end
20
+ res = @simple_client.request('/v2/account/keys')
21
+ key_data = res.fetch('ssh_keys').select {|a| a['name'] == ssh_key_name}.first
22
+ if key_data.nil?
23
+ env[:ssh_key_id] = create_ssh_key(ssh_key_name, env)
24
+ else
25
+ env[:ssh_key_id] = key_data['id']
30
26
  end
31
- env[:ssh_key_id] = create_ssh_key(ssh_key_name, env)
27
+ env[:ui].info I18n.t('vagrant_simple_cloud.info.using_key', {:name => ssh_key_name})
32
28
  @app.call(env)
33
29
  end
34
30
 
@@ -40,12 +36,16 @@ module VagrantPlugins
40
36
  path = path[0] if path.is_a?(Array)
41
37
  path = File.expand_path(path, @machine.env.root_path)
42
38
  pub_key = SimpleCloud.public_key(path)
43
- ssh_key = DropletKit::SSHKey.new(name: name, public_key: pub_key)
44
- result = @simple_client.ssh_keys.create(ssh_key)
39
+
45
40
  env[:ui].info I18n.t('vagrant_simple_cloud.info.creating_key', {
46
41
  :name => name
47
42
  })
48
- result.id
43
+
44
+ result = @simple_client.post('/v2/account/keys', {
45
+ :name => name,
46
+ :public_key => pub_key
47
+ })
48
+ result['ssh_key']['id']
49
49
  end
50
50
  end
51
51
  end
@@ -9,7 +9,6 @@ module VagrantPlugins
9
9
  def initialize(app, env)
10
10
  @app = app
11
11
  @machine = env[:machine]
12
- @client = client
13
12
  @simple_client = simple_client
14
13
  @logger = Log4r::Logger.new('vagrant::simplecloud::shut_down')
15
14
  end
@@ -20,8 +19,7 @@ module VagrantPlugins
20
19
 
21
20
  # wait for request to complete
22
21
  env[:ui].info I18n.t('vagrant_simple_cloud.info.shutting_down')
23
- #@client.wait_for_event(env, result['droplet']['event_id'])
24
- @client.wait_for_event(env, result['action']['id'])
22
+ @simple_client.wait_for_event(env, result['action']['id'])
25
23
 
26
24
  # refresh droplet state with provider
27
25
  Provider.droplet(@machine, :refresh => true)
@@ -1,7 +1,6 @@
1
1
  require 'vagrant-simplecloud/helpers/result'
2
2
  require 'faraday'
3
3
  require 'json'
4
- require 'droplet_kit'
5
4
  require 'uri'
6
5
  require 'net/http'
7
6
  require 'net/https'
@@ -10,141 +9,62 @@ module VagrantPlugins
10
9
  module SimpleCloud
11
10
  module Helpers
12
11
  module Client
13
- def client
14
- @client ||= ApiClient.new(@machine)
15
- end
16
12
  def simple_client
17
- @simple_client ||= SimpleClient.new(access_token: @machine.provider_config.token)
13
+ @simple_client ||= SimpleClient.new(@machine)
18
14
  end
19
15
  end
20
- class SimpleClient < DropletKit::Client
16
+ class SimpleClient
21
17
  include Vagrant::Util::Retryable
22
18
 
19
+ def initialize(machine)
20
+ @logger = Log4r::Logger.new('vagrant::simplecloud::apiclient')
21
+ @config = machine.provider_config
22
+ @url = "https://api.simplecloud.ru"
23
+ end
24
+
25
+ def delete(path, params = {})
26
+ self.request(path, params, :delete)
27
+ end
28
+
23
29
  def post(path, params = {})
24
- uri = URI.parse("#{connection_options[:url]}#{path}")
30
+ self.request(path, params, :post)
31
+ end
32
+
33
+ def request(path, params = {}, method = :get)
34
+ @logger.info "Request: #{@url}#{path} #{params}"
35
+ uri = URI.parse("#{@url}#{path}")
25
36
  https = Net::HTTP.new(uri.host,uri.port)
26
37
  https.use_ssl = true
27
- req = Net::HTTP::Post.new(uri.path)
28
- req['Content-Type'] = connection_options[:headers][:content_type]
29
- req['Authorization'] = connection_options[:headers][:authorization]
38
+ req = case method
39
+ when :get
40
+ Net::HTTP::Get.new(uri.path)
41
+ when :post
42
+ Net::HTTP::Post.new(uri.path)
43
+ when :delete
44
+ Net::HTTP::Delete.new(uri.path)
45
+ end
46
+ req['Content-Type'] = "application/json"
47
+ req['Authorization'] = "Bearer #{@config.token}"
30
48
  req.set_form_data(params)
31
49
  res = https.request(req)
32
50
  unless /^2\d\d$/ =~ res.code.to_s
33
51
  raise "Server response error #{res.code} #{path} #{params} #{res.message} #{res.body}"
34
52
  end
35
- JSON.parse(res.body)
53
+ JSON.parse(res.body) unless res.body.nil?
36
54
  end
37
55
 
38
56
  def wait_for_event(env, id)
39
57
  retryable(:tries => 120, :sleep => 10) do
40
58
  # stop waiting if interrupted
41
59
  next if env[:interrupted]
42
- # check action status
43
- result = self.actions.find(id: id)
44
- yield result if block_given?
45
- raise 'not ready' if result.status != 'completed'
46
- end
47
- end
48
-
49
- private
50
- def connection_options
51
- {
52
- url: "https://api.simplecloud.ru",
53
- headers: {
54
- content_type: 'application/json',
55
- authorization: "Bearer #{access_token}"
56
- }
57
- }
58
- end
59
- end
60
- class ApiClient
61
- include Vagrant::Util::Retryable
62
-
63
- def initialize(machine)
64
- @logger = Log4r::Logger.new('vagrant::simplecloud::apiclient')
65
- @config = machine.provider_config
66
- @client = Faraday.new({
67
- :url => 'https://api.simplecloud.ru/',
68
- :ssl => {
69
- :ca_file => @config.ca_path
70
- }
71
- })
72
- end
73
-
74
- def delete(path, params = {}, method = :delete)
75
- @client.request :url_encoded
76
- request(path, params, :delete)
77
- end
78
-
79
- def post(path, params = {}, method = :post)
80
- @client.headers['Content-Type'] = 'application/json'
81
- request(path, params, :post)
82
- end
83
60
 
84
- def request(path, params = {}, method = :get)
85
- begin
86
- @logger.info "Request: #{path} #{params}"
87
- result = @client.send(method) do |req|
88
- req.url path, params
89
- req.headers['Authorization'] = "Bearer #{@config.token}"
90
- end
91
- rescue Faraday::Error::ConnectionFailed => e
92
- # TODO this is suspect but because farady wraps the exception
93
- # in something generic there doesn't appear to be another
94
- # way to distinguish different connection errors :(
95
- if e.message =~ /certificate verify failed/
96
- raise Errors::CertificateError
97
- end
98
-
99
- raise e
100
- end
61
+ # check action status
62
+ result = self.request("/v2/actions/#{id}")
101
63
 
102
- unless method == :delete
103
- begin
104
- body = JSON.parse(result.body)
105
- @logger.info "Response: #{body}"
106
- next_page = body["links"]["pages"]["next"] rescue nil
107
- unless next_page.nil?
108
- uri = URI.parse(next_page)
109
- new_path = path.split("?")[0]
110
- next_result = self.request("#{new_path}?#{uri.query}")
111
- req_target = new_path.split("/")[-1]
112
- body["#{req_target}"].concat(next_result["#{req_target}"])
113
- end
114
- rescue JSON::ParserError => e
115
- raise(Errors::JSONError, {
116
- :message => e.message,
117
- :path => path,
118
- :params => params,
119
- :response => result.body
120
- })
64
+ yield result if block_given?
65
+ raise 'not ready' if result['action']['status'] != 'completed'
121
66
  end
122
67
  end
123
-
124
- unless /^2\d\d$/ =~ result.status.to_s
125
- raise(Errors::APIStatusError, {
126
- :path => path,
127
- :params => params,
128
- :status => result.status,
129
- :response => body.inspect
130
- })
131
- end
132
-
133
- Result.new(body)
134
- end
135
-
136
- def wait_for_event(env, id)
137
- retryable(:tries => 120, :sleep => 10) do
138
- # stop waiting if interrupted
139
- next if env[:interrupted]
140
-
141
- # check action status
142
- result = self.request("/v2/actions/#{id}")
143
-
144
- yield result if block_given?
145
- raise 'not ready' if result['action']['status'] != 'completed'
146
- end
147
- end
148
68
  end
149
69
  end
150
70
  end
@@ -8,7 +8,7 @@ module VagrantPlugins
8
8
  # the Simple Cloud account. A specific droplet's status
9
9
  # may be refreshed by passing :refresh => true as an option.
10
10
  def self.droplet(machine, opts = {})
11
- client = Helpers::ApiClient.new(machine)
11
+ client = Helpers::SimpleClient.new(machine)
12
12
 
13
13
  # load status of droplets if it has not been done before
14
14
  if !@droplets
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module SimpleCloud
3
- VERSION = '0.0.4'
3
+ VERSION = '0.0.5'
4
4
  end
5
5
  end
@@ -9,6 +9,7 @@ bundle _1.7.9_ exec vagrant provision
9
9
  bundle _1.7.9_ exec vagrant reload
10
10
  bundle _1.7.9_ exec vagrant rebuild
11
11
  bundle _1.7.9_ exec vagrant halt
12
+ bundle _1.7.9_ exec vagrant up
12
13
  bundle _1.7.9_ exec vagrant destroy
13
14
 
14
15
  cd ..
@@ -18,5 +18,4 @@ Gem::Specification.new do |gem|
18
18
  gem.add_dependency "faraday", ">= 0.8.6"
19
19
  gem.add_dependency "json"
20
20
  gem.add_dependency "log4r"
21
- gem.add_dependency "droplet_kit"
22
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-simplecloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Bender
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-08-12 00:00:00.000000000 Z
12
+ date: 2015-10-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -53,20 +53,6 @@ dependencies:
53
53
  - - ">="
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
- - !ruby/object:Gem::Dependency
57
- name: droplet_kit
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: '0'
63
- type: :runtime
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: '0'
70
56
  description: Enables Vagrant to manage Simple Cloud droplets. Based on https://github.com/smdahlen/vagrant-digitalocean
71
57
  email:
72
58
  - vadikgo@gmail.com
@@ -134,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
120
  version: '0'
135
121
  requirements: []
136
122
  rubyforge_project:
137
- rubygems_version: 2.4.3
123
+ rubygems_version: 2.4.6
138
124
  signing_key:
139
125
  specification_version: 4
140
126
  summary: Enables Vagrant to manage Simple Cloud droplets. Based on https://github.com/smdahlen/vagrant-digitalocean