bosh_cpi 1.3048.0 → 1.3232.0
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 +4 -4
- data/lib/bosh/cpi/cli.rb +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 +3 -3
- data/lib/cloud/internal_cpi.rb +25 -0
- data/lib/cloud/provider.rb +3 -3
- data/lib/cloud/version.rb +1 -1
- data/lib/cloud.rb +10 -21
- metadata +7 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c645d59aa7bd3bbf39e6d4d7a1dcd1fa91f3e8aa
|
|
4
|
+
data.tar.gz: 5b2891179978924c84ad53edb4a72658e5bda80d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 679aa03f789b0fd8ea75c059640363767128661deca3a06b67b7b8785f7a3d5d872949169ceee2c380b3559228abeeab1cf3d09c6a6b6d35e6c7ed48fbe6681b
|
|
7
|
+
data.tar.gz: ff10f37d0889566d870ee515b91a8d48a25281833dce08792e372ca15e60ad61302eb79ae2405131c63bd76c847d20ea712d407129fbcad2c00a74216df6db4c
|
data/lib/bosh/cpi/cli.rb
CHANGED
|
@@ -10,7 +10,6 @@ class Bosh::Cpi::Cli
|
|
|
10
10
|
has_vm
|
|
11
11
|
reboot_vm
|
|
12
12
|
set_vm_metadata
|
|
13
|
-
configure_networks
|
|
14
13
|
create_disk
|
|
15
14
|
has_disk
|
|
16
15
|
delete_disk
|
|
@@ -67,7 +66,8 @@ class Bosh::Cpi::Cli
|
|
|
67
66
|
ruby_method = RPC_METHOD_TO_RUBY_METHOD[method] || method
|
|
68
67
|
|
|
69
68
|
begin
|
|
70
|
-
|
|
69
|
+
cpi = @cpi.call
|
|
70
|
+
result = cpi.public_send(ruby_method, *arguments)
|
|
71
71
|
rescue Bosh::Clouds::RetriableCloudError => e
|
|
72
72
|
return error_response(error_name(e), e.message, e.ok_to_retry, e.backtrace)
|
|
73
73
|
rescue Bosh::Clouds::CloudError, Bosh::Clouds::CpiError => e
|
|
@@ -99,7 +99,7 @@ class Bosh::Cpi::Cli
|
|
|
99
99
|
message: message,
|
|
100
100
|
ok_to_retry: ok_to_retry,
|
|
101
101
|
},
|
|
102
|
-
log: @logs_string_io.string,
|
|
102
|
+
log: @logs_string_io.string.force_encoding(Encoding::UTF_8),
|
|
103
103
|
}
|
|
104
104
|
@result_io.print(JSON.dump(hash)); nil
|
|
105
105
|
end
|
|
@@ -108,7 +108,7 @@ class Bosh::Cpi::Cli
|
|
|
108
108
|
hash = {
|
|
109
109
|
result: result,
|
|
110
110
|
error: nil,
|
|
111
|
-
log: @logs_string_io.string,
|
|
111
|
+
log: @logs_string_io.string.force_encoding(Encoding::UTF_8),
|
|
112
112
|
}
|
|
113
113
|
@result_io.print(JSON.dump(hash)); nil
|
|
114
114
|
end
|
|
@@ -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
|
@@ -48,12 +48,11 @@ module Bosh::Clouds
|
|
|
48
48
|
def current_vm_id(*arguments); invoke_cpi_method(__method__.to_s, *arguments); end
|
|
49
49
|
def create_stemcell(*arguments); invoke_cpi_method(__method__.to_s, *arguments); end
|
|
50
50
|
def delete_stemcell(*arguments); invoke_cpi_method(__method__.to_s, *arguments); end
|
|
51
|
-
def create_vm(*arguments)
|
|
51
|
+
def create_vm(*arguments) invoke_cpi_method(__method__.to_s, *arguments); end
|
|
52
52
|
def delete_vm(*arguments); invoke_cpi_method(__method__.to_s, *arguments); end
|
|
53
53
|
def has_vm?(*arguments); invoke_cpi_method(__method__.to_s, *arguments); end
|
|
54
54
|
def reboot_vm(*arguments); invoke_cpi_method(__method__.to_s, *arguments); end
|
|
55
55
|
def set_vm_metadata(*arguments); invoke_cpi_method(__method__.to_s, *arguments); end
|
|
56
|
-
def configure_networks(*arguments); invoke_cpi_method(__method__.to_s, *arguments); end
|
|
57
56
|
def create_disk(*arguments); invoke_cpi_method(__method__.to_s, *arguments); end
|
|
58
57
|
def has_disk?(*arguments); invoke_cpi_method(__method__.to_s, *arguments); end
|
|
59
58
|
def delete_disk(*arguments); invoke_cpi_method(__method__.to_s, *arguments); end
|
|
@@ -90,13 +89,14 @@ module Bosh::Clouds
|
|
|
90
89
|
end
|
|
91
90
|
|
|
92
91
|
save_cpi_log(parsed_response['log'])
|
|
92
|
+
save_cpi_log(stderr)
|
|
93
93
|
|
|
94
94
|
parsed_response['result']
|
|
95
95
|
end
|
|
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
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module Bosh::Clouds
|
|
2
|
+
class InternalCpi
|
|
3
|
+
def initialize(cloud)
|
|
4
|
+
@cloud = cloud
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
private
|
|
8
|
+
|
|
9
|
+
def method_missing(method_sym, *arguments, &block)
|
|
10
|
+
invoke_cpi_method(method_sym, arguments)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def respond_to?(method_sym)
|
|
14
|
+
cloud.respond_to?(method_sym)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def cloud
|
|
18
|
+
@cloud
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def invoke_cpi_method(method_sym, arguments)
|
|
22
|
+
cloud.send(method_sym, *JSON.parse(JSON.dump(arguments)))
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
data/lib/cloud/provider.rb
CHANGED
|
@@ -4,14 +4,14 @@ module Bosh::Clouds
|
|
|
4
4
|
if cloud_config.has_key?('provider')
|
|
5
5
|
ExternalCpiProvider.create(cloud_config['provider']['path'], director_uuid)
|
|
6
6
|
else
|
|
7
|
-
|
|
7
|
+
InternalCpiProvider.create(cloud_config['plugin'], cloud_config['properties'])
|
|
8
8
|
end
|
|
9
9
|
end
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
private
|
|
13
13
|
|
|
14
|
-
class
|
|
14
|
+
class InternalCpiProvider
|
|
15
15
|
def self.create(plugin, options)
|
|
16
16
|
begin
|
|
17
17
|
require "cloud/#{plugin}"
|
|
@@ -19,7 +19,7 @@ module Bosh::Clouds
|
|
|
19
19
|
raise CloudError, "Could not load Cloud Provider Plugin: #{plugin}, with error #{error.inspect}"
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
Bosh::Clouds.const_get(plugin.capitalize).new(options)
|
|
22
|
+
InternalCpi.new(Bosh::Clouds.const_get(plugin.capitalize).new(options))
|
|
23
23
|
end
|
|
24
24
|
end
|
|
25
25
|
|
data/lib/cloud/version.rb
CHANGED
data/lib/cloud.rb
CHANGED
|
@@ -8,6 +8,7 @@ require "cloud/config"
|
|
|
8
8
|
require "cloud/errors"
|
|
9
9
|
require "cloud/provider"
|
|
10
10
|
require "cloud/external_cpi"
|
|
11
|
+
require "cloud/internal_cpi"
|
|
11
12
|
|
|
12
13
|
module Bosh
|
|
13
14
|
|
|
@@ -87,18 +88,17 @@ module Bosh
|
|
|
87
88
|
# @param [Hash] resource_pool cloud specific properties describing the resources needed
|
|
88
89
|
# for this VM
|
|
89
90
|
# @param [Hash] networks list of networks and their settings needed for this VM
|
|
90
|
-
# @param [
|
|
91
|
+
# @param [String, Array] disk_locality disk id(s) if known of the disk(s) that will be
|
|
91
92
|
# attached to this vm
|
|
92
|
-
# @param [
|
|
93
|
-
# @return [String] opaque id later used by {#
|
|
94
|
-
# {#detach_disk}, and {#delete_vm}
|
|
93
|
+
# @param [Hash] env environment that will be passed to this vm
|
|
94
|
+
# @return [String] opaque id later used by {#attach_disk}, {#detach_disk} and {#delete_vm}
|
|
95
95
|
def create_vm(agent_id, stemcell_id, resource_pool,
|
|
96
|
-
networks, disk_locality
|
|
96
|
+
networks, disk_locality, env)
|
|
97
97
|
not_implemented(:create_vm)
|
|
98
98
|
end
|
|
99
99
|
|
|
100
100
|
##
|
|
101
|
-
# Deletes a VM
|
|
101
|
+
# Deletes a VM. If the VM has already been deleted, this call returns normally and has no effect.
|
|
102
102
|
#
|
|
103
103
|
# @param [String] vm vm id that was once returned by {#create_vm}
|
|
104
104
|
# @return [void]
|
|
@@ -146,17 +146,6 @@ module Bosh
|
|
|
146
146
|
not_implemented(:set_vm_metadata)
|
|
147
147
|
end
|
|
148
148
|
|
|
149
|
-
##
|
|
150
|
-
# Configures networking an existing VM.
|
|
151
|
-
#
|
|
152
|
-
# @param [String] vm vm id that was once returned by {#create_vm}
|
|
153
|
-
# @param [Hash] networks list of networks and their settings needed for this VM,
|
|
154
|
-
# same as the networks argument in {#create_vm}
|
|
155
|
-
# @return [void]
|
|
156
|
-
def configure_networks(vm_id, networks)
|
|
157
|
-
not_implemented(:configure_networks)
|
|
158
|
-
end
|
|
159
|
-
|
|
160
149
|
##
|
|
161
150
|
# Creates a disk (possibly lazily) that will be attached later to a VM. When
|
|
162
151
|
# VM locality is specified the disk will be placed near the VM so it won't have to move
|
|
@@ -165,10 +154,10 @@ module Bosh
|
|
|
165
154
|
# @param [Integer] size disk size in MB
|
|
166
155
|
# @param [Hash] cloud_properties properties required for creating this disk
|
|
167
156
|
# specific to a CPI
|
|
168
|
-
# @param [
|
|
157
|
+
# @param [String] vm_locality vm id if known of the VM that this disk will
|
|
169
158
|
# be attached to
|
|
170
159
|
# @return [String] opaque id later used by {#attach_disk}, {#detach_disk}, and {#delete_disk}
|
|
171
|
-
def create_disk(size, cloud_properties, vm_locality
|
|
160
|
+
def create_disk(size, cloud_properties, vm_locality)
|
|
172
161
|
not_implemented(:create_disk)
|
|
173
162
|
end
|
|
174
163
|
|
|
@@ -194,7 +183,7 @@ module Bosh
|
|
|
194
183
|
# @param [String] disk_id disk id of the disk to take the snapshot of
|
|
195
184
|
# @param [Hash] metadata metadata key/value pairs
|
|
196
185
|
# @return [String] snapshot id
|
|
197
|
-
def snapshot_disk(disk_id, metadata
|
|
186
|
+
def snapshot_disk(disk_id, metadata)
|
|
198
187
|
not_implemented(:snapshot_disk)
|
|
199
188
|
end
|
|
200
189
|
|
|
@@ -225,7 +214,7 @@ module Bosh
|
|
|
225
214
|
|
|
226
215
|
def not_implemented(method)
|
|
227
216
|
raise Bosh::Clouds::NotImplemented,
|
|
228
|
-
"
|
|
217
|
+
"'#{method}' is not implemented by #{self.class}"
|
|
229
218
|
end
|
|
230
219
|
|
|
231
220
|
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.
|
|
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:
|
|
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.
|
|
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.
|
|
26
|
+
version: 1.3232.0
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: membrane
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -94,9 +94,7 @@ dependencies:
|
|
|
94
94
|
- - ">="
|
|
95
95
|
- !ruby/object:Gem::Version
|
|
96
96
|
version: '0'
|
|
97
|
-
description:
|
|
98
|
-
BOSH CPI
|
|
99
|
-
e2c11a
|
|
97
|
+
description: BOSH CPI
|
|
100
98
|
email: support@cloudfoundry.com
|
|
101
99
|
executables: []
|
|
102
100
|
extensions: []
|
|
@@ -106,12 +104,14 @@ files:
|
|
|
106
104
|
- lib/bosh/cpi/cli.rb
|
|
107
105
|
- lib/bosh/cpi/compatibility_helpers.rb
|
|
108
106
|
- lib/bosh/cpi/compatibility_helpers/delete_vm.rb
|
|
107
|
+
- lib/bosh/cpi/registry_client.rb
|
|
109
108
|
- lib/bosh/cpi/tasks.rb
|
|
110
109
|
- lib/bosh/cpi/tasks/spec.rake
|
|
111
110
|
- lib/cloud.rb
|
|
112
111
|
- lib/cloud/config.rb
|
|
113
112
|
- lib/cloud/errors.rb
|
|
114
113
|
- lib/cloud/external_cpi.rb
|
|
114
|
+
- lib/cloud/internal_cpi.rb
|
|
115
115
|
- lib/cloud/provider.rb
|
|
116
116
|
- lib/cloud/version.rb
|
|
117
117
|
homepage: https://github.com/cloudfoundry/bosh
|