vagrant-vsphere 0.18.0 → 0.19.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ca7707beee33ab9618da472c660a46a05e2ca8f4
4
- data.tar.gz: bd28c6055786c007862865c0768f053d8309498c
3
+ metadata.gz: c0b7b0145083bd30757aeba7829a8b75620300dd
4
+ data.tar.gz: d66b51f6e4a73bd1cf9d2373616c07cead5b6aaf
5
5
  SHA512:
6
- metadata.gz: 7a83daf3b86d22e1346e463b82d5f54536663cca554d7b4dcd554fdb5cd85bfd114bb02e0a15b126b4f9c6cb5a5e0eba7304484bd050c2cf62ddc7900043e172
7
- data.tar.gz: e5457be35238ac4eed9e1c95329ec9f699711d90c80432265dbce8a37cf288adaeb858c8edcbb8d21e1340fb2607f2b66f8fc804c7af0b51e323812f46732096
6
+ metadata.gz: 98453cec388971d2f0d5b8f1b5e3b50f7aa86203aa9c3ade98f4c7f76c863ccf25ab4af07fff3d0e7c8df59da9f9295a1e09311226432465fbde48d5774908eb
7
+ data.tar.gz: 029f6cb25ec23bd2219b2cc060f021c93a9343cc037b993ee228c7ae665a04587dc5412ae04cad26eb54151b42faa8904390f81318959d175f8b9920cb7cce41
data/.bumpversion.cfg CHANGED
@@ -1,5 +1,5 @@
1
1
  [bumpversion]
2
- current_version = 0.18.0
2
+ current_version = 0.19.0
3
3
  tag = true
4
4
  commit = true
5
5
 
data/README.md CHANGED
@@ -14,9 +14,9 @@ This provider is built on top of the [RbVmomi](https://github.com/vmware/rbvmomi
14
14
  * libxml2, libxml2-dev, libxslt, libxslt-dev
15
15
 
16
16
  ## Current Version
17
- **version: 0.18.0**
17
+ **version: 0.19.0**
18
18
 
19
- vagrant-vsphere (**version: 0.18.0**) is available from [RubyGems.org](https://rubygems.org/gems/vagrant-vsphere)
19
+ vagrant-vsphere (**version: 0.19.0**) is available from [RubyGems.org](https://rubygems.org/gems/vagrant-vsphere)
20
20
 
21
21
  ## Installation
22
22
 
@@ -297,6 +297,9 @@ vagrant destroy
297
297
  [#104 clintoncwolfe:shutdown-guest-on-halt](https://github.com/nsidc/vagrant-vsphere/pull/104).
298
298
  * Add configuration option `mac` to specify a MAC address for the VM
299
299
  [#108 dataplayer:master](https://github.com/nsidc/vagrant-vsphere/pull/108).
300
+ * 0.19.0
301
+ * Add support for ClusterComputeResource and DatastoreCluster
302
+ [#101 GregDomjan:StorageSDRS](https://github.com/nsidc/vagrant-vsphere/pull/101).
300
303
 
301
304
  ## Versioning
302
305
 
@@ -26,7 +26,11 @@ module VagrantPlugins
26
26
  raise Errors::VSphereError, :'invalid_base_path' if vm_base_folder.nil?
27
27
 
28
28
  begin
29
- location = get_location connection, machine, config, template
29
+ # Storage DRS does not support vSphere linked clones. http://www.vmware.com/files/pdf/techpaper/vsphere-storage-drs-interoperability.pdf
30
+ ds = get_datastore dc, machine
31
+ raise Errors::VSphereError, :'invalid_configuration_linked_clone_with_sdrs' if config.linked_clone and datastore.is_a? RbVmomi::VIM::StoragePod
32
+
33
+ location = get_location ds, dc, machine, template
30
34
  spec = RbVmomi::VIM.VirtualMachineCloneSpec :location => location, :powerOn => true, :template => false
31
35
  spec[:config] = RbVmomi::VIM.VirtualMachineConfigSpec
32
36
  customization_info = get_customization_spec_info_by_name connection, machine
@@ -37,11 +41,40 @@ module VagrantPlugins
37
41
  add_custom_memory(spec, config.memory_mb) unless config.memory_mb.nil?
38
42
  add_custom_cpu(spec, config.cpu_count) unless config.cpu_count.nil?
39
43
 
40
- env[:ui].info I18n.t('vsphere.creating_cloned_vm')
41
- env[:ui].info " -- #{config.clone_from_vm ? "Source" : "Template"} VM: #{template.pretty_path}"
42
- env[:ui].info " -- Target VM: #{vm_base_folder.pretty_path}/#{name}"
44
+ if !config.clone_from_vm and ds.is_a? RbVmomi::VIM::StoragePod
45
+
46
+ storageMgr = connection.serviceContent.storageResourceManager
47
+ podSpec = RbVmomi::VIM.StorageDrsPodSelectionSpec(:storagePod => ds)
48
+ # TODO: May want to add option on type?
49
+ storageSpec = RbVmomi::VIM.StoragePlacementSpec(:type => 'clone', :cloneName => name, :folder => vm_base_folder, :podSelectionSpec => podSpec, :vm => template, :cloneSpec => spec)
50
+
51
+ env[:ui].info I18n.t('vsphere.requesting_sdrs_recommendation')
52
+ env[:ui].info " -- DatastoreCluster: #{ds.name}"
53
+ env[:ui].info " -- Template VM: #{template.pretty_path}"
54
+ env[:ui].info " -- Target VM: #{vm_base_folder.pretty_path}/#{name}"
55
+
56
+ result = storageMgr.RecommendDatastores(:storageSpec => storageSpec)
57
+
58
+ recommendation = result.recommendations[0]
59
+ key = recommendation.key ||= ''
60
+ if key == ''
61
+ raise Errors::VSphereError, :missing_datastore_recommendation
62
+ end
63
+
64
+ env[:ui].info I18n.t('vsphere.creating_cloned_vm_sdrs')
65
+ env[:ui].info " -- Storage DRS recommendation: #{recommendation.target.name} #{recommendation.reasonText}"
43
66
 
44
- new_vm = template.CloneVM_Task(:folder => vm_base_folder, :name => name, :spec => spec).wait_for_completion
67
+ applySRresult = storageMgr.ApplyStorageDrsRecommendation_Task(:key => [key]).wait_for_completion
68
+ new_vm = applySRresult.vm
69
+
70
+ else
71
+
72
+ env[:ui].info I18n.t('vsphere.creating_cloned_vm')
73
+ env[:ui].info " -- #{config.clone_from_vm ? "Source" : "Template"} VM: #{template.pretty_path}"
74
+ env[:ui].info " -- Target VM: #{vm_base_folder.pretty_path}/#{name}"
75
+
76
+ new_vm = template.CloneVM_Task(:folder => vm_base_folder, :name => name, :spec => spec).wait_for_completion
77
+ end
45
78
  rescue Errors::VSphereError => e
46
79
  raise
47
80
  rescue Exception => e
@@ -80,8 +113,8 @@ module VagrantPlugins
80
113
  customization_spec
81
114
  end
82
115
 
83
- def get_location(connection, machine, config, template)
84
- if config.linked_clone
116
+ def get_location(datastore, dc, machine, template)
117
+ if machine.provider_config.linked_clone
85
118
  # The API for linked clones is quite strange. We can't create a linked
86
119
  # straight from any VM. The disks of the VM for which we can create a
87
120
  # linked clone need to be read-only and thus VC demands that the VM we
@@ -113,13 +146,14 @@ module VagrantPlugins
113
146
  end
114
147
 
115
148
  location = RbVmomi::VIM.VirtualMachineRelocateSpec(:diskMoveType => :moveChildMostDiskBacking)
149
+ elsif datastore.is_a? RbVmomi::VIM::StoragePod
150
+ location = RbVmomi::VIM.VirtualMachineRelocateSpec
116
151
  else
117
152
  location = RbVmomi::VIM.VirtualMachineRelocateSpec
118
153
 
119
- datastore = get_datastore connection, machine
120
154
  location[:datastore] = datastore unless datastore.nil?
121
155
  end
122
- location[:pool] = get_resource_pool(connection, machine) unless config.clone_from_vm
156
+ location[:pool] = get_resource_pool(dc, machine) unless machine.provider_config.clone_from_vm
123
157
  location
124
158
  end
125
159
 
@@ -12,15 +12,56 @@ module VagrantPlugins
12
12
  get_datacenter(connection, machine).vmFolder.findByUuid machine.id
13
13
  end
14
14
 
15
- def get_resource_pool(connection, machine)
16
- cr = get_datacenter(connection, machine).find_compute_resource(machine.provider_config.compute_resource_name) or fail Errors::VSphereError, :missing_compute_resource
17
- rp = cr.resourcePool
15
+ def get_resource_pool(datacenter, machine)
16
+ computeResource = get_compute_resource(datacenter, machine)
17
+ rp = computeResource.resourcePool
18
18
  if !(machine.provider_config.resource_pool_name.nil?)
19
- rp = cr.resourcePool.find(machine.provider_config.resource_pool_name) or fail Errors::VSphereError, :missing_resource_pool
19
+ rp = computeResource.resourcePool.find(machine.provider_config.resource_pool_name) or fail Errors::VSphereError, :missing_resource_pool
20
20
  end
21
21
  rp
22
22
  end
23
23
 
24
+ def get_compute_resource(datacenter, machine)
25
+ cr = find_clustercompute_or_compute_resource(datacenter, machine.provider_config.compute_resource_name) or fail Errors::VSphereError, :missing_compute_resource
26
+ cr
27
+ end
28
+
29
+ def find_clustercompute_or_compute_resource(datacenter, path)
30
+ if path.is_a? String
31
+ es = path.split('/').reject(&:empty?)
32
+ elsif path.is_a? Enumerable
33
+ es = path
34
+ else
35
+ fail "unexpected path class #{path.class}"
36
+ end
37
+ return datacenter.hostFolder if es.empty?
38
+ final = es.pop
39
+
40
+ p = es.inject(datacenter.hostFolder) do |f,e|
41
+ f.find(e, RbVmomi::VIM::Folder) || return
42
+ end
43
+
44
+ begin
45
+ if x = p.find(final, RbVmomi::VIM::ComputeResource)
46
+ x
47
+ elsif x = p.find(final, RbVmomi::VIM::ClusterComputeResource)
48
+ x
49
+ else
50
+ nil
51
+ end
52
+ rescue Exception => e
53
+ # When looking for the ClusterComputeResource there seems to be some parser error in RbVmomi Folder.find, try this instead
54
+ x = p.childEntity.find { |x| x.name == final }
55
+ if x.is_a? RbVmomi::VIM::ClusterComputeResource or x.is_a? RbVmomi::VIM::ComputeResource
56
+ x
57
+ else
58
+ puts "ex unknown type " + x.to_json
59
+ nil
60
+ end
61
+ end
62
+
63
+ end
64
+
24
65
  def get_customization_spec_info_by_name(connection, machine)
25
66
  name = machine.provider_config.customization_spec_name
26
67
  return if name.nil? || name.empty?
@@ -29,11 +70,12 @@ module VagrantPlugins
29
70
  spec = manager.GetCustomizationSpec(:name => name) or fail Errors::VSphereError, :missing_configuration_spec if spec.nil?
30
71
  end
31
72
 
32
- def get_datastore(connection, machine)
73
+ def get_datastore(datacenter, machine)
33
74
  name = machine.provider_config.data_store_name
34
75
  return if name.nil? || name.empty?
35
76
 
36
- get_datacenter(connection, machine).find_datastore name or fail Errors::VSphereError, :missing_datastore
77
+ # find_datastore uses folder datastore that only lists Datastore and not StoragePod, if not found also try datastoreFolder which contains StoragePod(s)
78
+ datacenter.find_datastore name or datacenter.datastoreFolder.traverse name or fail Errors::VSphereError, :missing_datastore
37
79
  end
38
80
 
39
81
  def get_network_by_name(dc, name)
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module VSphere
3
- VERSION = '0.18.0'
3
+ VERSION = '0.19.0'
4
4
  end
5
5
  end
data/locales/en.yml CHANGED
@@ -2,6 +2,10 @@ en:
2
2
  vsphere:
3
3
  creating_cloned_vm: |-
4
4
  Calling vSphere CloneVM with the following settings:
5
+ creating_cloned_vm_sdrs: |-
6
+ Calling vSphere ApplyStorageDrsRecommendation with the following settings:
7
+ requesting_sdrs_recommendation: |-
8
+ Calling vSphere RecommendDatastores with StoragePlacementSpec of the following settings:
5
9
  vm_clone_success: |-
6
10
  New virtual machine successfully cloned and started
7
11
  destroy_vm: |-
@@ -44,6 +48,9 @@ en:
44
48
  Configured vlan not found
45
49
  missing_network_card: |-
46
50
  Cannot find network card to customize
51
+ invalid_configuration_linked_clone_with_sdrs: |-
52
+ Cannot use Linked Clone with Storage DRS
53
+
47
54
  config:
48
55
  host: |-
49
56
  Configuration must specify a vSphere host
data/spec/spec_helper.rb CHANGED
@@ -102,10 +102,16 @@ RSpec.configure do |config|
102
102
  @child_resource_pool = double('testresourcepool')
103
103
  @root_resource_pool = double('pools', :find => @child_resource_pool)
104
104
 
105
+ @compute_resource = RbVmomi::VIM::ComputeResource.new(nil, nil)
106
+ @compute_resource.stub(:resourcePool).and_return(@root_resource_pool)
107
+
108
+ @host_folder = double('hostFolder', :childEntity => double('childEntity', :find => @compute_resource))
109
+
105
110
  @data_center = double('data_center',
106
111
  :vmFolder => vm_folder,
107
112
  :pretty_path => "data_center/#{vm_folder}",
108
- :find_compute_resource => double('compute resource', :resourcePool => @root_resource_pool))
113
+ :find_compute_resource => @compute_resource,
114
+ :hostFolder => @host_folder)
109
115
 
110
116
  @device = RbVmomi::VIM::VirtualEthernetCard.new
111
117
  @device.stub(:backing).and_return(RbVmomi::VIM::VirtualEthernetCardNetworkBackingInfo.new)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-vsphere
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.0
4
+ version: 0.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Grauch