fog-vsphere 1.12.0 → 1.13.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 +4 -4
- data/.gitignore +2 -1
- data/CHANGELOG.md +10 -0
- data/CONTRIBUTORS.md +1 -0
- data/lib/fog/vsphere/compute.rb +1 -0
- data/lib/fog/vsphere/requests/compute/list_clusters.rb +23 -17
- data/lib/fog/vsphere/requests/compute/list_compute_resources.rb +6 -4
- data/lib/fog/vsphere/requests/compute/vm_clone.rb +47 -0
- data/lib/fog/vsphere/requests/compute/vm_migrate.rb +11 -3
- data/lib/fog/vsphere/requests/compute/vm_relocate.rb +54 -0
- data/lib/fog/vsphere/version.rb +1 -1
- data/tests/class_from_string_tests.rb +3 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 434e3b3463c5006cc61edfae3028d40ab4dca98d
|
4
|
+
data.tar.gz: 12a91a040ca124230c2454076861dc09ea72cf5d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2675e30b127dc42fe10d99ded01be9464b4e7fd0b00110056871a56f92f8e9e31ec28814ede6f79d6bd7781c812ff105d0d8184bda052ebcadc04759a683f268
|
7
|
+
data.tar.gz: ff34150ecd8f6a1788565ea7c2f047b0696ce4e94ae89baabd4cb8b83502fa5af3ccd54533e838ae46aaea3d5cc38afb586f60e4810fe3889298feb2d437d754
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
## v1.13.0
|
2
|
+
|
3
|
+
* Add ability to change boot order on VM clone (#110)
|
4
|
+
* Support cloning volumes in different datastore (#107)
|
5
|
+
* Add ability to generate new mac addresses on VM clone (#109)
|
6
|
+
* Fix list_compute_resources error when folder nested inside datacenter level (#100)
|
7
|
+
* Updated list_clusters to have an optional param or allow filtering on datacenter (#102)
|
8
|
+
* Add check option for vm_migrate
|
9
|
+
* Add vm_relocate request
|
10
|
+
|
1
11
|
## v1.12.0
|
2
12
|
|
3
13
|
* Add existing state validation for power on/off requests
|
data/CONTRIBUTORS.md
CHANGED
@@ -9,6 +9,7 @@
|
|
9
9
|
* Christopher Oliver <coliver@datapipe.com>
|
10
10
|
* Cyrus Team <cyrusteam@cyruslists.com>
|
11
11
|
* Darren Foo <stonith@users.noreply.github.com>
|
12
|
+
* Derek Wright <derekmwright@users.noreply.github.com>
|
12
13
|
* Dominic Cleal <dcleal@redhat.com>
|
13
14
|
* Eric Stonfer <ericstonfer@yahoo.com>
|
14
15
|
* Ewoud Kohl van Wijngaarden <ewoud@kohlvanwijngaarden.nl>
|
data/lib/fog/vsphere/compute.rb
CHANGED
@@ -2,11 +2,17 @@ module Fog
|
|
2
2
|
module Compute
|
3
3
|
class Vsphere
|
4
4
|
class Real
|
5
|
-
def list_clusters(filters = { })
|
6
|
-
datacenter_name = filters[:datacenter]
|
7
5
|
|
8
|
-
|
9
|
-
|
6
|
+
def list_clusters(filters = {})
|
7
|
+
datacenter_name = filters[:datacenter] if filters.key? :datacenter
|
8
|
+
if datacenter_name.nil?
|
9
|
+
list_datacenters.map { |dc| list_clusters(:datacenter => dc[:name]) }.flatten
|
10
|
+
else
|
11
|
+
raw_clusters(datacenter_name).map do |cluster|
|
12
|
+
if cluster.instance_of? RbVmomi::VIM::ClusterComputeResource
|
13
|
+
cluster_attributes(cluster, datacenter_name)
|
14
|
+
end
|
15
|
+
end.compact
|
10
16
|
end
|
11
17
|
end
|
12
18
|
|
@@ -27,41 +33,41 @@ module Fog
|
|
27
33
|
end.flatten
|
28
34
|
end
|
29
35
|
|
30
|
-
def cluster_attributes
|
36
|
+
def cluster_attributes(cluster, datacenter_name)
|
31
37
|
{
|
32
|
-
:id
|
33
|
-
:name
|
34
|
-
:full_path
|
35
|
-
:num_host
|
36
|
-
:num_cpu_cores
|
38
|
+
:id => managed_obj_id(cluster),
|
39
|
+
:name => cluster.name,
|
40
|
+
:full_path => cluster_path(cluster, datacenter_name),
|
41
|
+
:num_host => cluster.summary.numHosts,
|
42
|
+
:num_cpu_cores => cluster.summary.numCpuCores,
|
37
43
|
:overall_status => cluster.summary.overallStatus,
|
38
|
-
:datacenter
|
44
|
+
:datacenter => datacenter_name || parent_attribute(cluster.path, :datacenter)[1]
|
39
45
|
}
|
40
46
|
end
|
41
47
|
|
42
48
|
def cluster_path(cluster, datacenter_name)
|
43
49
|
datacenter = find_raw_datacenter(datacenter_name)
|
44
|
-
cluster.pretty_path.gsub(
|
50
|
+
cluster.pretty_path.gsub(%r{(#{Regexp.escape(datacenter_name)}|#{Regexp.escape(datacenter.hostFolder.name)})\/}, '')
|
45
51
|
end
|
46
52
|
end
|
47
53
|
|
48
54
|
class Mock
|
49
|
-
def list_clusters(
|
55
|
+
def list_clusters(*)
|
50
56
|
raw_clusters.map do |cluster|
|
51
57
|
cluster
|
52
58
|
end
|
53
59
|
end
|
54
60
|
|
55
61
|
def raw_clusters
|
56
|
-
folder =
|
62
|
+
folder = data[:clusters]
|
57
63
|
@raw_clusters = get_raw_clusters_from_folder(folder)
|
58
64
|
end
|
59
65
|
|
60
66
|
def get_raw_clusters_from_folder(folder)
|
61
67
|
folder.map do |child|
|
62
|
-
if child[:klass] ==
|
63
|
-
|
64
|
-
elsif child[:klass] ==
|
68
|
+
if child[:klass] == 'RbVmomi::VIM::ComputeResource'
|
69
|
+
child
|
70
|
+
elsif child[:klass] == 'RbVmomi::VIM::Folder'
|
65
71
|
get_raw_clusters_from_folder(child[:clusters])
|
66
72
|
end
|
67
73
|
end.flatten
|
@@ -9,9 +9,11 @@ module Fog
|
|
9
9
|
compute_resources = raw_compute_resources datacenter_name
|
10
10
|
|
11
11
|
compute_resources.map do |compute_resource|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
unless compute_resource.instance_of? RbVmomi::VIM::Folder
|
13
|
+
summary = compute_resource.summary
|
14
|
+
next if only_active and summary.numEffectiveHosts == 0
|
15
|
+
compute_resource_attributes(compute_resource, datacenter_name)
|
16
|
+
end
|
15
17
|
end.compact
|
16
18
|
end
|
17
19
|
|
@@ -89,4 +91,4 @@ module Fog
|
|
89
91
|
end
|
90
92
|
end
|
91
93
|
end
|
92
|
-
end
|
94
|
+
end
|
@@ -175,6 +175,37 @@ module Fog
|
|
175
175
|
virtual_machine_config_spec.memoryHotAddEnabled = options['memoryHotAddEnabled'] if ( options.key?('memoryHotAddEnabled') )
|
176
176
|
virtual_machine_config_spec.firmware = options['firmware'] if ( options.key?('firmware') )
|
177
177
|
virtual_machine_config_spec.extraConfig = extra_config(extra_config: options['extraConfig']) if ( options.key?('extraConfig') )
|
178
|
+
if @vsphere_rev.to_f >= 5 && options.key?('boot_order')
|
179
|
+
boot_order = options['boot_order'].flat_map do |boot_device|
|
180
|
+
case boot_device.to_sym
|
181
|
+
when :network
|
182
|
+
interfaces = device_change.select do |change|
|
183
|
+
[:edit, :add].include?(change[:operation]) &&
|
184
|
+
change[:device].class <= RbVmomi::VIM::VirtualEthernetCard
|
185
|
+
end.map { |change| change[:device] }
|
186
|
+
interfaces.map do |interface|
|
187
|
+
RbVmomi::VIM::VirtualMachineBootOptionsBootableEthernetDevice.new(
|
188
|
+
:deviceKey => interface.key
|
189
|
+
)
|
190
|
+
end
|
191
|
+
when :disk
|
192
|
+
disks = device_change.select do |change|
|
193
|
+
[:edit, :add].include?(change[:operation]) &&
|
194
|
+
change[:device].is_a?(RbVmomi::VIM::VirtualDisk)
|
195
|
+
end.map { |change| change[:device] }
|
196
|
+
disks.map do |disk|
|
197
|
+
RbVmomi::VIM::VirtualMachineBootOptionsBootableDiskDevice.new(
|
198
|
+
:deviceKey => disk.key
|
199
|
+
)
|
200
|
+
end
|
201
|
+
when :cdrom
|
202
|
+
RbVmomi::VIM::VirtualMachineBootOptionsBootableCdromDevice.new
|
203
|
+
when :floppy
|
204
|
+
RbVmomi::VIM::VirtualMachineBootOptionsBootableFloppyDevice.new
|
205
|
+
end
|
206
|
+
end
|
207
|
+
virtual_machine_config_spec.bootOptions = { :bootOrder => boot_order }
|
208
|
+
end
|
178
209
|
# Options['customization_spec']
|
179
210
|
# OLD Options still supported
|
180
211
|
# * domain <~String> - *REQUIRED* - Sets the server's domain for customization
|
@@ -598,6 +629,7 @@ module Fog
|
|
598
629
|
relocation_spec[:datastore] = datastore_obj
|
599
630
|
end
|
600
631
|
end
|
632
|
+
relocation_spec[:disk] = relocate_template_volumes_specs(vm_mob_ref, options['volumes'], options['datacenter'])
|
601
633
|
# And the clone specification
|
602
634
|
clone_spec = RbVmomi::VIM.VirtualMachineCloneSpec(:location => relocation_spec,
|
603
635
|
:config => virtual_machine_config_spec,
|
@@ -721,6 +753,8 @@ module Fog
|
|
721
753
|
if new_nic
|
722
754
|
backing = create_nic_backing(new_nic, {})
|
723
755
|
template_nic.backing = backing
|
756
|
+
template_nic.addressType = 'generated'
|
757
|
+
template_nic.macAddress = nil
|
724
758
|
connectable = RbVmomi::VIM::VirtualDeviceConnectInfo(
|
725
759
|
:allowGuestControl => true,
|
726
760
|
:connected => true,
|
@@ -768,6 +802,19 @@ module Fog
|
|
768
802
|
specs.concat(new_volumes.map { |volume| create_disk(volume) })
|
769
803
|
return specs
|
770
804
|
end
|
805
|
+
|
806
|
+
def relocate_template_volumes_specs(vm_mob_ref, volumes, datacenter)
|
807
|
+
template_volumes = vm_mob_ref.config.hardware.device.grep(RbVmomi::VIM::VirtualDisk)
|
808
|
+
modified_volumes = volumes.take(template_volumes.size)
|
809
|
+
|
810
|
+
specs = []
|
811
|
+
template_volumes.zip(modified_volumes).each do |template_volume, new_volume|
|
812
|
+
if new_volume && new_volume.datastore != template_volume.backing.datastore.name
|
813
|
+
specs << { :diskId => new_volume.key, :datastore => get_raw_datastore(new_volume.datastore, datacenter) }
|
814
|
+
end
|
815
|
+
end
|
816
|
+
return specs
|
817
|
+
end
|
771
818
|
end
|
772
819
|
|
773
820
|
class Mock
|
@@ -16,9 +16,17 @@ module Fog
|
|
16
16
|
"Could not find VirtualMachine with instance uuid #{options['instance_uuid']}"
|
17
17
|
end
|
18
18
|
options['host'] = get_raw_host(options['host'], options['cluster'], options['datacenter']) if options['host']
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
task_options = {:pool => options['pool'], :host => options['host'], :state => options['state']}
|
20
|
+
if options['check']
|
21
|
+
checker = connection.serviceContent.vmProvisioningChecker
|
22
|
+
task = checker.CheckMigrate_Task(task_options.merge(:vm => vm_mob_ref))
|
23
|
+
task.wait_for_completion
|
24
|
+
{'error' => task.info.result[0].error, 'warning' => task.info.result[0].warning}
|
25
|
+
else
|
26
|
+
task = vm_mob_ref.MigrateVM_Task(task_options.merge(:priority => "#{priority}"))
|
27
|
+
task.wait_for_completion
|
28
|
+
{ 'task_state' => task.info.state }
|
29
|
+
end
|
22
30
|
end
|
23
31
|
end
|
24
32
|
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Fog
|
2
|
+
module Compute
|
3
|
+
class Vsphere
|
4
|
+
class Real
|
5
|
+
# Clones a VM from a template or existing machine on your vSphere
|
6
|
+
# Server.
|
7
|
+
#
|
8
|
+
# ==== Parameters
|
9
|
+
# * options<~Hash>:
|
10
|
+
# * 'instance_uuid'<~String> - *REQUIRED* VM to relocate
|
11
|
+
# * 'host'<~String> - name of host which will run the VM.
|
12
|
+
# * 'pool'<~String> - name of pool which the VM should be
|
13
|
+
# attached.
|
14
|
+
# * 'disks'<~Array> - disks to relocate. Each disk is a
|
15
|
+
# hash with diskId wich is key attribute of volume,
|
16
|
+
# and datastore to relocate to.
|
17
|
+
def vm_relocate(options = {})
|
18
|
+
raise ArgumentError, "instance_uuid is a required parameter" unless options.key? 'instance_uuid'
|
19
|
+
|
20
|
+
# Find the VM Object
|
21
|
+
search_filter = { :uuid => options['instance_uuid'], 'vmSearch' => true, 'instanceUuid' => true }
|
22
|
+
vm_mob_ref = connection.searchIndex.FindAllByUuid(search_filter).first
|
23
|
+
|
24
|
+
unless vm_mob_ref.kind_of? RbVmomi::VIM::VirtualMachine
|
25
|
+
raise Fog::Vsphere::Errors::NotFound,
|
26
|
+
"Could not find VirtualMachine with instance uuid #{options['instance_uuid']}"
|
27
|
+
end
|
28
|
+
options['host'] = get_raw_host(options['host'], options['cluster'], options['datacenter']) if options['host']
|
29
|
+
if options['disks']
|
30
|
+
options['disks'] = options['disks'].map do |disk|
|
31
|
+
disk['datastore'] = get_raw_datastore(disk['datastore'], nil)
|
32
|
+
RbVmomi::VIM::VirtualMachineRelocateSpecDiskLocator(disk)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
spec = RbVmomi::VIM::VirtualMachineRelocateSpec(
|
36
|
+
:pool => options['pool'],
|
37
|
+
:host => options['host'],
|
38
|
+
:disk => options['disks']
|
39
|
+
)
|
40
|
+
task = vm_mob_ref.RelocateVM_Task(:spec => spec, :priority => options["priority"])
|
41
|
+
task.wait_for_completion
|
42
|
+
{ 'task_state' => task.info.state }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class Mock
|
47
|
+
def vm_relocate(options = {})
|
48
|
+
raise ArgumentError, "instance_uuid is a required parameter" unless options.key? 'instance_uuid'
|
49
|
+
{ 'task_state' => 'success' }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/fog/vsphere/version.rb
CHANGED
@@ -4,11 +4,11 @@ class A; class B; class C; end; end; end
|
|
4
4
|
|
5
5
|
class TestClassFromString < Minitest::Test
|
6
6
|
def test_empty_string
|
7
|
-
|
7
|
+
assert_nil(Fog::Vsphere.class_from_string(''))
|
8
8
|
end
|
9
9
|
|
10
10
|
def test_nil
|
11
|
-
|
11
|
+
assert_nil(Fog::Vsphere.class_from_string(nil))
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_name_as_class
|
@@ -20,7 +20,7 @@ class TestClassFromString < Minitest::Test
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def test_unexpected_input
|
23
|
-
|
23
|
+
assert_nil(Fog::Vsphere.class_from_string(8))
|
24
24
|
end
|
25
25
|
|
26
26
|
def test_nested_class_without_default_path
|
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: 1.
|
4
|
+
version: 1.13.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: 2017-
|
11
|
+
date: 2017-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fog-core
|
@@ -254,6 +254,7 @@ files:
|
|
254
254
|
- lib/fog/vsphere/requests/compute/vm_reconfig_hardware.rb
|
255
255
|
- lib/fog/vsphere/requests/compute/vm_reconfig_memory.rb
|
256
256
|
- lib/fog/vsphere/requests/compute/vm_reconfig_volumes.rb
|
257
|
+
- lib/fog/vsphere/requests/compute/vm_relocate.rb
|
257
258
|
- lib/fog/vsphere/requests/compute/vm_remove_snapshot.rb
|
258
259
|
- lib/fog/vsphere/requests/compute/vm_rename.rb
|
259
260
|
- lib/fog/vsphere/requests/compute/vm_revert_snapshot.rb
|