fog-vsphere 3.1.0 → 3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/fog/vsphere/requests/compute/create_vm.rb +28 -8
- data/lib/fog/vsphere/requests/compute/vm_clone.rb +11 -6
- data/lib/fog/vsphere/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad810bd0bdd64f88734bbd79e55ec34499638de434018789fee29d7b0e80e18b
|
4
|
+
data.tar.gz: 12ee08e303541b65f02314ab02187a04952dd487198bc33e2c84d87591bf8245
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5635212e1c8379224a31165790df4d2c34c09760e3c6b52e6d2a432500d1ec115f174ab09d264690cbd8d544eaeb9d64a946b96fe195d7531ac124aaec43fe2c
|
7
|
+
data.tar.gz: c078f8486725f2749a6c6729952154baf64864e6ce422190680c5b4125f584de5e9739b264f9fea667b49a294fe39ce3d5c1e0e5450522f3172fde86177f00c9
|
data/CHANGELOG.md
CHANGED
@@ -33,7 +33,7 @@ module Fog
|
|
33
33
|
# if any volume has a storage_pod set, we deploy the vm on a storage pod instead of the defined datastores
|
34
34
|
pod = get_storage_pod_from_volumes(attributes)
|
35
35
|
vm = if pod
|
36
|
-
create_vm_on_storage_pod(pod, vm_cfg, vmFolder, resource_pool, attributes[:datacenter], host)
|
36
|
+
create_vm_on_storage_pod(pod, attributes[:volumes], vm_cfg, vmFolder, resource_pool, attributes[:datacenter], host)
|
37
37
|
else
|
38
38
|
create_vm_on_datastore(vm_cfg, vmFolder, resource_pool, host)
|
39
39
|
end
|
@@ -46,15 +46,17 @@ module Fog
|
|
46
46
|
vm = vmFolder.CreateVM_Task(config: vm_cfg, pool: resource_pool, host: host).wait_for_completion
|
47
47
|
end
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
49
|
+
# rubocop:disable Metrics/ParameterLists
|
50
|
+
def create_vm_on_storage_pod(vm_pod_name, volumes, vm_cfg, vmFolder, resource_pool, datacenter, host = nil)
|
51
|
+
disks_per_pod = volumes.group_by(&:storage_pod)
|
52
|
+
disks_per_pod[vm_pod_name] ||= []
|
53
|
+
disks_per_pod[vm_pod_name].concat(disks_per_pod.delete(nil)) if disks_per_pod.key?(nil)
|
54
|
+
|
53
55
|
storage_spec = RbVmomi::VIM::StoragePlacementSpec.new(
|
54
56
|
type: 'create',
|
55
57
|
folder: vmFolder,
|
56
58
|
resourcePool: resource_pool,
|
57
|
-
podSelectionSpec:
|
59
|
+
podSelectionSpec: pod_selection_spec(vm_pod_name, disks_per_pod, datacenter),
|
58
60
|
configSpec: vm_cfg,
|
59
61
|
host: host
|
60
62
|
)
|
@@ -62,8 +64,11 @@ module Fog
|
|
62
64
|
result = srm.RecommendDatastores(storageSpec: storage_spec)
|
63
65
|
|
64
66
|
# if result array contains recommendation, we can apply it
|
65
|
-
|
66
|
-
|
67
|
+
# we need one recomendation for one storagePod
|
68
|
+
grouped_recoms = result.recommendations.group_by { |rec| rec.target._ref }
|
69
|
+
if grouped_recoms.keys.size == disks_per_pod.size
|
70
|
+
keys = grouped_recoms.map { |_ref, recoms| recoms.first.key }
|
71
|
+
result = srm.ApplyStorageDrsRecommendation_Task(key: keys).wait_for_completion
|
67
72
|
vm = result.vm
|
68
73
|
else
|
69
74
|
raise 'Could not create vm on storage pod, did not get a storage recommendation'
|
@@ -71,6 +76,21 @@ module Fog
|
|
71
76
|
vm
|
72
77
|
end
|
73
78
|
|
79
|
+
def pod_selection_spec(vm_pod_name, disks_per_pod, datacenter)
|
80
|
+
raw_pods = {}
|
81
|
+
disks_per_pod.each_key { |pod_name| raw_pods[pod_name] = get_raw_storage_pod(pod_name, datacenter) }
|
82
|
+
|
83
|
+
RbVmomi::VIM::StorageDrsPodSelectionSpec.new(
|
84
|
+
storagePod: raw_pods[vm_pod_name],
|
85
|
+
initialVmConfig: disks_per_pod.map do |name, vols|
|
86
|
+
RbVmomi::VIM::VmPodConfigForPlacement.new(
|
87
|
+
disk: vols.collect { |vol| RbVmomi::VIM::PodDiskLocator.new(diskId: vol.key) },
|
88
|
+
storagePod: raw_pods[name]
|
89
|
+
)
|
90
|
+
end
|
91
|
+
)
|
92
|
+
end
|
93
|
+
|
74
94
|
# check if a storage pool is set on any of the volumes and return the first result found or nil
|
75
95
|
# return early if vsphere revision is lower than 5 as this is not supported
|
76
96
|
def get_storage_pod_from_volumes(attributes)
|
@@ -650,14 +650,16 @@ module Fog
|
|
650
650
|
# Clone VM on a storage pod
|
651
651
|
if options.key?('storage_pod') && !options['storage_pod'].nil?
|
652
652
|
raise ArgumentError, 'need to use at least vsphere revision 5.0 or greater to use storage pods' unless @vsphere_rev.to_f >= 5
|
653
|
-
|
654
|
-
|
655
|
-
|
653
|
+
vm_pod_name = options['storage_pod']
|
654
|
+
disks_per_pod = options['volumes'].group_by(&:storage_pod)
|
655
|
+
disks_per_pod[vm_pod_name] ||= []
|
656
|
+
disks_per_pod[vm_pod_name].concat(disks_per_pod.delete(nil)) if disks_per_pod.key?(nil)
|
657
|
+
|
656
658
|
storage_spec = RbVmomi::VIM::StoragePlacementSpec.new(
|
657
659
|
type: 'clone',
|
658
660
|
folder: dest_folder,
|
659
661
|
resourcePool: resource_pool,
|
660
|
-
podSelectionSpec:
|
662
|
+
podSelectionSpec: pod_selection_spec(vm_pod_name, disks_per_pod, options['datacenter']),
|
661
663
|
cloneSpec: clone_spec,
|
662
664
|
cloneName: options['name'],
|
663
665
|
vm: vm_mob_ref
|
@@ -666,8 +668,11 @@ module Fog
|
|
666
668
|
result = srm.RecommendDatastores(storageSpec: storage_spec)
|
667
669
|
|
668
670
|
# if result array contains recommendation, we can apply it
|
669
|
-
|
670
|
-
|
671
|
+
# we need one recomendation for one storagePod
|
672
|
+
grouped_recoms = result.recommendations.group_by { |rec| rec.target._ref }
|
673
|
+
if grouped_recoms.keys.size == disks_per_pod.size
|
674
|
+
keys = grouped_recoms.map { |_ref, recoms| recoms.first.key }
|
675
|
+
task = srm.ApplyStorageDrsRecommendation_Task(key: keys)
|
671
676
|
if options.fetch('wait', true)
|
672
677
|
result = task.wait_for_completion
|
673
678
|
new_vm = result.vm
|
data/lib/fog/vsphere/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fog-vsphere
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- J.R. Garcia
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-06-
|
11
|
+
date: 2019-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fog-core
|