bosh_cpi 1.3215.4.0 → 1.3232.0

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: f5b072ecb87cfd52cf3c3f05e4b398191297dd56
4
- data.tar.gz: 9555b9b810020665f128621b7b6b1dc1093d58f8
3
+ metadata.gz: c645d59aa7bd3bbf39e6d4d7a1dcd1fa91f3e8aa
4
+ data.tar.gz: 5b2891179978924c84ad53edb4a72658e5bda80d
5
5
  SHA512:
6
- metadata.gz: 5360ba99e403b6af0f62001d38a5926432a83bea1d6122847450d9f8d81cf50e6034b1fa020500058dcd5893dd84caac0fe95f6188851a33176ccc57ab34c61c
7
- data.tar.gz: cef7d85065d4269dd3d5e3f80b581a462d3d58e544383ab0e8bd37f2a3ede33efed21afaf85123bce427b90ac01bca73717b9e004ffce5fdd61626d2fac47d85
6
+ metadata.gz: 679aa03f789b0fd8ea75c059640363767128661deca3a06b67b7b8785f7a3d5d872949169ceee2c380b3559228abeeab1cf3d09c6a6b6d35e6c7ed48fbe6681b
7
+ data.tar.gz: ff10f37d0889566d870ee515b91a8d48a25281833dce08792e372ca15e60ad61302eb79ae2405131c63bd76c847d20ea712d407129fbcad2c00a74216df6db4c
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'
@@ -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/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
@@ -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.4.0'
3
+ VERSION = '1.3232.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bosh_cpi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3215.4.0
4
+ version: 1.3232.0
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-14 00:00:00.000000000 Z
11
+ date: 2016-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bosh_common
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.3215.4.0
19
+ version: 1.3232.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.3215.4.0
26
+ version: 1.3232.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: membrane
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -104,6 +104,7 @@ files:
104
104
  - lib/bosh/cpi/cli.rb
105
105
  - lib/bosh/cpi/compatibility_helpers.rb
106
106
  - lib/bosh/cpi/compatibility_helpers/delete_vm.rb
107
+ - lib/bosh/cpi/registry_client.rb
107
108
  - lib/bosh/cpi/tasks.rb
108
109
  - lib/bosh/cpi/tasks/spec.rake
109
110
  - lib/cloud.rb