bosh_cpi 1.2200.0 → 1.2291.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/bosh/cpi.rb CHANGED
@@ -1,3 +1,5 @@
1
1
  module Bosh
2
2
  module Cpi; end
3
3
  end
4
+
5
+ require 'bosh/cpi/cli'
@@ -0,0 +1,110 @@
1
+ require 'json'
2
+
3
+ class Bosh::Cpi::Cli
4
+ KNOWN_RPC_METHODS = %w(
5
+ current_vm_id
6
+ create_stemcell
7
+ delete_stemcell
8
+ create_vm
9
+ delete_vm
10
+ has_vm
11
+ reboot_vm
12
+ set_vm_metadata
13
+ configure_networks
14
+ create_disk
15
+ delete_disk
16
+ attach_disk
17
+ detach_disk
18
+ snapshot_disk
19
+ delete_snapshot
20
+ get_disks
21
+ ping
22
+ ).freeze
23
+
24
+ RPC_METHOD_TO_RUBY_METHOD = {
25
+ 'has_vm' => 'has_vm?',
26
+ }.freeze
27
+
28
+ INVALID_CALL_ERROR_TYPE = 'InvalidCall'.freeze
29
+ UNKNOWN_ERROR_TYPE = 'Unknown'.freeze
30
+
31
+ def initialize(cpi, result_io)
32
+ @cpi = cpi
33
+ @result_io = result_io
34
+ end
35
+
36
+ def run(json)
37
+ begin
38
+ request = JSON.load(json)
39
+ rescue JSON::ParserError
40
+ return error_response(INVALID_CALL_ERROR_TYPE, 'Request cannot be deserialized', false)
41
+ end
42
+
43
+ method = request['method']
44
+ unless method.is_a?(String)
45
+ return error_response(INVALID_CALL_ERROR_TYPE, 'Method must be a String', false)
46
+ end
47
+
48
+ unless KNOWN_RPC_METHODS.include?(method)
49
+ return error_response(INVALID_CALL_ERROR_TYPE, 'Method is not known', false)
50
+ end
51
+
52
+ arguments = request['arguments']
53
+ unless arguments.is_a?(Array)
54
+ return error_response(INVALID_CALL_ERROR_TYPE, 'Arguments must be an Array', false)
55
+ end
56
+
57
+ context = request['context']
58
+ unless context.is_a?(Hash) && context['director_uuid'].is_a?(String)
59
+ return error_response(INVALID_CALL_ERROR_TYPE, 'Request should include context with director uuid', false)
60
+ end
61
+
62
+ configure_director(context['director_uuid'])
63
+
64
+ ruby_method = RPC_METHOD_TO_RUBY_METHOD[method] || method
65
+
66
+ begin
67
+ result = @cpi.public_send(ruby_method, *arguments)
68
+ rescue Bosh::Clouds::RetriableCloudError => e
69
+ return error_response(error_name(e), e.message, e.ok_to_retry)
70
+ rescue Bosh::Clouds::CloudError, Bosh::Clouds::CpiError => e
71
+ return error_response(error_name(e), e.message, false)
72
+ rescue ArgumentError
73
+ return error_response(INVALID_CALL_ERROR_TYPE, 'Arguments are not correct', false)
74
+ rescue Exception => e
75
+ return error_response(UNKNOWN_ERROR_TYPE, e.message, false)
76
+ end
77
+
78
+ result_response(result)
79
+ end
80
+
81
+ private
82
+
83
+ def configure_director(director_uuid)
84
+ Bosh::Clouds::Config.uuid = director_uuid
85
+ end
86
+
87
+ def error_response(type, message, ok_to_retry)
88
+ hash = {
89
+ result: nil,
90
+ error: {
91
+ type: type,
92
+ message: message,
93
+ ok_to_retry: ok_to_retry,
94
+ },
95
+ }
96
+ @result_io.print(JSON.dump(hash)); nil
97
+ end
98
+
99
+ def result_response(result)
100
+ hash = {
101
+ result: result,
102
+ error: nil,
103
+ }
104
+ @result_io.print(JSON.dump(hash)); nil
105
+ end
106
+
107
+ def error_name(error)
108
+ error.class.name
109
+ end
110
+ end
data/lib/cloud.rb CHANGED
@@ -170,9 +170,7 @@ module Bosh
170
170
  not_implemented(:delete_disk)
171
171
  end
172
172
 
173
- ##
174
173
  # Attaches a disk
175
- #
176
174
  # @param [String] vm vm id that was once returned by {#create_vm}
177
175
  # @param [String] disk disk id that was once returned by {#create_disk}
178
176
  # @return [void]
@@ -182,6 +180,7 @@ module Bosh
182
180
 
183
181
  # Take snapshot of disk
184
182
  # @param [String] disk_id disk id of the disk to take the snapshot of
183
+ # @param [Hash] metadata metadata key/value pairs
185
184
  # @return [String] snapshot id
186
185
  def snapshot_disk(disk_id, metadata={})
187
186
  not_implemented(:snapshot_disk)
@@ -189,13 +188,12 @@ module Bosh
189
188
 
190
189
  # Delete a disk snapshot
191
190
  # @param [String] snapshot_id snapshot id to delete
191
+ # @return [void]
192
192
  def delete_snapshot(snapshot_id)
193
193
  not_implemented(:delete_snapshot)
194
194
  end
195
195
 
196
- ##
197
196
  # Detaches a disk
198
- #
199
197
  # @param [String] vm vm id that was once returned by {#create_vm}
200
198
  # @param [String] disk disk id that was once returned by {#create_disk}
201
199
  # @return [void]
@@ -203,18 +201,14 @@ module Bosh
203
201
  not_implemented(:detach_disk)
204
202
  end
205
203
 
206
- ##
207
204
  # List the attached disks of the VM.
208
- #
209
205
  # @param [String] vm_id is the CPI-standard vm_id (eg, returned from current_vm_id)
210
- #
211
206
  # @return [array[String]] list of opaque disk_ids that can be used with the
212
207
  # other disk-related methods on the CPI
213
208
  def get_disks(vm_id)
214
209
  not_implemented(:get_disks)
215
210
  end
216
211
 
217
- ##
218
212
  # Validates the deployment
219
213
  # @api not_yet_used
220
214
  def validate_deployment(old_manifest, new_manifest)
data/lib/cloud/config.rb CHANGED
@@ -5,7 +5,7 @@ module Bosh::Clouds
5
5
 
6
6
  class << self
7
7
  extend Forwardable
8
- def_delegators :@delegate, :db, :logger, :uuid, :task_checkpoint
8
+ def_delegators :@delegate, :db, :logger, :uuid, :uuid=, :task_checkpoint
9
9
  end
10
10
 
11
11
  # @param [Bosh::Director::Config] config director config file
data/lib/cloud/errors.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  module Bosh::Clouds
2
-
3
2
  class CpiError < StandardError; end
4
3
  class NotImplemented < CpiError; end
5
4
  class NotSupported < CpiError; end
@@ -19,5 +18,4 @@ module Bosh::Clouds
19
18
  class DiskNotAttached < RetriableCloudError; end
20
19
  class DiskNotFound < RetriableCloudError; end
21
20
  class VMCreationFailed < RetriableCloudError; end
22
-
23
21
  end
data/lib/cloud/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Bosh
2
2
  module Clouds
3
- VERSION = '1.2200.0'
3
+ VERSION = '1.2291.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bosh_cpi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2200.0
4
+ version: 1.2291.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-14 00:00:00.000000000 Z
12
+ date: 2014-03-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bosh_common
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 1.2200.0
21
+ version: 1.2291.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,16 +26,17 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 1.2200.0
29
+ version: 1.2291.0
30
30
  description: ! 'BOSH CPI
31
31
 
32
- 87cbf9'
32
+ 51a1bb'
33
33
  email: support@cloudfoundry.com
34
34
  executables: []
35
35
  extensions: []
36
36
  extra_rdoc_files: []
37
37
  files:
38
38
  - lib/bosh/cpi.rb
39
+ - lib/bosh/cpi/cli.rb
39
40
  - lib/bosh/cpi/compatibility_helpers.rb
40
41
  - lib/bosh/cpi/compatibility_helpers/delete_vm.rb
41
42
  - lib/bosh/cpi/tasks.rb
@@ -67,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
68
  version: '0'
68
69
  segments:
69
70
  - 0
70
- hash: -4489019858572925328
71
+ hash: -2726584133311882745
71
72
  requirements: []
72
73
  rubyforge_project:
73
74
  rubygems_version: 1.8.23