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 +4 -4
- data/lib/bosh/cpi/compatibility_helpers/delete_vm.rb +1 -1
- data/lib/bosh/cpi/registry_client.rb +106 -0
- data/lib/bosh/cpi.rb +1 -0
- data/lib/cloud/external_cpi.rb +1 -1
- data/lib/cloud/version.rb +1 -1
- data/lib/cloud.rb +1 -1
- metadata +4 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e47a8b1c490ee6b087454854ea70db9db74a0501
|
4
|
+
data.tar.gz: 365900e4eda1c666317d58416b632228c0f84784
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
data/lib/cloud/external_cpi.rb
CHANGED
@@ -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:
|
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
data/lib/cloud.rb
CHANGED
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.
|
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-
|
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.
|
123
|
+
rubygems_version: 2.2.5
|
137
124
|
signing_key:
|
138
125
|
specification_version: 4
|
139
126
|
summary: BOSH CPI
|