fog-vsphere 3.1.1 → 3.2.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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73be829a1d5ffd1d11f38e91c589dc06d13053df3265907615b8ab025d577dc0
|
4
|
+
data.tar.gz: fbcffa36f4ea94ae6a3f56a958143593a5a27b84041bc70fb5842830063d288d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f74b04e50ffc07f9523df9b27e954b4709fb65f347f7c1c1bfadda3c1b0a19953f1e38cf46695041242276a363f8a6feecda18385d00e42230551a5b502868fb
|
7
|
+
data.tar.gz: 5a0a583a956180e5bb8bbb2758472c5e510b7f9814af7ecac32cf82f3a736cd348e0c0243f73de5cf94f432dcaa55e40f316ee278b1e5ba97967490dd2b23160
|
data/CHANGELOG.md
CHANGED
data/CONTRIBUTORS.md
CHANGED
@@ -56,6 +56,7 @@
|
|
56
56
|
* Paul Thornthwaite <paul@brightbox.co.uk>
|
57
57
|
* Paul Thornthwaite <tokengeek@gmail.com>
|
58
58
|
* Paulo Henrique Lopes Ribeiro <plribeiro3000@gmail.com>
|
59
|
+
* Rohan Arora <roarora@redhat.com>
|
59
60
|
* Rich Daley <rdaley@williamhill.co.uk>
|
60
61
|
* Rich Lane <rlane@club.cc.cmu.edu>
|
61
62
|
* Samuel Keeley <samuel@dropbox.com>
|
@@ -48,15 +48,11 @@ module Fog
|
|
48
48
|
|
49
49
|
# rubocop:disable Metrics/ParameterLists
|
50
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
|
-
|
55
51
|
storage_spec = RbVmomi::VIM::StoragePlacementSpec.new(
|
56
52
|
type: 'create',
|
57
53
|
folder: vmFolder,
|
58
54
|
resourcePool: resource_pool,
|
59
|
-
podSelectionSpec: pod_selection_spec(vm_pod_name,
|
55
|
+
podSelectionSpec: pod_selection_spec(vm_pod_name, group_disks_by_storage_pod(volumes, vm_pod_name), datacenter),
|
60
56
|
configSpec: vm_cfg,
|
61
57
|
host: host
|
62
58
|
)
|
@@ -76,19 +72,40 @@ module Fog
|
|
76
72
|
vm
|
77
73
|
end
|
78
74
|
|
79
|
-
def
|
75
|
+
def group_disks_by_storage_pod(volumes, vm_pod_name: nil)
|
76
|
+
vm_pod_name ||= volumes.detect { |v| !v.storage_pod.empty? }.storage_pod
|
77
|
+
disks_per_pod = volumes.group_by(&:storage_pod)
|
78
|
+
if disks_per_pod.key?(nil)
|
79
|
+
disks_per_pod[vm_pod_name] ||= []
|
80
|
+
disks_per_pod[vm_pod_name].concat(disks_per_pod.delete(nil))
|
81
|
+
end
|
82
|
+
disks_per_pod
|
83
|
+
end
|
84
|
+
|
85
|
+
def pod_selection_spec(vm_pod_name, disks_per_pod, datacenter, with_relocation: false, only_volumes: false)
|
80
86
|
raw_pods = {}
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
87
|
+
raw_pods[vm_pod_name] = get_raw_storage_pod(vm_pod_name, datacenter)
|
88
|
+
disks_per_pod.each_key { |pod_name| raw_pods[pod_name] ||= get_raw_storage_pod(pod_name, datacenter) }
|
89
|
+
|
90
|
+
disk_placements = disks_per_pod.map do |name, vols|
|
91
|
+
RbVmomi::VIM::VmPodConfigForPlacement.new(
|
92
|
+
disk: vols.collect do |vol|
|
93
|
+
locator = RbVmomi::VIM::PodDiskLocator.new(diskId: vol.key)
|
94
|
+
locator[:diskBackingInfo] = relocation_volume_backing(vol) if with_relocation
|
95
|
+
locator
|
96
|
+
end,
|
97
|
+
storagePod: raw_pods[name]
|
98
|
+
)
|
99
|
+
end
|
100
|
+
vm_config_placements = []
|
101
|
+
vm_config_placements << RbVmomi::VIM::VmPodConfigForPlacement.new(storagePod: raw_pods[vm_pod_name], disk: []) unless only_volumes
|
102
|
+
vm_config_placements.concat(disk_placements)
|
103
|
+
|
104
|
+
spec = RbVmomi::VIM::StorageDrsPodSelectionSpec.new(
|
105
|
+
initialVmConfig: vm_config_placements
|
91
106
|
)
|
107
|
+
spec[:storagePod] = raw_pods[vm_pod_name] unless only_volumes
|
108
|
+
spec
|
92
109
|
end
|
93
110
|
|
94
111
|
# check if a storage pool is set on any of the volumes and return the first result found or nil
|
@@ -164,7 +164,8 @@ module Fog
|
|
164
164
|
device_change << modify_template_nics_simple_spec(options['network_label'], options['nic_type'], options['network_adapter_device_key'], options['datacenter'])
|
165
165
|
end
|
166
166
|
if disks = options['volumes']
|
167
|
-
device_change.concat(modify_template_volumes_specs(vm_mob_ref, options['volumes']
|
167
|
+
device_change.concat(modify_template_volumes_specs(vm_mob_ref, options['volumes']))
|
168
|
+
device_change.concat(add_new_volumes_specs(vm_mob_ref, options['volumes'])) unless options['storage_pod']
|
168
169
|
end
|
169
170
|
virtual_machine_config_spec.deviceChange = device_change if device_change.any?
|
170
171
|
# Options['numCPUs'] or Options['memoryMB']
|
@@ -178,6 +179,7 @@ module Fog
|
|
178
179
|
virtual_machine_config_spec.cpuHotAddEnabled = options['cpuHotAddEnabled'] if options.key?('cpuHotAddEnabled')
|
179
180
|
virtual_machine_config_spec.memoryHotAddEnabled = options['memoryHotAddEnabled'] if options.key?('memoryHotAddEnabled')
|
180
181
|
virtual_machine_config_spec.firmware = options['firmware'] if options.key?('firmware')
|
182
|
+
virtual_machine_config_spec.annotation = options['annotation'] if options.key?('annotation')
|
181
183
|
virtual_machine_config_spec.extraConfig = extra_config(extra_config: options['extraConfig']) if options.key?('extraConfig')
|
182
184
|
if @vsphere_rev.to_f >= 5 && options.key?('boot_order')
|
183
185
|
boot_order = options['boot_order'].flat_map do |boot_device|
|
@@ -627,18 +629,16 @@ module Fog
|
|
627
629
|
diskMoveType: :moveChildMostDiskBacking)
|
628
630
|
else
|
629
631
|
relocation_spec = RbVmomi::VIM.VirtualMachineRelocateSpec(pool: resource_pool,
|
630
|
-
host: host
|
631
|
-
|
632
|
-
unless options.key?('storage_pod') && datastore_obj.nil?
|
632
|
+
host: host)
|
633
|
+
unless options['storage_pod'] && datastore_obj.nil?
|
633
634
|
relocation_spec[:datastore] = datastore_obj
|
634
635
|
end
|
635
636
|
end
|
636
637
|
# relocate templates is not supported by fog-vsphere when vm is cloned on a storage pod
|
637
|
-
|
638
|
-
|
639
|
-
relocation_spec[:disk] = relocate_template_volumes_specs(vm_mob_ref, options['volumes'], options['datacenter'])
|
640
|
-
end
|
638
|
+
if !options['storage_pod'] && options['volumes'] && !options['volumes'].empty?
|
639
|
+
relocation_spec[:disk] = relocate_template_volumes_specs(vm_mob_ref, options['volumes'], options['datacenter'])
|
641
640
|
end
|
641
|
+
|
642
642
|
# And the clone specification
|
643
643
|
clone_spec = RbVmomi::VIM.VirtualMachineCloneSpec(location: relocation_spec,
|
644
644
|
config: virtual_machine_config_spec,
|
@@ -648,18 +648,16 @@ module Fog
|
|
648
648
|
|
649
649
|
# Perform the actual Clone Task
|
650
650
|
# Clone VM on a storage pod
|
651
|
-
if options
|
651
|
+
if options['storage_pod']
|
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
653
|
vm_pod_name = options['storage_pod']
|
654
|
-
disks_per_pod = options['volumes']
|
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)
|
654
|
+
disks_per_pod = group_disks_by_storage_pod(modified_volumes(vm_mob_ref, options['volumes']), vm_pod_name: options['storage_pod'])
|
657
655
|
|
658
656
|
storage_spec = RbVmomi::VIM::StoragePlacementSpec.new(
|
659
657
|
type: 'clone',
|
660
658
|
folder: dest_folder,
|
661
659
|
resourcePool: resource_pool,
|
662
|
-
podSelectionSpec: pod_selection_spec(vm_pod_name, disks_per_pod, options['datacenter']),
|
660
|
+
podSelectionSpec: pod_selection_spec(vm_pod_name, disks_per_pod, options['datacenter'], with_relocation: true),
|
663
661
|
cloneSpec: clone_spec,
|
664
662
|
cloneName: options['name'],
|
665
663
|
vm: vm_mob_ref
|
@@ -688,6 +686,26 @@ module Fog
|
|
688
686
|
raise Fog::Vsphere::Errors::NotFound unless new_vm
|
689
687
|
end
|
690
688
|
end
|
689
|
+
|
690
|
+
new_volumes = new_volumes(vm_mob_ref, options['volumes'])
|
691
|
+
if new_vm && !new_volumes.empty?
|
692
|
+
new_disks_per_pod = group_disks_by_storage_pod(new_volumes, vm_pod_name: options['storage_pod'])
|
693
|
+
add_vols_config_spec = {
|
694
|
+
deviceChange: add_new_volumes_specs(vm_mob_ref, options['volumes'], default_storage_pod: options['storage_pod'])
|
695
|
+
}
|
696
|
+
placement_spec = RbVmomi::VIM::StoragePlacementSpec.new(
|
697
|
+
type: 'reconfigure',
|
698
|
+
vm: new_vm,
|
699
|
+
configSpec: add_vols_config_spec,
|
700
|
+
podSelectionSpec: pod_selection_spec(vm_pod_name, new_disks_per_pod, options['datacenter'], only_volumes: true)
|
701
|
+
)
|
702
|
+
result = srm.RecommendDatastores(storageSpec: placement_spec)
|
703
|
+
grouped_recoms = result.recommendations.group_by { |rec| rec.target._ref }
|
704
|
+
if grouped_recoms.keys.size == new_disks_per_pod.size
|
705
|
+
keys = grouped_recoms.map { |_ref, recoms| recoms.first.key }
|
706
|
+
srm.ApplyStorageDrsRecommendation_Task(key: keys).wait_for_completion
|
707
|
+
end
|
708
|
+
end
|
691
709
|
else
|
692
710
|
task = vm_mob_ref.CloneVM_Task(folder: dest_folder,
|
693
711
|
name: options['name'],
|
@@ -794,13 +812,21 @@ module Fog
|
|
794
812
|
specs
|
795
813
|
end
|
796
814
|
|
797
|
-
def
|
815
|
+
def modified_volumes(vm_mob_ref, volumes)
|
816
|
+
template_volumes = vm_mob_ref.config.hardware.device.grep(RbVmomi::VIM::VirtualDisk)
|
817
|
+
volumes.take(template_volumes.size)
|
818
|
+
end
|
819
|
+
|
820
|
+
def new_volumes(vm_mob_ref, volumes)
|
821
|
+
template_volumes = vm_mob_ref.config.hardware.device.grep(RbVmomi::VIM::VirtualDisk)
|
822
|
+
volumes.drop(template_volumes.size)
|
823
|
+
end
|
824
|
+
|
825
|
+
def modify_template_volumes_specs(vm_mob_ref, volumes)
|
798
826
|
template_volumes = vm_mob_ref.config.hardware.device.grep(RbVmomi::VIM::VirtualDisk)
|
799
|
-
modified_volumes = volumes.take(template_volumes.size)
|
800
|
-
new_volumes = volumes.drop(template_volumes.size)
|
801
827
|
|
802
828
|
specs = []
|
803
|
-
template_volumes.zip(modified_volumes).each do |template_volume, new_volume|
|
829
|
+
template_volumes.zip(modified_volumes(vm_mob_ref, volumes)).each do |template_volume, new_volume|
|
804
830
|
if new_volume
|
805
831
|
# copy identifiers to fog device to mark them as used
|
806
832
|
new_volume.unit_number = template_volume.unitNumber
|
@@ -819,22 +845,36 @@ module Fog
|
|
819
845
|
device: template_volume }
|
820
846
|
end
|
821
847
|
end
|
822
|
-
specs.concat(new_volumes.map { |volume| create_disk(volume, :add, storage_pod: default_storage_pod) })
|
823
848
|
specs
|
824
849
|
end
|
825
850
|
|
851
|
+
def add_new_volumes_specs(vm_mob_ref, volumes, default_storage_pod: nil)
|
852
|
+
new_volumes(vm_mob_ref, volumes).map { |volume| create_disk(volume, :add, storage_pod: default_storage_pod) }
|
853
|
+
end
|
854
|
+
|
826
855
|
def relocate_template_volumes_specs(vm_mob_ref, volumes, datacenter)
|
827
856
|
template_volumes = vm_mob_ref.config.hardware.device.grep(RbVmomi::VIM::VirtualDisk)
|
828
857
|
modified_volumes = volumes.take(template_volumes.size)
|
829
858
|
|
830
859
|
specs = []
|
831
860
|
template_volumes.zip(modified_volumes).each do |template_volume, new_volume|
|
832
|
-
|
833
|
-
|
834
|
-
|
861
|
+
next unless new_volume
|
862
|
+
specs << RbVmomi::VIM.VirtualMachineRelocateSpecDiskLocator(
|
863
|
+
diskId: template_volume.key,
|
864
|
+
datastore: get_raw_datastore(new_volume.datastore, datacenter),
|
865
|
+
diskBackingInfo: relocation_volume_backing(new_volume)
|
866
|
+
)
|
835
867
|
end
|
836
868
|
specs
|
837
869
|
end
|
870
|
+
|
871
|
+
def relocation_volume_backing(volume)
|
872
|
+
RbVmomi::VIM.VirtualDiskFlatVer2BackingInfo(
|
873
|
+
diskMode: volume.mode.to_sym,
|
874
|
+
fileName: '',
|
875
|
+
thinProvisioned: volume.thin
|
876
|
+
)
|
877
|
+
end
|
838
878
|
end
|
839
879
|
|
840
880
|
# rubocop:enable ClassLength
|
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.
|
4
|
+
version: 3.2.0
|
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-
|
11
|
+
date: 2019-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fog-core
|
@@ -334,8 +334,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
334
334
|
- !ruby/object:Gem::Version
|
335
335
|
version: '0'
|
336
336
|
requirements: []
|
337
|
-
|
338
|
-
rubygems_version: 2.7.6.2
|
337
|
+
rubygems_version: 3.0.4
|
339
338
|
signing_key:
|
340
339
|
specification_version: 4
|
341
340
|
summary: Module for the 'fog' gem to support VMware vSphere.
|