bosh_vsphere_cpi 1.2640.0 → 1.2641.0

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: 5b3ff836bd97ee23bf158fef2e4aafd5bc6023f2
4
- data.tar.gz: d5bb614b569e97721c66231ccefcfc3fed695282
3
+ metadata.gz: 3b2082bb5cb9b231442ac9bc874347505aa72a68
4
+ data.tar.gz: eb45587078b8b16f82bb717c35411b49614711e2
5
5
  SHA512:
6
- metadata.gz: 2e0abfdbe4c484b47e7782224cee35421b628149faf6455530ee638747c035b14ecb8f13f7605ba551fc829de357988ea8a44983c4f79c99c2dda90154dde7db
7
- data.tar.gz: 3855d4007e7dd566a0be2cde3454ddda74adde71e1005afed21f6322cb3c72a2e4f66a44020b248450557eaf710c09f41f4187922774cc0ae81560f33ebfc0cd
6
+ metadata.gz: c0e6a06a50283dad34b8b83fc03a647b3b16f3f2455eb08730f6fa19b8aa0b82089e231696600bad02cb8ef243a6a45c8617ef8ea5f599b9e702dd811371526e
7
+ data.tar.gz: 6b14f6706b27b70e4a97b9eb8c92430b2e5ef34a2797654b5e8003614e9799523db58ed847ccb334ec3cce6ab5173054a2dad4980ffd739c82bf50928c0fbfed
@@ -8,21 +8,35 @@ module VSphereCloud
8
8
  @file_provider = file_provider
9
9
  end
10
10
 
11
- def get_current_env(location)
12
- contents = @file_provider.fetch_file(location[:datacenter], location[:datastore], "#{location[:vm]}/env.json")
13
- contents ? JSON.load(contents) : nil
11
+ def get_current_env(vm, datacenter_name)
12
+ cdrom = @client.get_cdrom_device(vm)
13
+ env_iso_folder = File.dirname(cdrom.backing.file_name)
14
+ datastore_name = cdrom.backing.datastore.name
15
+ env_path = env_iso_folder.match(/\[#{datastore_name}\] (.*)/)[1]
16
+
17
+ contents = @file_provider.fetch_file(datacenter_name, datastore_name, "#{env_path}/env.json")
18
+ raise Bosh::Clouds::CloudError.new('Unable to load env.json') unless contents
19
+
20
+ JSON.load(contents)
14
21
  end
15
22
 
16
23
  def set_env(vm, location, env)
17
24
  env_json = JSON.dump(env)
18
25
 
19
- connect_cdrom(vm, false)
26
+ disconnect_cdrom(vm)
27
+ clean_up_old_env(vm)
20
28
  @file_provider.upload_file(location[:datacenter], location[:datastore], "#{location[:vm]}/env.json", env_json)
21
29
  @file_provider.upload_file(location[:datacenter], location[:datastore], "#{location[:vm]}/env.iso", generate_env_iso(env_json))
22
- connect_cdrom(vm, true)
30
+
31
+ datastore = @client.get_managed_object(Vim::Datastore, name: location[:datastore])
32
+ file_name = "[#{location[:datastore]}] #{location[:vm]}/env.iso"
33
+
34
+ update_cdrom_env(vm, datastore, file_name)
23
35
  end
24
36
 
25
- def configure_env_cdrom(datastore, devices, file_name)
37
+ private
38
+
39
+ def update_cdrom_env(vm, datastore, file_name)
26
40
  backing_info = Vim::Vm::Device::VirtualCdrom::IsoBackingInfo.new
27
41
  backing_info.datastore = datastore
28
42
  backing_info.file_name = file_name
@@ -32,21 +46,20 @@ module VSphereCloud
32
46
  connect_info.start_connected = true
33
47
  connect_info.connected = true
34
48
 
49
+ devices = vm.config.hardware.device
35
50
  cdrom = devices.find { |device| device.kind_of?(Vim::Vm::Device::VirtualCdrom) }
36
51
  cdrom.connectable = connect_info
37
52
  cdrom.backing = backing_info
38
53
 
39
- create_edit_device_spec(cdrom)
54
+ config = Vim::Vm::ConfigSpec.new
55
+ config.device_change = [create_edit_device_spec(cdrom)]
56
+ @client.reconfig_vm(vm, config)
40
57
  end
41
58
 
42
- private
43
-
44
- def connect_cdrom(vm, connected = true)
45
- devices = @client.get_property(vm, Vim::VirtualMachine, 'config.hardware.device', ensure_all: true)
46
- cdrom = devices.find { |device| device.kind_of?(Vim::Vm::Device::VirtualCdrom) }
47
-
48
- if cdrom.connectable.connected != connected
49
- cdrom.connectable.connected = connected
59
+ def disconnect_cdrom(vm)
60
+ cdrom = @client.get_cdrom_device(vm)
61
+ if cdrom.connectable.connected
62
+ cdrom.connectable.connected = false
50
63
  config = Vim::Vm::ConfigSpec.new
51
64
  config.device_change = [create_edit_device_spec(cdrom)]
52
65
  @client.reconfig_vm(vm, config)
@@ -64,6 +77,17 @@ module VSphereCloud
64
77
  end
65
78
  end
66
79
 
80
+ def clean_up_old_env(vm)
81
+ cdrom = @client.get_cdrom_device(vm)
82
+ return unless cdrom && cdrom.backing.respond_to?(:file_name)
83
+
84
+ env_iso_folder = File.dirname(cdrom.backing.file_name)
85
+ datacenter = @client.find_parent(vm, Vim::Datacenter)
86
+
87
+ @client.delete_path(datacenter, File.join(env_iso_folder, 'env.json'))
88
+ @client.delete_path(datacenter, File.join(env_iso_folder, 'env.iso'))
89
+ end
90
+
67
91
  def which(programs)
68
92
  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
69
93
  programs.each do |bin|
@@ -159,7 +159,7 @@ module VSphereCloud
159
159
  task = datacenter.power_on_vm([vm], nil)
160
160
  result = wait_for_task(task)
161
161
 
162
- raise "Recommendations were detected, you may be running in Manual DRS mode. Aborting." if result.recommendations.any?
162
+ raise 'Recommendations were detected, you may be running in Manual DRS mode. Aborting.' if result.recommendations.any?
163
163
 
164
164
  if result.attempted.empty?
165
165
  raise "Could not power on VM: #{result.not_attempted.map(&:msg).join(', ')}"
@@ -174,9 +174,18 @@ module VSphereCloud
174
174
  wait_for_task(task)
175
175
  end
176
176
 
177
+ def get_cdrom_device(vm)
178
+ devices = get_property(vm, Vim::VirtualMachine, 'config.hardware.device', ensure_all: true)
179
+ devices.find { |device| device.kind_of?(Vim::Vm::Device::VirtualCdrom) }
180
+ end
181
+
177
182
  def delete_path(datacenter, path)
178
183
  task = @service_content.file_manager.delete_file(path, datacenter)
179
184
  wait_for_task(task)
185
+ rescue => e
186
+ unless e.message =~ /File .* was not found/
187
+ raise e
188
+ end
180
189
  end
181
190
 
182
191
  def delete_disk(datacenter, path)
@@ -238,10 +238,11 @@ module VSphereCloud
238
238
 
239
239
  # Delete env.iso and VM specific files managed by the director
240
240
  retry_block do
241
- datastore = get_primary_datastore(devices)
242
- datastore_name = client.get_property(datastore, Vim::Datastore, 'name')
243
- vm_name = properties['name']
244
- client.delete_path(datacenter, "[#{datastore_name}] #{vm_name}")
241
+ cdrom_device = devices.find { |device| device.kind_of?(Vim::Vm::Device::VirtualCdrom) }
242
+ if cdrom_device
243
+ env_iso_folder = File.dirname(cdrom_device.backing.file_name)
244
+ client.delete_path(datacenter, env_iso_folder)
245
+ end
245
246
  end
246
247
  end
247
248
  end
@@ -355,14 +356,14 @@ module VSphereCloud
355
356
  @logger.debug('Reconfiguring the networks')
356
357
  @client.reconfig_vm(vm, config)
357
358
 
358
- location = get_vm_location(vm, datacenter: datacenter_name)
359
- env = @agent_env.get_current_env(location)
359
+ env = @agent_env.get_current_env(vm, datacenter_name)
360
360
  @logger.debug("Reading current agent env: #{env.pretty_inspect}")
361
361
 
362
362
  devices = client.get_property(vm, Vim::VirtualMachine, 'config.hardware.device', ensure_all: true)
363
363
  env['networks'] = generate_network_env(devices, networks, dvs_index)
364
364
 
365
365
  @logger.debug("Updating agent env to: #{env.pretty_inspect}")
366
+ location = get_vm_location(vm, datacenter: datacenter_name)
366
367
  @agent_env.set_env(vm, location, env)
367
368
 
368
369
  @logger.debug('Powering the VM back on')
@@ -486,11 +487,12 @@ module VSphereCloud
486
487
  config.device_change << attached_disk_config
487
488
  fix_device_unit_numbers(devices, config.device_change)
488
489
 
489
- location = get_vm_location(vm, datacenter: datacenter_name)
490
- env = @agent_env.get_current_env(location)
490
+ env = @agent_env.get_current_env(vm, datacenter_name)
491
491
  @logger.info("Reading current agent env: #{env.pretty_inspect}")
492
492
  env['disks']['persistent'][disk.uuid] = attached_disk_config.device.unit_number.to_s
493
493
  @logger.info("Updating agent env to: #{env.pretty_inspect}")
494
+
495
+ location = get_vm_location(vm, datacenter: datacenter_name)
494
496
  @agent_env.set_env(vm, location, env)
495
497
  @logger.info('Attaching disk')
496
498
  client.reconfig_vm(vm, config)
@@ -520,10 +522,11 @@ module VSphereCloud
520
522
  config.device_change << create_delete_device_spec(virtual_disk)
521
523
 
522
524
  location = get_vm_location(vm)
523
- env = @agent_env.get_current_env(location)
525
+ env = @agent_env.get_current_env(vm, location[:datacenter])
524
526
  @logger.info("Reading current agent env: #{env.pretty_inspect}")
525
527
  env['disks']['persistent'].delete(disk.uuid)
526
528
  @logger.info("Updating agent env to: #{env.pretty_inspect}")
529
+
527
530
  @agent_env.set_env(vm, location, env)
528
531
  @logger.info('Detaching disk')
529
532
  client.reconfig_vm(vm, config)
@@ -1,7 +1,7 @@
1
1
  module Bosh
2
2
  module Clouds
3
3
  class VSphere
4
- VERSION = '1.2640.0'
4
+ VERSION = '1.2641.0'
5
5
  end
6
6
  end
7
7
  end
@@ -77,27 +77,22 @@ module VSphereCloud
77
77
  vm = @client.wait_for_task(task)
78
78
 
79
79
  begin
80
- @file_provider.upload_file(cluster.datacenter.name, datastore.name, "#{name}/env.iso", '')
81
-
82
80
  vm_properties = @client.get_properties(vm, VimSdk::Vim::VirtualMachine, ['config.hardware.device'], ensure_all: true)
83
81
  devices = vm_properties['config.hardware.device']
84
82
 
85
- # Configure the ENV CDROM
86
- config = VimSdk::Vim::Vm::ConfigSpec.new
87
- config.device_change = []
88
- file_name = "[#{datastore.name}] #{name}/env.iso"
89
- cdrom_change = @agent_env.configure_env_cdrom(datastore.mob, devices, file_name)
90
- config.device_change << cdrom_change
91
- @client.reconfig_vm(vm, config)
92
-
93
83
  network_env = @cpi.generate_network_env(devices, networks, dvs_index)
94
84
  disk_env = @cpi.generate_disk_env(system_disk, ephemeral_disk_config.device)
95
85
  env = @cpi.generate_agent_env(name, vm, agent_id, network_env, disk_env)
96
86
  env['env'] = environment
97
87
  @logger.info("Setting VM env: #{env.pretty_inspect}")
98
88
 
99
- location =
100
- @cpi.get_vm_location(vm, datacenter: cluster.datacenter.name, datastore: datastore.name, vm: name)
89
+ location = @cpi.get_vm_location(
90
+ vm,
91
+ datacenter: cluster.datacenter.name,
92
+ datastore: datastore.name,
93
+ vm: name
94
+ )
95
+
101
96
  @agent_env.set_env(vm, location, env)
102
97
 
103
98
  @logger.info("Powering on VM: #{vm} (#{name})")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bosh_vsphere_cpi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2640.0
4
+ version: 1.2641.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - VMware
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-08 00:00:00.000000000 Z
11
+ date: 2014-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bosh_common
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.2640.0
19
+ version: 1.2641.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.2640.0
26
+ version: 1.2641.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bosh_cpi
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.2640.0
33
+ version: 1.2641.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.2640.0
40
+ version: 1.2641.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: membrane
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -138,7 +138,7 @@ dependencies:
138
138
  version: 2.2.4
139
139
  description: |-
140
140
  BOSH VSphere CPI
141
- 986896
141
+ 23fe6f
142
142
  email: support@cloudfoundry.com
143
143
  executables:
144
144
  - vsphere_cpi