bosh_cpi 1.3215.3.0 → 1.3215.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 88eab9857f0da6fdada35c11e83ccdf0cc113586
4
- data.tar.gz: c004a63411abdf0126ad0a6f68d69f3b9d6d15c4
3
+ metadata.gz: e47a8b1c490ee6b087454854ea70db9db74a0501
4
+ data.tar.gz: 365900e4eda1c666317d58416b632228c0f84784
5
5
  SHA512:
6
- metadata.gz: 028d7298c370e7853b5726e7aa3eecb90ae48119afe2e7139bcbf6e895e3055bb46eb45c3dbc29509cb95d7a32b885e03195c116371fa03ecc15184c754131ec
7
- data.tar.gz: 089a4b2e24d40dc945efc132489e1dd626a4481b128657f32e7718b7299ae8cb389364aa17407a808674a912fd5a253a57f3e1d125facf2c0fab6fff33335e76
6
+ metadata.gz: f4c6e3b7ef8f6f7276f8e627051dcbee701aa482051cc6dd5594b212d7297c08ff8171786d7c5488c081daa7ff80b113c81e657efb021148efeb92987d0f623d
7
+ data.tar.gz: 39e8e7e42f4d0b3ea8e8d7812e8fee9aae41acbb6deca601a62d473cffa3dafb54f39f2271b518b40efa4f67b369abf042580696d5f5f5d5bea2b1036dad5f91
@@ -7,7 +7,7 @@ module Bosh::Cpi::CompatibilityHelpers
7
7
  it "raises VMNotFound error" do
8
8
  expect {
9
9
  cpi.delete_vm(vm_cid)
10
- }.to raise_error(Bosh::Clouds::VMNotFound, "VM `#{vm_cid}' not found")
10
+ }.to raise_error(Bosh::Clouds::VMNotFound, "VM '#{vm_cid}' not found")
11
11
  end
12
12
  end
13
13
  end
@@ -0,0 +1,106 @@
1
+ require 'cloud/errors'
2
+ require 'httpclient'
3
+ require 'base64'
4
+ require 'json'
5
+
6
+ module Bosh::Cpi
7
+ class RegistryClient
8
+ attr_reader :endpoint
9
+ attr_reader :user
10
+ attr_reader :password
11
+
12
+ def initialize(endpoint, user, password)
13
+ @endpoint = endpoint
14
+
15
+ unless @endpoint =~ /^http:\/\//
16
+ @endpoint = "http://#{@endpoint}"
17
+ end
18
+
19
+ @user = user
20
+ @password = password
21
+
22
+ auth = Base64.encode64("#{@user}:#{@password}").gsub("\n", '')
23
+
24
+ @headers = {
25
+ "Accept" => 'application/json',
26
+ "Authorization" => "Basic #{auth}"
27
+ }
28
+
29
+ @client = HTTPClient.new
30
+ end
31
+
32
+ ##
33
+ # Update instance settings in the registry
34
+ # @param [String] instance_id EC2 instance id
35
+ # @param [Hash] settings New agent settings
36
+ # @return [Boolean]
37
+ def update_settings(instance_id, settings)
38
+ unless settings.is_a?(Hash)
39
+ raise ArgumentError, "Invalid settings format, Hash expected, #{settings.class} given"
40
+ end
41
+
42
+ payload = JSON.dump(settings)
43
+ url = "#{@endpoint}/instances/#{instance_id}/settings"
44
+
45
+ response = @client.put(url, {:body => payload, :header => @headers})
46
+
47
+ unless HTTP::Status.successful?(response.status)
48
+ cloud_error("Cannot update settings for '#{instance_id}', got HTTP #{response.status}")
49
+ end
50
+
51
+ true
52
+ end
53
+
54
+ ##
55
+ # Read instance settings from the registry
56
+ # @param [String] instance_id EC2 instance id
57
+ # @return [Hash] Agent settings
58
+ def read_settings(instance_id)
59
+ url = "#{@endpoint}/instances/#{instance_id}/settings"
60
+
61
+ response = @client.get(url, {:header => @headers})
62
+
63
+ if response.status != 200
64
+ cloud_error("Cannot read settings for '#{instance_id}', got HTTP #{response.status}")
65
+ end
66
+
67
+ body = JSON.load(response.body)
68
+
69
+ unless body.is_a?(Hash)
70
+ cloud_error("Invalid registry response, Hash expected, got #{body.class}: #{body}")
71
+ end
72
+
73
+ settings = JSON.load(body["settings"])
74
+
75
+ unless settings.is_a?(Hash)
76
+ cloud_error("Invalid settings format, Hash expected, got #{settings.class}: #{settings}")
77
+ end
78
+
79
+ settings
80
+ rescue JSON::ParserError => e
81
+ cloud_error("Cannot parse settings for '#{instance_id}': #{e.message}")
82
+ end
83
+
84
+ ##
85
+ # Delete instance settings from the registry
86
+ # @param [String] instance_id EC2 instance id
87
+ # @return [Boolean]
88
+ def delete_settings(instance_id)
89
+ url = "#{@endpoint}/instances/#{instance_id}/settings"
90
+
91
+ response = @client.delete(url, {:header => @headers})
92
+
93
+ unless [200, 404].include? response.status
94
+ cloud_error("Cannot delete settings for '#{instance_id}', got HTTP #{response.status}")
95
+ end
96
+
97
+ true
98
+ end
99
+
100
+ private
101
+
102
+ def cloud_error(message)
103
+ raise Bosh::Clouds::CloudError, message
104
+ end
105
+ end
106
+ end
data/lib/bosh/cpi.rb CHANGED
@@ -3,3 +3,4 @@ module Bosh
3
3
  end
4
4
 
5
5
  require 'bosh/cpi/cli'
6
+ require 'bosh/cpi/registry_client'
@@ -96,7 +96,7 @@ module Bosh::Clouds
96
96
 
97
97
  def checked_cpi_exec_path
98
98
  unless File.executable?(@cpi_path)
99
- raise NonExecutable, "Failed to run cpi: `#{@cpi_path}' is not executable"
99
+ raise NonExecutable, "Failed to run cpi: '#{@cpi_path}' is not executable"
100
100
  end
101
101
  @cpi_path
102
102
  end
data/lib/cloud/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Bosh
2
2
  module Clouds
3
- VERSION = '1.3215.3.0'
3
+ VERSION = '1.3215.0'
4
4
  end
5
5
  end
data/lib/cloud.rb CHANGED
@@ -214,7 +214,7 @@ module Bosh
214
214
 
215
215
  def not_implemented(method)
216
216
  raise Bosh::Clouds::NotImplemented,
217
- "`#{method}' is not implemented by #{self.class}"
217
+ "'#{method}' is not implemented by #{self.class}"
218
218
  end
219
219
 
220
220
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bosh_cpi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3215.3.0
4
+ version: 1.3215.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - VMware
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-01 00:00:00.000000000 Z
11
+ date: 2016-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bosh_common
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: 1.3215.3.0
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: 1.3215.3.0
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: membrane
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -104,6 +90,7 @@ files:
104
90
  - lib/bosh/cpi/cli.rb
105
91
  - lib/bosh/cpi/compatibility_helpers.rb
106
92
  - lib/bosh/cpi/compatibility_helpers/delete_vm.rb
93
+ - lib/bosh/cpi/registry_client.rb
107
94
  - lib/bosh/cpi/tasks.rb
108
95
  - lib/bosh/cpi/tasks/spec.rake
109
96
  - lib/cloud.rb
@@ -133,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
120
  version: '0'
134
121
  requirements: []
135
122
  rubyforge_project:
136
- rubygems_version: 2.2.2
123
+ rubygems_version: 2.2.5
137
124
  signing_key:
138
125
  specification_version: 4
139
126
  summary: BOSH CPI