bosh_cpi 1.2579.0 → 2.5.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 +7 -0
- data/lib/bosh/cpi/cli.rb +53 -16
- data/lib/bosh/cpi/compatibility_helpers/delete_vm.rb +1 -1
- data/lib/bosh/cpi/logger.rb +15 -0
- data/lib/bosh/cpi/redactor.rb +32 -0
- data/lib/bosh/cpi/registry_client.rb +107 -0
- data/lib/bosh/cpi.rb +3 -0
- data/lib/cloud/errors.rb +1 -0
- data/lib/cloud/version.rb +1 -1
- data/lib/cloud.rb +3 -214
- data/lib/cloud_v1.rb +270 -0
- data/lib/cloud_v2.rb +102 -0
- metadata +32 -25
- data/README +0 -1
- data/lib/cloud/external_cpi.rb +0 -151
- data/lib/cloud/provider.rb +0 -31
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 4dac2f17efac6e742ca6ee8403f088184fc887166269adbad9e10212797cbcd7
|
|
4
|
+
data.tar.gz: 6f82d9a5aa37ee49140e0572729c23df6af684597b747b8d94556a346ae3fd50
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 0dcb6fdf43d4ae9abd8e356400127b9956e4cce37ef4c75c615fda32c27cca330a68f56d2ab452e45da7ba70d56032cf2af56ad9262188ea3d9fd9f98c1c67d7
|
|
7
|
+
data.tar.gz: 7dd0378a47313cb03fc107fa3502abbe6ce610b6ab326d870e0a99251b31d3a5687a3e9f08a9ba4be81b1ba0b18e36ac106c1eaf85bfdf99d581abd23ce04c2d
|
data/lib/bosh/cpi/cli.rb
CHANGED
|
@@ -2,6 +2,7 @@ require 'json'
|
|
|
2
2
|
|
|
3
3
|
class Bosh::Cpi::Cli
|
|
4
4
|
KNOWN_RPC_METHODS = %w(
|
|
5
|
+
info
|
|
5
6
|
current_vm_id
|
|
6
7
|
create_stemcell
|
|
7
8
|
delete_stemcell
|
|
@@ -10,19 +11,25 @@ class Bosh::Cpi::Cli
|
|
|
10
11
|
has_vm
|
|
11
12
|
reboot_vm
|
|
12
13
|
set_vm_metadata
|
|
13
|
-
|
|
14
|
+
set_disk_metadata
|
|
14
15
|
create_disk
|
|
16
|
+
has_disk
|
|
15
17
|
delete_disk
|
|
16
18
|
attach_disk
|
|
17
19
|
detach_disk
|
|
18
20
|
snapshot_disk
|
|
19
21
|
delete_snapshot
|
|
20
22
|
get_disks
|
|
23
|
+
resize_disk
|
|
21
24
|
ping
|
|
25
|
+
calculate_vm_cloud_properties
|
|
26
|
+
create_network
|
|
27
|
+
delete_network
|
|
22
28
|
).freeze
|
|
23
29
|
|
|
24
30
|
RPC_METHOD_TO_RUBY_METHOD = {
|
|
25
31
|
'has_vm' => 'has_vm?',
|
|
32
|
+
'has_disk' => 'has_disk?',
|
|
26
33
|
}.freeze
|
|
27
34
|
|
|
28
35
|
INVALID_CALL_ERROR_TYPE = 'InvalidCall'.freeze
|
|
@@ -32,48 +39,65 @@ class Bosh::Cpi::Cli
|
|
|
32
39
|
@cpi = cpi
|
|
33
40
|
@logs_string_io = logs_string_io
|
|
34
41
|
@result_io = result_io
|
|
42
|
+
@logger = Bosh::Cpi::Logger.new(STDERR)
|
|
35
43
|
end
|
|
36
44
|
|
|
37
45
|
def run(json)
|
|
38
46
|
begin
|
|
39
47
|
request = JSON.load(json)
|
|
40
|
-
rescue JSON::ParserError
|
|
41
|
-
return error_response(INVALID_CALL_ERROR_TYPE,
|
|
48
|
+
rescue JSON::ParserError => e
|
|
49
|
+
return error_response(INVALID_CALL_ERROR_TYPE, "Request cannot be deserialized, details: #{e.message}", false, e.backtrace)
|
|
42
50
|
end
|
|
43
51
|
|
|
44
52
|
method = request['method']
|
|
45
53
|
unless method.is_a?(String)
|
|
46
|
-
return error_response(INVALID_CALL_ERROR_TYPE,
|
|
54
|
+
return error_response(INVALID_CALL_ERROR_TYPE, "Method must be a String, got: '#{method.inspect}'", false)
|
|
47
55
|
end
|
|
48
56
|
|
|
49
57
|
unless KNOWN_RPC_METHODS.include?(method)
|
|
50
|
-
return error_response(
|
|
58
|
+
return error_response(Bosh::Clouds::NotImplemented.name, "Method is not known, got: '#{method}'", false)
|
|
51
59
|
end
|
|
52
60
|
|
|
53
61
|
arguments = request['arguments']
|
|
54
62
|
unless arguments.is_a?(Array)
|
|
55
|
-
return error_response(INVALID_CALL_ERROR_TYPE,
|
|
63
|
+
return error_response(INVALID_CALL_ERROR_TYPE, "Arguments must be an Array", false)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
cpi_api_version = request['api_version']
|
|
67
|
+
if request.has_key?('api_version') && !cpi_api_version.is_a?(Integer)
|
|
68
|
+
return error_response(INVALID_CALL_ERROR_TYPE, "CPI api_version requested must be an Integer", false)
|
|
56
69
|
end
|
|
57
70
|
|
|
58
71
|
context = request['context']
|
|
59
72
|
unless context.is_a?(Hash) && context['director_uuid'].is_a?(String)
|
|
60
|
-
return error_response(INVALID_CALL_ERROR_TYPE,
|
|
73
|
+
return error_response(INVALID_CALL_ERROR_TYPE, "Request should include context with director uuid", false)
|
|
61
74
|
end
|
|
62
75
|
|
|
76
|
+
req_id = context['request_id']
|
|
77
|
+
@logger.set_request_id(req_id)
|
|
78
|
+
|
|
63
79
|
configure_director(context['director_uuid'])
|
|
64
80
|
|
|
65
81
|
ruby_method = RPC_METHOD_TO_RUBY_METHOD[method] || method
|
|
66
82
|
|
|
67
83
|
begin
|
|
68
|
-
|
|
84
|
+
start_time = Time.now.utc
|
|
85
|
+
@logger.info("Starting #{method}...")
|
|
86
|
+
|
|
87
|
+
cpi = @cpi.call(context, cpi_api_version)
|
|
88
|
+
|
|
89
|
+
result = cpi.public_send(ruby_method, *arguments)
|
|
69
90
|
rescue Bosh::Clouds::RetriableCloudError => e
|
|
70
|
-
return error_response(error_name(e), e.message, e.ok_to_retry)
|
|
91
|
+
return error_response(error_name(e), e.message, e.ok_to_retry, e.backtrace)
|
|
71
92
|
rescue Bosh::Clouds::CloudError, Bosh::Clouds::CpiError => e
|
|
72
|
-
return error_response(error_name(e), e.message, false)
|
|
73
|
-
rescue ArgumentError
|
|
74
|
-
return error_response(INVALID_CALL_ERROR_TYPE,
|
|
93
|
+
return error_response(error_name(e), e.message, false, e.backtrace)
|
|
94
|
+
rescue ArgumentError => e
|
|
95
|
+
return error_response(INVALID_CALL_ERROR_TYPE, "Arguments are not correct, details: '#{e.message}'", false, e.backtrace)
|
|
75
96
|
rescue Exception => e
|
|
76
|
-
return error_response(UNKNOWN_ERROR_TYPE, e.message, false)
|
|
97
|
+
return error_response(UNKNOWN_ERROR_TYPE, e.message, false, e.backtrace)
|
|
98
|
+
ensure
|
|
99
|
+
end_time = Time.now.utc
|
|
100
|
+
@logger.info("Finished #{method} in #{(end_time - start_time).round(2)} seconds")
|
|
77
101
|
end
|
|
78
102
|
|
|
79
103
|
result_response(result)
|
|
@@ -85,7 +109,11 @@ class Bosh::Cpi::Cli
|
|
|
85
109
|
Bosh::Clouds::Config.uuid = director_uuid
|
|
86
110
|
end
|
|
87
111
|
|
|
88
|
-
def error_response(type, message, ok_to_retry)
|
|
112
|
+
def error_response(type, message, ok_to_retry, bt=[])
|
|
113
|
+
if !bt.empty?
|
|
114
|
+
@logs_string_io.print("Rescued #{type}: #{message}. backtrace: #{bt.join("\n")}")
|
|
115
|
+
end
|
|
116
|
+
|
|
89
117
|
hash = {
|
|
90
118
|
result: nil,
|
|
91
119
|
error: {
|
|
@@ -93,7 +121,7 @@ class Bosh::Cpi::Cli
|
|
|
93
121
|
message: message,
|
|
94
122
|
ok_to_retry: ok_to_retry,
|
|
95
123
|
},
|
|
96
|
-
log: @logs_string_io.string
|
|
124
|
+
log: encode_string_as_utf8(@logs_string_io.string)
|
|
97
125
|
}
|
|
98
126
|
@result_io.print(JSON.dump(hash)); nil
|
|
99
127
|
end
|
|
@@ -102,7 +130,7 @@ class Bosh::Cpi::Cli
|
|
|
102
130
|
hash = {
|
|
103
131
|
result: result,
|
|
104
132
|
error: nil,
|
|
105
|
-
log: @logs_string_io.string
|
|
133
|
+
log: encode_string_as_utf8(@logs_string_io.string)
|
|
106
134
|
}
|
|
107
135
|
@result_io.print(JSON.dump(hash)); nil
|
|
108
136
|
end
|
|
@@ -110,4 +138,13 @@ class Bosh::Cpi::Cli
|
|
|
110
138
|
def error_name(error)
|
|
111
139
|
error.class.name
|
|
112
140
|
end
|
|
141
|
+
|
|
142
|
+
def encode_string_as_utf8(src)
|
|
143
|
+
log = @logs_string_io.string.force_encoding(Encoding::UTF_8)
|
|
144
|
+
unless log.valid_encoding?
|
|
145
|
+
# the src encoding hint of Encoding::BINARY is only required for ruby 1.9.3
|
|
146
|
+
log = @logs_string_io.string.encode(Encoding::UTF_8, Encoding::BINARY, undef: :replace, invalid: :replace)
|
|
147
|
+
end
|
|
148
|
+
log
|
|
149
|
+
end
|
|
113
150
|
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,15 @@
|
|
|
1
|
+
require 'logger'
|
|
2
|
+
|
|
3
|
+
class Bosh::Cpi::Logger < Logger
|
|
4
|
+
|
|
5
|
+
def initialize(log_device)
|
|
6
|
+
super(log_device)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def set_request_id(req_id)
|
|
10
|
+
original_formatter = Logger::Formatter.new
|
|
11
|
+
self.formatter = proc { |severity, datetime, progname, msg|
|
|
12
|
+
original_formatter.call(severity, datetime, "[req_id #{req_id}]#{progname}", msg)
|
|
13
|
+
}
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module Bosh::Cpi
|
|
2
|
+
class Redactor
|
|
3
|
+
|
|
4
|
+
REDACTED = '<redacted>'
|
|
5
|
+
|
|
6
|
+
def self.clone_and_redact(hash, *paths)
|
|
7
|
+
begin
|
|
8
|
+
hash = JSON.parse(hash.to_json)
|
|
9
|
+
rescue
|
|
10
|
+
return nil
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
redact!(hash, *paths)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.redact!(hash, *json_paths)
|
|
17
|
+
json_paths.each do |json_path|
|
|
18
|
+
properties = json_path.split('.')
|
|
19
|
+
property_to_redact = properties.pop
|
|
20
|
+
|
|
21
|
+
target_hash = properties.reduce(hash, &fetch_property)
|
|
22
|
+
target_hash[property_to_redact] = REDACTED if target_hash.has_key? property_to_redact
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
hash
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def self.fetch_property
|
|
29
|
+
-> (hash, property) { hash.fetch(property, {})}
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,107 @@
|
|
|
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
|
+
put_headers = @headers.merge('Content-Type' => 'application/json')
|
|
45
|
+
|
|
46
|
+
response = @client.put(url, {:body => payload, :header => put_headers})
|
|
47
|
+
|
|
48
|
+
unless HTTP::Status.successful?(response.status)
|
|
49
|
+
cloud_error("Cannot update settings for '#{instance_id}', got HTTP #{response.status}")
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
true
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
##
|
|
56
|
+
# Read instance settings from the registry
|
|
57
|
+
# @param [String] instance_id EC2 instance id
|
|
58
|
+
# @return [Hash] Agent settings
|
|
59
|
+
def read_settings(instance_id)
|
|
60
|
+
url = "#{@endpoint}/instances/#{instance_id}/settings"
|
|
61
|
+
|
|
62
|
+
response = @client.get(url, {:header => @headers})
|
|
63
|
+
|
|
64
|
+
if response.status != 200
|
|
65
|
+
cloud_error("Cannot read settings for '#{instance_id}', got HTTP #{response.status}")
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
body = JSON.load(response.body)
|
|
69
|
+
|
|
70
|
+
unless body.is_a?(Hash)
|
|
71
|
+
cloud_error("Invalid registry response, Hash expected, got #{body.class}: #{body}")
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
settings = JSON.load(body["settings"])
|
|
75
|
+
|
|
76
|
+
unless settings.is_a?(Hash)
|
|
77
|
+
cloud_error("Invalid settings format, Hash expected, got #{settings.class}: #{settings}")
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
settings
|
|
81
|
+
rescue JSON::ParserError => e
|
|
82
|
+
cloud_error("Cannot parse settings for '#{instance_id}': #{e.message}")
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
##
|
|
86
|
+
# Delete instance settings from the registry
|
|
87
|
+
# @param [String] instance_id EC2 instance id
|
|
88
|
+
# @return [Boolean]
|
|
89
|
+
def delete_settings(instance_id)
|
|
90
|
+
url = "#{@endpoint}/instances/#{instance_id}/settings"
|
|
91
|
+
|
|
92
|
+
response = @client.delete(url, {:header => @headers})
|
|
93
|
+
|
|
94
|
+
unless [200, 404].include? response.status
|
|
95
|
+
cloud_error("Cannot delete settings for '#{instance_id}', got HTTP #{response.status}")
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
true
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
private
|
|
102
|
+
|
|
103
|
+
def cloud_error(message)
|
|
104
|
+
raise Bosh::Clouds::CloudError, message
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
data/lib/bosh/cpi.rb
CHANGED
data/lib/cloud/errors.rb
CHANGED
data/lib/cloud/version.rb
CHANGED
data/lib/cloud.rb
CHANGED
|
@@ -6,222 +6,11 @@ require "forwardable"
|
|
|
6
6
|
|
|
7
7
|
require "cloud/config"
|
|
8
8
|
require "cloud/errors"
|
|
9
|
-
require "
|
|
10
|
-
require "cloud/external_cpi"
|
|
9
|
+
require "cloud_v1"
|
|
11
10
|
|
|
12
11
|
module Bosh
|
|
13
|
-
|
|
14
|
-
##
|
|
15
|
-
# CPI - Cloud Provider Interface, used for interfacing with various IaaS APIs.
|
|
16
|
-
#
|
|
17
|
-
# Key terms:
|
|
18
|
-
# Stemcell: template used for creating VMs (shouldn't be powered on)
|
|
19
|
-
# VM: VM created from a stemcell with custom settings (networking and resources)
|
|
20
|
-
# Disk: volume that can be attached and detached from the VMs,
|
|
21
|
-
# never attached to more than a single VM at one time
|
|
12
|
+
# Base class definition for backwards compatibility
|
|
22
13
|
class Cloud
|
|
23
|
-
|
|
24
|
-
##
|
|
25
|
-
# Cloud initialization
|
|
26
|
-
#
|
|
27
|
-
# @param [Hash] options cloud options
|
|
28
|
-
def initialize(options)
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
##
|
|
32
|
-
# Get the vm_id of this host
|
|
33
|
-
#
|
|
34
|
-
# @return [String] opaque id later used by other methods of the CPI
|
|
35
|
-
def current_vm_id
|
|
36
|
-
not_implemented(:current_vm_id)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
##
|
|
40
|
-
# Creates a stemcell
|
|
41
|
-
#
|
|
42
|
-
# @param [String] image_path path to an opaque blob containing the stemcell image
|
|
43
|
-
# @param [Hash] cloud_properties properties required for creating this template
|
|
44
|
-
# specific to a CPI
|
|
45
|
-
# @return [String] opaque id later used by {#create_vm} and {#delete_stemcell}
|
|
46
|
-
def create_stemcell(image_path, cloud_properties)
|
|
47
|
-
not_implemented(:create_stemcell)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
##
|
|
51
|
-
# Deletes a stemcell
|
|
52
|
-
#
|
|
53
|
-
# @param [String] stemcell stemcell id that was once returned by {#create_stemcell}
|
|
54
|
-
# @return [void]
|
|
55
|
-
def delete_stemcell(stemcell_id)
|
|
56
|
-
not_implemented(:delete_stemcell)
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
##
|
|
60
|
-
# Creates a VM - creates (and powers on) a VM from a stemcell with the proper resources
|
|
61
|
-
# and on the specified network. When disk locality is present the VM will be placed near
|
|
62
|
-
# the provided disk so it won't have to move when the disk is attached later.
|
|
63
|
-
#
|
|
64
|
-
# Sample networking config:
|
|
65
|
-
# {"network_a" =>
|
|
66
|
-
# {
|
|
67
|
-
# "netmask" => "255.255.248.0",
|
|
68
|
-
# "ip" => "172.30.41.40",
|
|
69
|
-
# "gateway" => "172.30.40.1",
|
|
70
|
-
# "dns" => ["172.30.22.153", "172.30.22.154"],
|
|
71
|
-
# "cloud_properties" => {"name" => "VLAN444"}
|
|
72
|
-
# }
|
|
73
|
-
# }
|
|
74
|
-
#
|
|
75
|
-
# Sample resource pool config (CPI specific):
|
|
76
|
-
# {
|
|
77
|
-
# "ram" => 512,
|
|
78
|
-
# "disk" => 512,
|
|
79
|
-
# "cpu" => 1
|
|
80
|
-
# }
|
|
81
|
-
# or similar for EC2:
|
|
82
|
-
# {"name" => "m1.small"}
|
|
83
|
-
#
|
|
84
|
-
# @param [String] agent_id UUID for the agent that will be used later on by the director
|
|
85
|
-
# to locate and talk to the agent
|
|
86
|
-
# @param [String] stemcell stemcell id that was once returned by {#create_stemcell}
|
|
87
|
-
# @param [Hash] resource_pool cloud specific properties describing the resources needed
|
|
88
|
-
# for this VM
|
|
89
|
-
# @param [Hash] networks list of networks and their settings needed for this VM
|
|
90
|
-
# @param [optional, String, Array] disk_locality disk id(s) if known of the disk(s) that will be
|
|
91
|
-
# attached to this vm
|
|
92
|
-
# @param [optional, Hash] env environment that will be passed to this vm
|
|
93
|
-
# @return [String] opaque id later used by {#configure_networks}, {#attach_disk},
|
|
94
|
-
# {#detach_disk}, and {#delete_vm}
|
|
95
|
-
def create_vm(agent_id, stemcell_id, resource_pool,
|
|
96
|
-
networks, disk_locality = nil, env = nil)
|
|
97
|
-
not_implemented(:create_vm)
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
##
|
|
101
|
-
# Deletes a VM
|
|
102
|
-
#
|
|
103
|
-
# @param [String] vm vm id that was once returned by {#create_vm}
|
|
104
|
-
# @return [void]
|
|
105
|
-
def delete_vm(vm_id)
|
|
106
|
-
not_implemented(:delete_vm)
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
##
|
|
110
|
-
# Checks if a VM exists
|
|
111
|
-
#
|
|
112
|
-
# @param [String] vm vm id that was once returned by {#create_vm}
|
|
113
|
-
# @return [Boolean] True if the vm exists
|
|
114
|
-
def has_vm?(vm_id)
|
|
115
|
-
not_implemented(:has_vm?)
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
##
|
|
119
|
-
# Reboots a VM
|
|
120
|
-
#
|
|
121
|
-
# @param [String] vm vm id that was once returned by {#create_vm}
|
|
122
|
-
# @param [Optional, Hash] CPI specific options (e.g hard/soft reboot)
|
|
123
|
-
# @return [void]
|
|
124
|
-
def reboot_vm(vm_id)
|
|
125
|
-
not_implemented(:reboot_vm)
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
##
|
|
129
|
-
# Set metadata for a VM
|
|
130
|
-
#
|
|
131
|
-
# Optional. Implement to provide more information for the IaaS.
|
|
132
|
-
#
|
|
133
|
-
# @param [String] vm vm id that was once returned by {#create_vm}
|
|
134
|
-
# @param [Hash] metadata metadata key/value pairs
|
|
135
|
-
# @return [void]
|
|
136
|
-
def set_vm_metadata(vm, metadata)
|
|
137
|
-
not_implemented(:set_vm_metadata)
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
##
|
|
141
|
-
# Configures networking an existing VM.
|
|
142
|
-
#
|
|
143
|
-
# @param [String] vm vm id that was once returned by {#create_vm}
|
|
144
|
-
# @param [Hash] networks list of networks and their settings needed for this VM,
|
|
145
|
-
# same as the networks argument in {#create_vm}
|
|
146
|
-
# @return [void]
|
|
147
|
-
def configure_networks(vm_id, networks)
|
|
148
|
-
not_implemented(:configure_networks)
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
##
|
|
152
|
-
# Creates a disk (possibly lazily) that will be attached later to a VM. When
|
|
153
|
-
# VM locality is specified the disk will be placed near the VM so it won't have to move
|
|
154
|
-
# when it's attached later.
|
|
155
|
-
#
|
|
156
|
-
# @param [Integer] size disk size in MB
|
|
157
|
-
# @param [optional, String] vm_locality vm id if known of the VM that this disk will
|
|
158
|
-
# be attached to
|
|
159
|
-
# @return [String] opaque id later used by {#attach_disk}, {#detach_disk}, and {#delete_disk}
|
|
160
|
-
def create_disk(size, vm_locality = nil)
|
|
161
|
-
not_implemented(:create_disk)
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
##
|
|
165
|
-
# Deletes a disk
|
|
166
|
-
# Will raise an exception if the disk is attached to a VM
|
|
167
|
-
#
|
|
168
|
-
# @param [String] disk disk id that was once returned by {#create_disk}
|
|
169
|
-
# @return [void]
|
|
170
|
-
def delete_disk(disk_id)
|
|
171
|
-
not_implemented(:delete_disk)
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
# Attaches a disk
|
|
175
|
-
# @param [String] vm vm id that was once returned by {#create_vm}
|
|
176
|
-
# @param [String] disk disk id that was once returned by {#create_disk}
|
|
177
|
-
# @return [void]
|
|
178
|
-
def attach_disk(vm_id, disk_id)
|
|
179
|
-
not_implemented(:attach_disk)
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
# Take snapshot of disk
|
|
183
|
-
# @param [String] disk_id disk id of the disk to take the snapshot of
|
|
184
|
-
# @param [Hash] metadata metadata key/value pairs
|
|
185
|
-
# @return [String] snapshot id
|
|
186
|
-
def snapshot_disk(disk_id, metadata={})
|
|
187
|
-
not_implemented(:snapshot_disk)
|
|
188
|
-
end
|
|
189
|
-
|
|
190
|
-
# Delete a disk snapshot
|
|
191
|
-
# @param [String] snapshot_id snapshot id to delete
|
|
192
|
-
# @return [void]
|
|
193
|
-
def delete_snapshot(snapshot_id)
|
|
194
|
-
not_implemented(:delete_snapshot)
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
# Detaches a disk
|
|
198
|
-
# @param [String] vm vm id that was once returned by {#create_vm}
|
|
199
|
-
# @param [String] disk disk id that was once returned by {#create_disk}
|
|
200
|
-
# @return [void]
|
|
201
|
-
def detach_disk(vm_id, disk_id)
|
|
202
|
-
not_implemented(:detach_disk)
|
|
203
|
-
end
|
|
204
|
-
|
|
205
|
-
# List the attached disks of the VM.
|
|
206
|
-
# @param [String] vm_id is the CPI-standard vm_id (eg, returned from current_vm_id)
|
|
207
|
-
# @return [array[String]] list of opaque disk_ids that can be used with the
|
|
208
|
-
# other disk-related methods on the CPI
|
|
209
|
-
def get_disks(vm_id)
|
|
210
|
-
not_implemented(:get_disks)
|
|
211
|
-
end
|
|
212
|
-
|
|
213
|
-
# Validates the deployment
|
|
214
|
-
# @api not_yet_used
|
|
215
|
-
def validate_deployment(old_manifest, new_manifest)
|
|
216
|
-
not_implemented(:validate_deployment)
|
|
217
|
-
end
|
|
218
|
-
|
|
219
|
-
private
|
|
220
|
-
|
|
221
|
-
def not_implemented(method)
|
|
222
|
-
raise Bosh::Clouds::NotImplemented,
|
|
223
|
-
"`#{method}' is not implemented by #{self.class}"
|
|
224
|
-
end
|
|
225
|
-
|
|
14
|
+
include Bosh::CloudV1
|
|
226
15
|
end
|
|
227
16
|
end
|
data/lib/cloud_v1.rb
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
# Copyright (c) 2009-2012 VMware, Inc.
|
|
2
|
+
|
|
3
|
+
module Bosh; module Clouds; end; end
|
|
4
|
+
|
|
5
|
+
require "forwardable"
|
|
6
|
+
|
|
7
|
+
require "cloud/config"
|
|
8
|
+
require "cloud/errors"
|
|
9
|
+
|
|
10
|
+
module Bosh
|
|
11
|
+
|
|
12
|
+
##
|
|
13
|
+
# CPI - Cloud Provider Interface, used for interfacing with various IaaS APIs.
|
|
14
|
+
#
|
|
15
|
+
# Key terms:
|
|
16
|
+
# Stemcell: template used for creating VMs (shouldn't be powered on)
|
|
17
|
+
# VM: VM created from a stemcell with custom settings (networking and resources)
|
|
18
|
+
# Disk: volume that can be attached and detached from the VMs,
|
|
19
|
+
# never attached to more than a single VM at one time
|
|
20
|
+
module CloudV1
|
|
21
|
+
## Information about cpi
|
|
22
|
+
#
|
|
23
|
+
# Sample info response:
|
|
24
|
+
# {
|
|
25
|
+
# "stemcell_formats" => ["aws-raw", "aws-light"],
|
|
26
|
+
# "api_version" => <highest supported version>,
|
|
27
|
+
# }
|
|
28
|
+
# @return [Hash] information about cpi, currently supported stemcell formats; CPI api_version this cpi supports
|
|
29
|
+
def info
|
|
30
|
+
not_implemented(:info)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
##
|
|
34
|
+
# Get the vm_id of this host
|
|
35
|
+
#
|
|
36
|
+
# @return [String] opaque id later used by other methods of the CPI
|
|
37
|
+
def current_vm_id
|
|
38
|
+
not_implemented(:current_vm_id)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
##
|
|
42
|
+
# Creates a stemcell
|
|
43
|
+
#
|
|
44
|
+
# @param [String] image_path path to an opaque blob containing the stemcell image
|
|
45
|
+
# @param [Hash] cloud_properties properties required for creating this template
|
|
46
|
+
# specific to a CPI
|
|
47
|
+
# @return [String] opaque id later used by {#create_vm} and {#delete_stemcell}
|
|
48
|
+
def create_stemcell(image_path, cloud_properties)
|
|
49
|
+
not_implemented(:create_stemcell)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
##
|
|
53
|
+
# Deletes a stemcell
|
|
54
|
+
#
|
|
55
|
+
# @param [String] stemcell stemcell id that was once returned by {#create_stemcell}
|
|
56
|
+
# @return [void]
|
|
57
|
+
def delete_stemcell(stemcell_id)
|
|
58
|
+
not_implemented(:delete_stemcell)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
##
|
|
62
|
+
# Creates a VM - creates (and powers on) a VM from a stemcell with the proper resources
|
|
63
|
+
# and on the specified network. When disk locality is present the VM will be placed near
|
|
64
|
+
# the provided disk so it won't have to move when the disk is attached later.
|
|
65
|
+
#
|
|
66
|
+
# Sample networking config:
|
|
67
|
+
# {"network_a" =>
|
|
68
|
+
# {
|
|
69
|
+
# "netmask" => "255.255.248.0",
|
|
70
|
+
# "ip" => "172.30.41.40",
|
|
71
|
+
# "gateway" => "172.30.40.1",
|
|
72
|
+
# "dns" => ["172.30.22.153", "172.30.22.154"],
|
|
73
|
+
# "cloud_properties" => {"name" => "VLAN444"}
|
|
74
|
+
# }
|
|
75
|
+
# }
|
|
76
|
+
#
|
|
77
|
+
# Sample resource pool config (CPI specific):
|
|
78
|
+
# {
|
|
79
|
+
# "ram" => 512,
|
|
80
|
+
# "disk" => 512,
|
|
81
|
+
# "cpu" => 1
|
|
82
|
+
# }
|
|
83
|
+
# or similar for EC2:
|
|
84
|
+
# {"name" => "m1.small"}
|
|
85
|
+
#
|
|
86
|
+
# @param [String] agent_id UUID for the agent that will be used later on by the director
|
|
87
|
+
# to locate and talk to the agent
|
|
88
|
+
# @param [String] stemcell_id stemcell id that was once returned by {#create_stemcell}
|
|
89
|
+
# @param [Hash] resource_pool cloud specific properties describing the resources needed
|
|
90
|
+
# for this VM
|
|
91
|
+
# @param [Hash] networks list of networks and their settings needed for this VM
|
|
92
|
+
# @param [String, Array] disk_locality disk id(s) if known of the disk(s) that will be
|
|
93
|
+
# attached to this vm
|
|
94
|
+
# @param [Hash] env environment that will be passed to this vm
|
|
95
|
+
# @return [String] opaque id later used by {#attach_disk}, {#detach_disk} and {#delete_vm}
|
|
96
|
+
def create_vm(agent_id, stemcell_id, resource_pool, networks, disk_locality, env)
|
|
97
|
+
not_implemented(:create_vm)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
##
|
|
101
|
+
# Deletes a VM. If the VM has already been deleted, this call returns normally and has no effect.
|
|
102
|
+
#
|
|
103
|
+
# @param [String] vm vm id that was once returned by {#create_vm}
|
|
104
|
+
# @return [void]
|
|
105
|
+
def delete_vm(vm_id)
|
|
106
|
+
not_implemented(:delete_vm)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
##
|
|
110
|
+
# Checks if a VM exists
|
|
111
|
+
#
|
|
112
|
+
# @param [String] vm vm id that was once returned by {#create_vm}
|
|
113
|
+
# @return [Boolean] True if the vm exists
|
|
114
|
+
def has_vm?(vm_id)
|
|
115
|
+
not_implemented(:has_vm?)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
##
|
|
119
|
+
# Checks if a disk exists
|
|
120
|
+
#
|
|
121
|
+
# @param [String] disk disk_id that was once returned by {#create_disk}
|
|
122
|
+
# @return [Boolean] True if the disk exists
|
|
123
|
+
def has_disk?(disk_id)
|
|
124
|
+
not_implemented(:has_disk?)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
##
|
|
128
|
+
# Reboots a VM
|
|
129
|
+
#
|
|
130
|
+
# @param [String] vm vm id that was once returned by {#create_vm}
|
|
131
|
+
# @param [Optional, Hash] CPI specific options (e.g hard/soft reboot)
|
|
132
|
+
# @return [void]
|
|
133
|
+
def reboot_vm(vm_id)
|
|
134
|
+
not_implemented(:reboot_vm)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
##
|
|
138
|
+
# Set metadata for a VM
|
|
139
|
+
#
|
|
140
|
+
# Optional. Implement to provide more information for the IaaS.
|
|
141
|
+
#
|
|
142
|
+
# @param [String] vm vm id that was once returned by {#create_vm}
|
|
143
|
+
# @param [Hash] metadata metadata key/value pairs
|
|
144
|
+
# @return [void]
|
|
145
|
+
def set_vm_metadata(vm, metadata)
|
|
146
|
+
not_implemented(:set_vm_metadata)
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
##
|
|
150
|
+
# Set metadata for a disk
|
|
151
|
+
#
|
|
152
|
+
# Optional. Implement to provide more information for the IaaS.
|
|
153
|
+
#
|
|
154
|
+
# @param [String] disk_id disk id that was once returned by {#create_disk}
|
|
155
|
+
# @param [Hash] metadata metadata key/value pairs
|
|
156
|
+
# @return [void]
|
|
157
|
+
def set_disk_metadata(disk_id, metadata)
|
|
158
|
+
not_implemented(:set_disk_metadata)
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
##
|
|
162
|
+
# Creates a disk (possibly lazily) that will be attached later to a VM. When
|
|
163
|
+
# VM locality is specified the disk will be placed near the VM so it won't have to move
|
|
164
|
+
# when it's attached later.
|
|
165
|
+
#
|
|
166
|
+
# @param [Integer] size disk size in MB
|
|
167
|
+
# @param [Hash] cloud_properties properties required for creating this disk
|
|
168
|
+
# specific to a CPI
|
|
169
|
+
# @param [String] vm_locality vm id if known of the VM that this disk will
|
|
170
|
+
# be attached to
|
|
171
|
+
# @return [String] opaque id later used by {#attach_disk}, {#detach_disk}, and {#delete_disk}
|
|
172
|
+
def create_disk(size, cloud_properties, vm_locality)
|
|
173
|
+
not_implemented(:create_disk)
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
##
|
|
177
|
+
# Deletes a disk
|
|
178
|
+
# Will raise an exception if the disk is attached to a VM
|
|
179
|
+
#
|
|
180
|
+
# @param [String] disk disk id that was once returned by {#create_disk}
|
|
181
|
+
# @return [void]
|
|
182
|
+
def delete_disk(disk_id)
|
|
183
|
+
not_implemented(:delete_disk)
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
# Attaches a disk
|
|
187
|
+
# @param [String] vm vm id that was once returned by {#create_vm}
|
|
188
|
+
# @param [String] disk disk id that was once returned by {#create_disk}
|
|
189
|
+
# @return [void]
|
|
190
|
+
def attach_disk(vm_id, disk_id)
|
|
191
|
+
not_implemented(:attach_disk)
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
# Take snapshot of disk
|
|
195
|
+
# @param [String] disk_id disk id of the disk to take the snapshot of
|
|
196
|
+
# @param [Hash] metadata metadata key/value pairs
|
|
197
|
+
# @return [String] snapshot id
|
|
198
|
+
def snapshot_disk(disk_id, metadata)
|
|
199
|
+
not_implemented(:snapshot_disk)
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
# Delete a disk snapshot
|
|
203
|
+
# @param [String] snapshot_id snapshot id to delete
|
|
204
|
+
# @return [void]
|
|
205
|
+
def delete_snapshot(snapshot_id)
|
|
206
|
+
not_implemented(:delete_snapshot)
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
# Detaches a disk
|
|
210
|
+
# @param [String] vm vm id that was once returned by {#create_vm}
|
|
211
|
+
# @param [String] disk disk id that was once returned by {#create_disk}
|
|
212
|
+
# @return [void]
|
|
213
|
+
def detach_disk(vm_id, disk_id)
|
|
214
|
+
not_implemented(:detach_disk)
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
# List the attached disks of the VM.
|
|
218
|
+
# @param [String] vm_id is the CPI-standard vm_id (eg, returned from current_vm_id)
|
|
219
|
+
# @return [array[String]] list of opaque disk_ids that can be used with the
|
|
220
|
+
# other disk-related methods on the CPI
|
|
221
|
+
def get_disks(vm_id)
|
|
222
|
+
not_implemented(:get_disks)
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
##
|
|
226
|
+
# Resizes an existing disk
|
|
227
|
+
#
|
|
228
|
+
# @param [String] disk_id disk id
|
|
229
|
+
# @param [Integer] new_size disk size in MiB
|
|
230
|
+
# @return [void]
|
|
231
|
+
def resize_disk(disk_id, new_size)
|
|
232
|
+
not_implemented(:resize_disk)
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
# Specify VM's hardware resources
|
|
236
|
+
# @param [Hash] vm_properties (typically cpu, ram, ephemeral_disk_size)
|
|
237
|
+
# @return [Hash] opaque description of the VM's configuration that
|
|
238
|
+
# can be used with {#create_vm}
|
|
239
|
+
def calculate_vm_cloud_properties(vm_properties)
|
|
240
|
+
not_implemented(:calculate_vm_cloud_properties)
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
##
|
|
244
|
+
# Creates a network that will be used to place VMs on.
|
|
245
|
+
#
|
|
246
|
+
# @param [Hash] network_definition properties required for creating network.
|
|
247
|
+
# may contain range and gateway keys. Has to have cloud_properties - properties required for creating
|
|
248
|
+
# this network specific to a CPI
|
|
249
|
+
# @return [Hash] network_cid key has unique id of network, cloud_properties are properties required for placing VMs
|
|
250
|
+
def create_network(network_definition)
|
|
251
|
+
not_implemented(:create_network)
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
##
|
|
255
|
+
# Deletes network by given network_id
|
|
256
|
+
# @param [String] network_id of network to delete
|
|
257
|
+
# @return [void]
|
|
258
|
+
def delete_network(network_id)
|
|
259
|
+
not_implemented(:delete_network)
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
private
|
|
263
|
+
|
|
264
|
+
def not_implemented(method)
|
|
265
|
+
raise Bosh::Clouds::NotImplemented,
|
|
266
|
+
"'#{method}' is not implemented by #{self.class}"
|
|
267
|
+
end
|
|
268
|
+
end
|
|
269
|
+
end
|
|
270
|
+
|
data/lib/cloud_v2.rb
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# Copyright (c) 2009-2018 VMware, Inc.
|
|
2
|
+
|
|
3
|
+
module Bosh; module Clouds; end; end
|
|
4
|
+
|
|
5
|
+
require "forwardable"
|
|
6
|
+
|
|
7
|
+
require "cloud/config"
|
|
8
|
+
require "cloud/errors"
|
|
9
|
+
require "cloud_v1"
|
|
10
|
+
|
|
11
|
+
module Bosh
|
|
12
|
+
|
|
13
|
+
##
|
|
14
|
+
# CPI - Cloud Provider Interface, used for interfacing with various IaaS APIs.
|
|
15
|
+
#
|
|
16
|
+
# Key terms:
|
|
17
|
+
# Stemcell: template used for creating VMs (shouldn't be powered on)
|
|
18
|
+
# VM: VM created from a stemcell with custom settings (networking and resources)
|
|
19
|
+
# Disk: volume that can be attached and detached from the VMs,
|
|
20
|
+
# never attached to more than a single VM at one time
|
|
21
|
+
module CloudV2
|
|
22
|
+
include Bosh::CloudV1
|
|
23
|
+
##
|
|
24
|
+
# Creates a VM - creates (and powers on) a VM from a stemcell with the proper resources
|
|
25
|
+
# and on the specified network. When disk locality is present the VM will be placed near
|
|
26
|
+
# the provided disk so it won't have to move when the disk is attached later.
|
|
27
|
+
#
|
|
28
|
+
# Sample networking config:
|
|
29
|
+
# {"network_a" =>
|
|
30
|
+
# {
|
|
31
|
+
# "netmask" => "255.255.248.0",
|
|
32
|
+
# "ip" => "172.30.41.40",
|
|
33
|
+
# "gateway" => "172.30.40.1",
|
|
34
|
+
# "dns" => ["172.30.22.153", "172.30.22.154"],
|
|
35
|
+
# "cloud_properties" => {"name" => "VLAN444"}
|
|
36
|
+
# }
|
|
37
|
+
# }
|
|
38
|
+
#
|
|
39
|
+
# Sample resource pool config (CPI specific):
|
|
40
|
+
# {
|
|
41
|
+
# "ram" => 512,
|
|
42
|
+
# "disk" => 512,
|
|
43
|
+
# "cpu" => 1
|
|
44
|
+
# }
|
|
45
|
+
# or similar for EC2:
|
|
46
|
+
# {"name" => "m1.small"}
|
|
47
|
+
#
|
|
48
|
+
# Sample return value:
|
|
49
|
+
# [
|
|
50
|
+
# "vm-cid-123",
|
|
51
|
+
# { # ... networks ...
|
|
52
|
+
# "private": {
|
|
53
|
+
# "type": "manual",
|
|
54
|
+
# "netmask": "255.255.255.0",
|
|
55
|
+
# "gateway": "10.230.13.1",
|
|
56
|
+
# "ip": "10.230.13.6",
|
|
57
|
+
# "default": [ "dns", "gateway" ],
|
|
58
|
+
# "cloud_properties": {
|
|
59
|
+
# "net_id": "d29fdb0d-44d8-4e04-818d-5b03888f8eaa"
|
|
60
|
+
# }
|
|
61
|
+
# },
|
|
62
|
+
# "public": {
|
|
63
|
+
# "type": "vip",
|
|
64
|
+
# "ip": "173.101.112.104",
|
|
65
|
+
# "cloud_properties": {}
|
|
66
|
+
# }
|
|
67
|
+
# }
|
|
68
|
+
# ]
|
|
69
|
+
#
|
|
70
|
+
# @param [String] agent_id UUID for the agent that will be used later on by the director
|
|
71
|
+
# to locate and talk to the agent
|
|
72
|
+
# @param [String] stemcell_id stemcell id that was once returned by {#create_stemcell}
|
|
73
|
+
# @param [Hash] resource_pool cloud specific properties describing the resources needed
|
|
74
|
+
# for this VM
|
|
75
|
+
# @param [Hash] networks list of networks and their settings needed for this VM
|
|
76
|
+
# @param [String, Array] disk_locality disk id(s) if known of the disk(s) that will be
|
|
77
|
+
# attached to this vm
|
|
78
|
+
# @param [Hash] env environment that will be passed to this vm
|
|
79
|
+
# @return [Array] [VM_ID, {...networks...}]
|
|
80
|
+
def create_vm(agent_id, stemcell_id, resource_pool, networks, disk_locality, env)
|
|
81
|
+
not_implemented(:create_vm)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Attaches a disk
|
|
85
|
+
# @param [String] vm vm id that was once returned by {#create_vm}
|
|
86
|
+
# @param [String] disk disk id that was once returned by {#create_disk}
|
|
87
|
+
# @return [Object] hint for location of attached disk - varies by IaaS
|
|
88
|
+
#
|
|
89
|
+
# Sample return value for attach_disk
|
|
90
|
+
# "/dev/sdd"
|
|
91
|
+
#
|
|
92
|
+
def attach_disk(vm_id, disk_id)
|
|
93
|
+
not_implemented(:attach_disk)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
private
|
|
97
|
+
|
|
98
|
+
def not_implemented(method)
|
|
99
|
+
raise Bosh::Clouds::NotImplemented, "'#{method}' is not implemented by #{self.class}"
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
metadata
CHANGED
|
@@ -1,35 +1,44 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bosh_cpi
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
5
|
-
prerelease:
|
|
4
|
+
version: 2.5.0
|
|
6
5
|
platform: ruby
|
|
7
6
|
authors:
|
|
8
7
|
- VMware
|
|
9
8
|
autorequire:
|
|
10
9
|
bindir: bin
|
|
11
10
|
cert_chain: []
|
|
12
|
-
date:
|
|
11
|
+
date: 2018-08-15 00:00:00.000000000 Z
|
|
13
12
|
dependencies:
|
|
14
13
|
- !ruby/object:Gem::Dependency
|
|
15
|
-
name:
|
|
14
|
+
name: membrane
|
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
|
17
|
-
none: false
|
|
18
16
|
requirements:
|
|
19
|
-
- - ~>
|
|
17
|
+
- - "~>"
|
|
20
18
|
- !ruby/object:Gem::Version
|
|
21
|
-
version: 1.
|
|
19
|
+
version: 1.1.0
|
|
22
20
|
type: :runtime
|
|
23
21
|
prerelease: false
|
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
-
none: false
|
|
26
23
|
requirements:
|
|
27
|
-
- - ~>
|
|
24
|
+
- - "~>"
|
|
28
25
|
- !ruby/object:Gem::Version
|
|
29
|
-
version: 1.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
version: 1.1.0
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: httpclient
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 2.8.3
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 2.8.3
|
|
41
|
+
description: BOSH CPI
|
|
33
42
|
email: support@cloudfoundry.com
|
|
34
43
|
executables: []
|
|
35
44
|
extensions: []
|
|
@@ -39,41 +48,39 @@ files:
|
|
|
39
48
|
- lib/bosh/cpi/cli.rb
|
|
40
49
|
- lib/bosh/cpi/compatibility_helpers.rb
|
|
41
50
|
- lib/bosh/cpi/compatibility_helpers/delete_vm.rb
|
|
51
|
+
- lib/bosh/cpi/logger.rb
|
|
52
|
+
- lib/bosh/cpi/redactor.rb
|
|
53
|
+
- lib/bosh/cpi/registry_client.rb
|
|
42
54
|
- lib/bosh/cpi/tasks.rb
|
|
43
55
|
- lib/bosh/cpi/tasks/spec.rake
|
|
44
56
|
- lib/cloud.rb
|
|
45
57
|
- lib/cloud/config.rb
|
|
46
58
|
- lib/cloud/errors.rb
|
|
47
|
-
- lib/cloud/external_cpi.rb
|
|
48
|
-
- lib/cloud/provider.rb
|
|
49
59
|
- lib/cloud/version.rb
|
|
50
|
-
-
|
|
60
|
+
- lib/cloud_v1.rb
|
|
61
|
+
- lib/cloud_v2.rb
|
|
51
62
|
homepage: https://github.com/cloudfoundry/bosh
|
|
52
63
|
licenses:
|
|
53
64
|
- Apache 2.0
|
|
65
|
+
metadata: {}
|
|
54
66
|
post_install_message:
|
|
55
67
|
rdoc_options: []
|
|
56
68
|
require_paths:
|
|
57
69
|
- lib
|
|
58
70
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
59
|
-
none: false
|
|
60
71
|
requirements:
|
|
61
|
-
- -
|
|
72
|
+
- - ">="
|
|
62
73
|
- !ruby/object:Gem::Version
|
|
63
74
|
version: 1.9.3
|
|
64
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
|
-
none: false
|
|
66
76
|
requirements:
|
|
67
|
-
- -
|
|
77
|
+
- - ">="
|
|
68
78
|
- !ruby/object:Gem::Version
|
|
69
79
|
version: '0'
|
|
70
|
-
segments:
|
|
71
|
-
- 0
|
|
72
|
-
hash: -2094969827085848795
|
|
73
80
|
requirements: []
|
|
74
81
|
rubyforge_project:
|
|
75
|
-
rubygems_version:
|
|
82
|
+
rubygems_version: 2.7.7
|
|
76
83
|
signing_key:
|
|
77
|
-
specification_version:
|
|
84
|
+
specification_version: 4
|
|
78
85
|
summary: BOSH CPI
|
|
79
86
|
test_files: []
|
data/README
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
BOSH Cloud Provider Interface
|
data/lib/cloud/external_cpi.rb
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
require 'membrane'
|
|
2
|
-
require 'open3'
|
|
3
|
-
|
|
4
|
-
module Bosh::Clouds
|
|
5
|
-
class ExternalCpi
|
|
6
|
-
##
|
|
7
|
-
# Raised when the external CPI executable returns an error unknown to director
|
|
8
|
-
#
|
|
9
|
-
class UnknownError < StandardError; end
|
|
10
|
-
|
|
11
|
-
##
|
|
12
|
-
# Raised when the external CPI executable returns nil or invalid JSON format to director
|
|
13
|
-
class InvalidResponse < StandardError; end
|
|
14
|
-
|
|
15
|
-
##
|
|
16
|
-
# Raised when the external CPI bin/cpi is not executable
|
|
17
|
-
class NonExecutable < StandardError; end
|
|
18
|
-
|
|
19
|
-
KNOWN_RPC_ERRORS = %w(
|
|
20
|
-
Bosh::Clouds::VMCreationFailed
|
|
21
|
-
Bosh::Clouds::DiskNotFound
|
|
22
|
-
Bosh::Clouds::DiskNotAttached
|
|
23
|
-
Bosh::Clouds::NoDiskSpace
|
|
24
|
-
Bosh::Clouds::CloudError
|
|
25
|
-
Bosh::Clouds::CpiError
|
|
26
|
-
).freeze
|
|
27
|
-
|
|
28
|
-
KNOWN_RPC_METHODS = %w(
|
|
29
|
-
current_vm_id
|
|
30
|
-
create_stemcell
|
|
31
|
-
delete_stemcell
|
|
32
|
-
create_vm
|
|
33
|
-
delete_vm
|
|
34
|
-
has_vm?
|
|
35
|
-
reboot_vm
|
|
36
|
-
set_vm_metadata
|
|
37
|
-
configure_networks
|
|
38
|
-
create_disk
|
|
39
|
-
delete_disk
|
|
40
|
-
attach_disk
|
|
41
|
-
detach_disk
|
|
42
|
-
snapshot_disk
|
|
43
|
-
delete_snapshot
|
|
44
|
-
get_disks
|
|
45
|
-
ping
|
|
46
|
-
).freeze
|
|
47
|
-
|
|
48
|
-
RESPONSE_SCHEMA = Membrane::SchemaParser.parse do
|
|
49
|
-
{
|
|
50
|
-
'result' => any,
|
|
51
|
-
'error' => enum(nil,
|
|
52
|
-
{ 'type' => String,
|
|
53
|
-
'message' => String,
|
|
54
|
-
'ok_to_retry' => bool
|
|
55
|
-
}
|
|
56
|
-
),
|
|
57
|
-
'log' => String
|
|
58
|
-
}
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def initialize(cpi_path, director_uuid)
|
|
62
|
-
@cpi_path = cpi_path
|
|
63
|
-
@director_uuid = director_uuid
|
|
64
|
-
@logger = Config.logger
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
KNOWN_RPC_METHODS.each do |method_name|
|
|
68
|
-
define_method method_name do |*arguments|
|
|
69
|
-
request = JSON.dump({
|
|
70
|
-
'method' => method_name.gsub(/\?$/,''),
|
|
71
|
-
'arguments' => arguments,
|
|
72
|
-
'context' => {
|
|
73
|
-
'director_uuid' => @director_uuid
|
|
74
|
-
}
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
env = {'PATH' => '/usr/sbin:/usr/bin:/sbin:/bin', 'TMPDIR' => ENV['TMPDIR']}
|
|
78
|
-
cpi_exec_path = checked_cpi_exec_path
|
|
79
|
-
|
|
80
|
-
@logger.debug("External CPI sending request: #{request} with command: #{cpi_exec_path}")
|
|
81
|
-
cpi_response, stderr, exit_status = Open3.capture3(env, cpi_exec_path, stdin_data: request)
|
|
82
|
-
@logger.debug("External CPI got response: #{cpi_response}, err: #{stderr}, exit_status: #{exit_status}")
|
|
83
|
-
|
|
84
|
-
parsed_response = parsed_response(cpi_response)
|
|
85
|
-
validate_response(parsed_response)
|
|
86
|
-
|
|
87
|
-
if parsed_response['error']
|
|
88
|
-
handle_error(parsed_response['error'])
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
save_cpi_log(parsed_response['log'])
|
|
92
|
-
|
|
93
|
-
parsed_response['result']
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
private
|
|
98
|
-
|
|
99
|
-
def checked_cpi_exec_path
|
|
100
|
-
unless File.executable?(@cpi_path)
|
|
101
|
-
raise NonExecutable, "Failed to run cpi: `#{@cpi_path}' is not executable"
|
|
102
|
-
end
|
|
103
|
-
@cpi_path
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
def handle_error(error_response)
|
|
107
|
-
error_type = error_response['type']
|
|
108
|
-
error_message = error_response['message']
|
|
109
|
-
unless KNOWN_RPC_ERRORS.include?(error_type)
|
|
110
|
-
raise UnknownError, "Received unknown error from cpi: #{error_type} with message #{error_message}"
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
error_class = constantize(error_type)
|
|
114
|
-
|
|
115
|
-
if error_class <= RetriableCloudError
|
|
116
|
-
error = error_class.new(error_response['ok_to_retry'])
|
|
117
|
-
else
|
|
118
|
-
error = error_class.new(error_message)
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
raise error, error_message
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
def save_cpi_log(output)
|
|
125
|
-
# cpi log path is set up at the beginning of every task in Config
|
|
126
|
-
# see JobRunner#setup_task_logging
|
|
127
|
-
File.open(Config.cpi_task_log, 'a') do |f|
|
|
128
|
-
f.write(output)
|
|
129
|
-
end
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
def parsed_response(input)
|
|
133
|
-
begin
|
|
134
|
-
JSON.load(input)
|
|
135
|
-
rescue JSON::ParserError => e
|
|
136
|
-
raise InvalidResponse, "Received invalid response from cpi with error #{e.message}"
|
|
137
|
-
end
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
def validate_response(response)
|
|
141
|
-
RESPONSE_SCHEMA.validate(response)
|
|
142
|
-
rescue Membrane::SchemaValidationError => e
|
|
143
|
-
raise InvalidResponse, "Received invalid response from cpi with error #{e.message}"
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
def constantize(camel_cased_word)
|
|
147
|
-
error_name = camel_cased_word.split('::').last
|
|
148
|
-
Bosh::Clouds.const_get(error_name)
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
end
|
data/lib/cloud/provider.rb
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
module Bosh::Clouds
|
|
2
|
-
class Provider
|
|
3
|
-
def self.create(cloud_config, director_uuid)
|
|
4
|
-
if cloud_config.fetch('external_cpi',{}).fetch('enabled', false)
|
|
5
|
-
ExternalCpiProvider.create(cloud_config['external_cpi'], director_uuid)
|
|
6
|
-
else
|
|
7
|
-
PluginCloudProvider.create(cloud_config['plugin'], cloud_config['properties'])
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
private
|
|
13
|
-
|
|
14
|
-
class PluginCloudProvider
|
|
15
|
-
def self.create(plugin, options)
|
|
16
|
-
begin
|
|
17
|
-
require "cloud/#{plugin}"
|
|
18
|
-
rescue LoadError => error
|
|
19
|
-
raise CloudError, "Could not load Cloud Provider Plugin: #{plugin}"
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
Bosh::Clouds.const_get(plugin.capitalize).new(options)
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
class ExternalCpiProvider
|
|
27
|
-
def self.create(external_cpi_config, director_uuid)
|
|
28
|
-
ExternalCpi.new(external_cpi_config['cpi_path'], director_uuid)
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|