bosh_vcloud_cpi 0.7.8 → 0.7.9

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: fcbdf7f3f5c6a9d0852c992f96b106ddd67503f0
4
- data.tar.gz: a48e39654ba4916e2c28cf221f1e949ce4224e55
3
+ metadata.gz: 710aa4ae586bb095e7d141d87f370f32aea9b5a3
4
+ data.tar.gz: 244fc9bb0602ed4cb4de55cfdbccef20b91b1c66
5
5
  SHA512:
6
- metadata.gz: ad0c6cd71dbe20b8e184e75660ff18d7cb727dee725b9c9a6f47f8f8f941a2b867cb2f3e5b03b8ad32c30af8282b501d37fdb7dbece810d0251416de5e9ef0fb
7
- data.tar.gz: 0ccad8d4448fb37560df3cfbf6128ffe4caad3e833f463c398ec7d10998b9d24e5e7c3290bf5d8255b88ba618a1d4055a761675729303b31131a61635a1cdf83
6
+ metadata.gz: 622c767b56144f930d34a7241cc3f942a52553ef246277b8a9cac0c71dcbb57db0744d63a3bde2a19a13f83be359f0e561c60113d993f4fc10d3ad2d64f9bf38
7
+ data.tar.gz: 081218358ed1a0ecb744bad2953e67d83515ee8895ae01d2c363d6b68a6e4ac6cf96c5f16efe624608ee4c9e5a2cacf0d7df1a2bbef4f5a99baa238a1db29aa1
@@ -1,5 +1,6 @@
1
1
  require 'securerandom'
2
2
  require 'logger'
3
+ require 'common/common'
3
4
 
4
5
  require_relative 'errors'
5
6
  require_relative 'vcd_client'
@@ -22,8 +23,7 @@ module VCloudCloud
22
23
  @entities = @vcd['entities']
23
24
  raise ArgumentError, 'Invalid entities in VCD settings' unless @entities && @entities.is_a?(Hash)
24
25
 
25
- @client_lock = Mutex.new # lock for establishing client connection
26
- @vapp_lock = Mutex.new # lock for recompose vApp and delete vm from vApp
26
+ @client = VCloudClient.new(@vcd, @logger)
27
27
  end
28
28
 
29
29
  def create_stemcell(image, _)
@@ -47,6 +47,8 @@ module VCloudCloud
47
47
  end
48
48
  end
49
49
 
50
+ def cpi_call_wait_time; 2; end
51
+
50
52
  def create_vm(agent_id, catalog_vapp_id, resource_pool, networks, disk_locality = nil, environment = nil)
51
53
  (steps "create_vm(#{agent_id}, #{catalog_vapp_id}, #{resource_pool}, ...)" do |s|
52
54
  # disk_locality should be an array of disk ids
@@ -61,6 +63,7 @@ module VCloudCloud
61
63
  storage_profiles = client.vdc.storage_profiles || []
62
64
  storage_profile = storage_profiles.find { |sp| sp['name'] == @entities['vapp_storage_profile'] }
63
65
 
66
+
64
67
  s.next Steps::Instantiate, catalog_vapp_id, vapp_name, description, disk_locality, storage_profile
65
68
  client.flush_cache # flush cached vdc which contains vapp list
66
69
  vapp = s.state[:vapp]
@@ -76,45 +79,59 @@ module VCloudCloud
76
79
  # if the target vApp exists, creates a temp vApp, and then recomposes its VM to the target vApp.
77
80
  if requested_name
78
81
  container_vapp = nil
79
- vm_href = nil
80
- existing_vm_hrefs = []
81
82
 
82
- # VM is added to the target vApp sequentially.
83
- @vapp_lock.synchronize do
83
+ errors = [RuntimeError]
84
+ Bosh::Common.retryable(sleep: cpi_call_wait_time, tries: 10, on: errors) do
84
85
  begin
85
- @logger.debug "Requesting container vApp: #{requested_name}"
86
- container_vapp = client.vapp_by_name requested_name
87
- rescue ObjectNotFoundError
88
- # ignored, keep container_vapp nil
89
- @logger.debug "Invalid container vApp: #{requested_name}"
90
- end
91
-
92
- if container_vapp
93
- existing_vm_hrefs = container_vapp.vms.map { |v| v.href }
94
- s.next Steps::Recompose, container_vapp.name, container_vapp, vm
95
- client.flush_cache
96
- vapp = client.reload vapp
97
- client.wait_entity vapp
98
86
  begin
99
- s.next Steps::Delete, vapp, true
100
- rescue => ex
101
- @logger.warn "Caught exception when trying to delete tmp vapp #{vapp.name}: #{ex.to_s}"
87
+ @logger.debug "Requesting container vApp: #{requested_name}"
88
+ container_vapp = client.vapp_by_name requested_name
89
+ rescue ObjectNotFoundError
90
+ # ignored, keep container_vapp nil
91
+ @logger.debug "Invalid container vApp: #{requested_name}"
102
92
  end
103
- else
104
- # just rename the vApp
105
- container_vapp = vapp
106
- s.next Steps::Recompose, requested_name, container_vapp
93
+
94
+ if container_vapp
95
+ @logger.debug "Enter recompose, container_vapp: #{container_vapp.name}"
96
+ begin
97
+ s.next Steps::Recompose, container_vapp.name, container_vapp, vm
98
+ rescue VCloudCloud::ObjectExistsError => e
99
+ @logger.debug "VM already exists, skip the error"
100
+ end
101
+ else
102
+ # just rename the vApp
103
+ container_vapp = vapp
104
+ s.next Steps::Recompose, requested_name, container_vapp
105
+ end
106
+ rescue Exception => e
107
+ @logger.warn "Caught an exception during create_vm Exception #{e}, Type #{e.class} Message #{e.message}"
108
+ @logger.warn "Exception trace #{e.backtrace.join('\n')}"
109
+ raise "re raising exception #{e.message} in create_vm"
107
110
  end
111
+ end
108
112
 
109
- # reload all the stuff
110
- client.flush_cache
111
- vapp = client.reload container_vapp
112
- client.wait_entity vapp
113
- vm_href = vapp.vms.map { |v| v.href } - existing_vm_hrefs
113
+ # delete tmp vapp only if the name is different from requested
114
+ client.flush_cache
115
+ vapp = client.reload vapp
116
+ client.wait_entity vapp, true
117
+ if vapp.name != requested_name
118
+ begin
119
+ s.next Steps::Delete, vapp, true
120
+ rescue Exception => ex
121
+ @logger.warn "Caught exception when trying to delete tmp vapp #{vapp.name}: #{ex.to_s}"
122
+ end
114
123
  end
115
124
 
116
- raise "New virtual machine not found in recomposed vApp" if vm_href.empty?
117
- s.state[:vm] = client.resolve_link vm_href[0]
125
+ # Wait for Delete/Recompose step to finish, retry if fails
126
+ # reload all the stuff
127
+ client.flush_cache
128
+ vapp = client.reload container_vapp
129
+ client.wait_entity vapp, true
130
+
131
+ vms = vapp.vms.select { |v| v.name == vm.name }
132
+
133
+ raise "New virtual machine not found in recomposed vApp" if vms.empty?
134
+ s.state[:vm] = client.resolve_link vms[0].href
118
135
  end
119
136
 
120
137
  # create env and generate env ISO image
@@ -123,17 +140,22 @@ module VCloudCloud
123
140
 
124
141
  # TODO refact this
125
142
  if requested_name
126
- @vapp_lock.synchronize do
127
- save_agent_env s
128
- s.next Steps::PowerOn, :vm
143
+ errors = [RuntimeError]
144
+ Bosh::Common.retryable(sleep: cpi_call_wait_time, tries: 20, on: errors) do
145
+ begin
146
+ save_agent_env s
147
+ s.next Steps::PowerOn, :vm
148
+ rescue Exception => e
149
+ @logger.warn "Caught an exception during create_vm Exception #{e}, Type #{e.class} Message #{e.message}"
150
+ @logger.warn "Exception trace #{e.backtrace.join('\n')}"
151
+ raise "re raising exception #{e.message} in create_vm"
152
+ end
129
153
  end
130
154
  else
131
155
  save_agent_env s
132
156
  s.next Steps::PowerOn, :vm
133
157
  end
134
158
 
135
- # Update state to point to the correct vapp instead of the newly created temporary vapp for transition
136
- # We do this as the final step to avoid problems such as rollback of Steps::Instantiate, which deletes state[:vapp]
137
159
  s.state[:vapp] = vapp
138
160
  s.state
139
161
  end)[:vm].urn
@@ -143,21 +165,28 @@ module VCloudCloud
143
165
  steps "reboot_vm(#{vm_id})" do |s|
144
166
  vm = s.state[:vm] = client.resolve_entity(vm_id)
145
167
 
146
- @vapp_lock.synchronize do
147
- if vm['status'] == VCloudSdk::Xml::RESOURCE_ENTITY_STATUS[:SUSPENDED].to_s
148
- s.next Steps::DiscardSuspendedState, :vm
149
- s.next Steps::PowerOn, :vm
150
- elsif vm['status'] == VCloudSdk::Xml::RESOURCE_ENTITY_STATUS[:POWERED_OFF].to_s
151
- s.next Steps::PowerOn, :vm
152
- else
153
- begin
154
- s.next Steps::Reboot, :vm
155
- rescue => ex
156
- @logger.warn "Caught exception when trying to Reboot vm #{vm_id}: #{ex.to_s}"
157
- @logger.debug 'Force a hard-reboot when failed to perform a soft-reboot'
158
- s.next Steps::PowerOff, :vm, true
168
+ errors = [RuntimeError]
169
+ Bosh::Common.retryable(sleep: cpi_call_wait_time, tries: 20, on: errors) do
170
+ begin
171
+ if vm['status'] == VCloudSdk::Xml::RESOURCE_ENTITY_STATUS[:SUSPENDED].to_s
172
+ s.next Steps::DiscardSuspendedState, :vm
173
+ s.next Steps::PowerOn, :vm
174
+ elsif vm['status'] == VCloudSdk::Xml::RESOURCE_ENTITY_STATUS[:POWERED_OFF].to_s
159
175
  s.next Steps::PowerOn, :vm
176
+ else
177
+ begin
178
+ s.next Steps::Reboot, :vm
179
+ rescue => ex
180
+ @logger.warn "Caught exception when trying to Reboot vm #{vm_id}: #{ex.to_s}"
181
+ @logger.debug 'Force a hard-reboot when failed to perform a soft-reboot'
182
+ s.next Steps::PowerOff, :vm, true
183
+ s.next Steps::PowerOn, :vm
184
+ end
160
185
  end
186
+ rescue Exception => e
187
+ @logger.warn "Caught an exception during reboot_vm Exception #{e}, Type #{e.class} Message #{e.message}"
188
+ @logger.warn "Exception trace #{e.backtrace.join('\n')}"
189
+ raise "re raising exception #{e.message} in reboot_vm"
161
190
  end
162
191
  end
163
192
  end
@@ -176,7 +205,9 @@ module VCloudCloud
176
205
  steps "delete_vm(#{vm_id})" do |s|
177
206
  vm = s.state[:vm] = client.resolve_entity vm_id
178
207
 
179
- @vapp_lock.synchronize do
208
+ errors = [RuntimeError]
209
+ Bosh::Common.retryable(sleep: cpi_call_wait_time, tries: 20, on: errors) do
210
+ begin
180
211
  # poweroff vm before we are able to delete it
181
212
  s.next Steps::PowerOff, :vm, true
182
213
 
@@ -191,6 +222,11 @@ module VCloudCloud
191
222
  s.next Steps::Undeploy, :vm
192
223
  s.next Steps::Delete, s.state[:vm], true
193
224
  end
225
+ rescue Exception => e
226
+ @logger.warn "Caught an exception during delete_vm Exception #{e}, Type #{e.class} Message #{e.message}"
227
+ @logger.warn "Exception trace #{e.backtrace.join('\n')}"
228
+ raise "re raising exception #{e.message} in delete_vm"
229
+ end
194
230
  end
195
231
 
196
232
  s.next Steps::DeleteCatalogMedia, vm.name
@@ -220,17 +256,24 @@ module VCloudCloud
220
256
 
221
257
  s.state[:disk] = client.resolve_entity disk_id
222
258
 
223
- @vapp_lock.synchronize do
224
- s.next Steps::AttachDetachDisk, :attach
259
+ errors = [RuntimeError]
260
+ Bosh::Common.retryable(sleep: cpi_call_wait_time, tries: 20, on: errors) do
261
+ begin
262
+ s.next Steps::AttachDetachDisk, :attach
225
263
 
226
- # update environment
227
- s.state[:env_metadata_key] = @entities['vm_metadata_key']
228
- s.next Steps::LoadAgentEnv
264
+ # update environment
265
+ s.state[:env_metadata_key] = @entities['vm_metadata_key']
266
+ s.next Steps::LoadAgentEnv
229
267
 
230
- vm = s.state[:vm] = client.reload vm
231
- Steps::CreateOrUpdateAgentEnv.update_persistent_disk s.state[:env], vm, disk_id , previous_disks_list
268
+ vm = s.state[:vm] = client.reload vm
269
+ Steps::CreateOrUpdateAgentEnv.update_persistent_disk s.state[:env], vm, disk_id , previous_disks_list
232
270
 
233
- save_agent_env s
271
+ save_agent_env s
272
+ rescue Exception => e
273
+ @logger.warn "Caught an exception during attach_disk Exception #{e}, Type #{e.class} Message #{e.message}"
274
+ @logger.warn "Exception trace #{e.backtrace.join('\n')}"
275
+ raise "re raising exception #{e.message} in attach_disk"
276
+ end
234
277
  end
235
278
  end
236
279
  end
@@ -242,21 +285,28 @@ module VCloudCloud
242
285
  # if disk is not attached, just ignore
243
286
  next unless vm.find_attached_disk s.state[:disk]
244
287
 
245
- @vapp_lock.synchronize do
246
- if vm['status'] == VCloudSdk::Xml::RESOURCE_ENTITY_STATUS[:SUSPENDED].to_s
247
- s.next Steps::DiscardSuspendedState, :vm
248
- end
249
- s.next Steps::AttachDetachDisk, :detach
250
-
251
- # update environment
252
- s.state[:env_metadata_key] = @entities['vm_metadata_key']
253
- s.next Steps::LoadAgentEnv
254
- env = s.state[:env]
255
- if env['disks'] && env['disks']['persistent'].is_a?(Hash)
256
- env['disks']['persistent'].delete disk_id
257
- end
288
+ errors = [RuntimeError]
289
+ Bosh::Common.retryable(sleep: cpi_call_wait_time, tries: 20, on: errors) do
290
+ begin
291
+ if vm['status'] == VCloudSdk::Xml::RESOURCE_ENTITY_STATUS[:SUSPENDED].to_s
292
+ s.next Steps::DiscardSuspendedState, :vm
293
+ end
294
+ s.next Steps::AttachDetachDisk, :detach
295
+
296
+ # update environment
297
+ s.state[:env_metadata_key] = @entities['vm_metadata_key']
298
+ s.next Steps::LoadAgentEnv
299
+ env = s.state[:env]
300
+ if env['disks'] && env['disks']['persistent'].is_a?(Hash)
301
+ env['disks']['persistent'].delete disk_id
302
+ end
258
303
 
259
- save_agent_env s
304
+ save_agent_env s
305
+ rescue Exception => e
306
+ @logger.warn "Caught an exception during detach_disk Exception #{e}, Type #{e.class} Message #{e.message}"
307
+ @logger.warn "Exception trace #{e.backtrace.join('\n')}"
308
+ raise "re raising exception #{e.message} in detach_disk"
309
+ end
260
310
  end
261
311
  end
262
312
  end
@@ -276,9 +326,6 @@ module VCloudCloud
276
326
  end
277
327
 
278
328
  def client
279
- @client_lock.synchronize do
280
- @client = VCloudClient.new(@vcd, @logger) if @client.nil?
281
- end
282
329
  @client
283
330
  end
284
331
 
@@ -95,8 +95,13 @@ module VCloudCloud
95
95
  end
96
96
 
97
97
  def vapp_by_name(name)
98
- node = vdc.get_vapp name
98
+ # @logger.debug "VAPP_BY_NAME - org.vdc_link: #{org.vdc_link}"
99
+ vdc_link = org.vdc_link vdc_name
100
+ raise ObjectNotFoundError, "Invalid virtual datacenter name: #{vdc_name}" unless vdc_link
101
+ vdc_obj = resolve_link vdc_link
102
+ node = vdc_obj.get_vapp name
99
103
  raise ObjectNotFoundError, "vApp #{name} does not exist" unless node
104
+ @logger.debug "VAPP_BY_NAME - get a vapp name"
100
105
  resolve_link node.href
101
106
  end
102
107
 
@@ -119,7 +124,7 @@ module VCloudCloud
119
124
  session
120
125
 
121
126
  response = send_request method, path, options
122
- (options[:no_wrap] || response.code == 204) ? nil : wrap_response(response)
127
+ (options[:no_wrap] || response.code == 204) ? response : wrap_response(response)
123
128
  end
124
129
 
125
130
  def upload_stream(url, size, stream, options = {})
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bosh_vcloud_cpi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.8
4
+ version: 0.7.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - VMware
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-08 00:00:00.000000000 Z
11
+ date: 2015-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bosh_common
@@ -124,7 +124,7 @@ dependencies:
124
124
  version: '0'
125
125
  description: |-
126
126
  BOSH vCloud CPI
127
- a3d5f4
127
+ 99eceb
128
128
  email: support@cloudfoundry.com
129
129
  executables: []
130
130
  extensions: []