fog-vsphere 2.1.1 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +8 -0
- data/.rubocop_todo.yml +217 -0
- data/.travis.yml +1 -0
- data/CHANGELOG.md +4 -0
- data/Rakefile +10 -1
- data/fog-vsphere.gemspec +2 -2
- data/lib/fog/bin/vsphere.rb +1 -1
- data/lib/fog/vsphere/compute.rb +320 -301
- data/lib/fog/vsphere/models/compute/cdrom.rb +10 -10
- data/lib/fog/vsphere/models/compute/cdroms.rb +2 -2
- data/lib/fog/vsphere/models/compute/cluster.rb +20 -20
- data/lib/fog/vsphere/models/compute/clusters.rb +1 -1
- data/lib/fog/vsphere/models/compute/customfields.rb +4 -4
- data/lib/fog/vsphere/models/compute/customvalues.rb +8 -8
- data/lib/fog/vsphere/models/compute/datacenter.rb +16 -16
- data/lib/fog/vsphere/models/compute/datastores.rb +1 -1
- data/lib/fog/vsphere/models/compute/folder.rb +2 -2
- data/lib/fog/vsphere/models/compute/folders.rb +2 -2
- data/lib/fog/vsphere/models/compute/hosts.rb +4 -4
- data/lib/fog/vsphere/models/compute/interface.rb +12 -12
- data/lib/fog/vsphere/models/compute/interfaces.rb +14 -16
- data/lib/fog/vsphere/models/compute/interfacetype.rb +2 -2
- data/lib/fog/vsphere/models/compute/interfacetypes.rb +6 -8
- data/lib/fog/vsphere/models/compute/networks.rb +1 -1
- data/lib/fog/vsphere/models/compute/resource_pools.rb +1 -1
- data/lib/fog/vsphere/models/compute/rule.rb +8 -9
- data/lib/fog/vsphere/models/compute/rules.rb +9 -10
- data/lib/fog/vsphere/models/compute/scsicontroller.rb +1 -1
- data/lib/fog/vsphere/models/compute/server.rb +68 -80
- data/lib/fog/vsphere/models/compute/servers.rb +12 -13
- data/lib/fog/vsphere/models/compute/servertype.rb +6 -6
- data/lib/fog/vsphere/models/compute/servertypes.rb +2 -2
- data/lib/fog/vsphere/models/compute/snapshot.rb +5 -6
- data/lib/fog/vsphere/models/compute/snapshots.rb +1 -1
- data/lib/fog/vsphere/models/compute/ticket.rb +0 -1
- data/lib/fog/vsphere/models/compute/volume.rb +12 -14
- data/lib/fog/vsphere/models/compute/volumes.rb +10 -10
- data/lib/fog/vsphere/requests/compute/cloudinit_to_customspec.rb +8 -8
- data/lib/fog/vsphere/requests/compute/create_folder.rb +5 -5
- data/lib/fog/vsphere/requests/compute/create_group.rb +16 -16
- data/lib/fog/vsphere/requests/compute/create_rule.rb +13 -13
- data/lib/fog/vsphere/requests/compute/create_vm.rb +117 -119
- data/lib/fog/vsphere/requests/compute/destroy_group.rb +8 -8
- data/lib/fog/vsphere/requests/compute/destroy_rule.rb +8 -8
- data/lib/fog/vsphere/requests/compute/folder_destroy.rb +3 -3
- data/lib/fog/vsphere/requests/compute/get_cluster.rb +2 -2
- data/lib/fog/vsphere/requests/compute/get_compute_resource.rb +16 -16
- data/lib/fog/vsphere/requests/compute/get_datacenter.rb +7 -7
- data/lib/fog/vsphere/requests/compute/get_datastore.rb +1 -2
- data/lib/fog/vsphere/requests/compute/get_folder.rb +24 -24
- data/lib/fog/vsphere/requests/compute/get_host.rb +2 -3
- data/lib/fog/vsphere/requests/compute/get_interface_type.rb +6 -6
- data/lib/fog/vsphere/requests/compute/get_network.rb +7 -10
- data/lib/fog/vsphere/requests/compute/get_resource_pool.rb +1 -2
- data/lib/fog/vsphere/requests/compute/get_server_type.rb +14 -14
- data/lib/fog/vsphere/requests/compute/get_storage_pod.rb +2 -2
- data/lib/fog/vsphere/requests/compute/get_template.rb +1 -2
- data/lib/fog/vsphere/requests/compute/get_virtual_machine.rb +26 -26
- data/lib/fog/vsphere/requests/compute/get_vm_first_scsi_controller.rb +6 -7
- data/lib/fog/vsphere/requests/compute/host_finish_maintenance.rb +1 -1
- data/lib/fog/vsphere/requests/compute/host_shutdown.rb +1 -1
- data/lib/fog/vsphere/requests/compute/host_start_maintenance.rb +1 -1
- data/lib/fog/vsphere/requests/compute/list_child_snapshots.rb +37 -39
- data/lib/fog/vsphere/requests/compute/list_clusters.rb +8 -9
- data/lib/fog/vsphere/requests/compute/list_compute_resources.rb +57 -59
- data/lib/fog/vsphere/requests/compute/list_customfields.rb +5 -6
- data/lib/fog/vsphere/requests/compute/list_datacenters.rb +17 -17
- data/lib/fog/vsphere/requests/compute/list_datastores.rb +16 -15
- data/lib/fog/vsphere/requests/compute/list_folders.rb +4 -4
- data/lib/fog/vsphere/requests/compute/list_groups.rb +5 -5
- data/lib/fog/vsphere/requests/compute/list_hosts.rb +30 -14
- data/lib/fog/vsphere/requests/compute/list_interface_types.rb +7 -7
- data/lib/fog/vsphere/requests/compute/list_networks.rb +12 -16
- data/lib/fog/vsphere/requests/compute/list_processes.rb +14 -14
- data/lib/fog/vsphere/requests/compute/list_resource_pools.rb +13 -14
- data/lib/fog/vsphere/requests/compute/list_rules.rb +4 -4
- data/lib/fog/vsphere/requests/compute/list_server_types.rb +24 -26
- data/lib/fog/vsphere/requests/compute/list_storage_pods.rb +8 -8
- data/lib/fog/vsphere/requests/compute/list_templates.rb +4 -5
- data/lib/fog/vsphere/requests/compute/list_virtual_machines.rb +15 -15
- data/lib/fog/vsphere/requests/compute/list_vm_cdroms.rb +16 -12
- data/lib/fog/vsphere/requests/compute/list_vm_customvalues.rb +3 -4
- data/lib/fog/vsphere/requests/compute/list_vm_interfaces.rb +54 -56
- data/lib/fog/vsphere/requests/compute/list_vm_scsi_controllers.rb +7 -7
- data/lib/fog/vsphere/requests/compute/list_vm_snapshots.rb +36 -36
- data/lib/fog/vsphere/requests/compute/list_vm_volumes.rb +43 -36
- data/lib/fog/vsphere/requests/compute/modify_vm_cdrom.rb +4 -4
- data/lib/fog/vsphere/requests/compute/modify_vm_controller.rb +2 -2
- data/lib/fog/vsphere/requests/compute/modify_vm_interface.rb +26 -19
- data/lib/fog/vsphere/requests/compute/modify_vm_volume.rb +7 -7
- data/lib/fog/vsphere/requests/compute/revert_to_snapshot.rb +2 -2
- data/lib/fog/vsphere/requests/compute/set_vm_customvalue.rb +2 -2
- data/lib/fog/vsphere/requests/compute/update_vm.rb +111 -0
- data/lib/fog/vsphere/requests/compute/upload_iso.rb +10 -10
- data/lib/fog/vsphere/requests/compute/vm_acquire_ticket.rb +3 -3
- data/lib/fog/vsphere/requests/compute/vm_clone.rb +245 -247
- data/lib/fog/vsphere/requests/compute/vm_config_vnc.rb +15 -15
- data/lib/fog/vsphere/requests/compute/vm_destroy.rb +2 -2
- data/lib/fog/vsphere/requests/compute/vm_execute.rb +16 -16
- data/lib/fog/vsphere/requests/compute/vm_migrate.rb +11 -11
- data/lib/fog/vsphere/requests/compute/vm_power_off.rb +8 -8
- data/lib/fog/vsphere/requests/compute/vm_power_on.rb +2 -2
- data/lib/fog/vsphere/requests/compute/vm_reboot.rb +5 -5
- data/lib/fog/vsphere/requests/compute/vm_reconfig_cdrom.rb +11 -11
- data/lib/fog/vsphere/requests/compute/vm_reconfig_cpus.rb +8 -8
- data/lib/fog/vsphere/requests/compute/vm_reconfig_hardware.rb +6 -6
- data/lib/fog/vsphere/requests/compute/vm_reconfig_memory.rb +8 -8
- data/lib/fog/vsphere/requests/compute/vm_reconfig_volumes.rb +14 -16
- data/lib/fog/vsphere/requests/compute/vm_relocate.rb +8 -8
- data/lib/fog/vsphere/requests/compute/vm_remove_snapshot.rb +2 -2
- data/lib/fog/vsphere/requests/compute/vm_rename.rb +5 -5
- data/lib/fog/vsphere/requests/compute/vm_revert_snapshot.rb +1 -1
- data/lib/fog/vsphere/requests/compute/vm_take_snapshot.rb +8 -8
- data/lib/fog/vsphere/version.rb +1 -1
- data/tests/compute_tests.rb +16 -17
- data/tests/helpers/mock_helper.rb +3 -3
- data/tests/models/compute/cluster_tests.rb +4 -5
- data/tests/models/compute/hosts_tests.rb +2 -4
- data/tests/models/compute/rules_tests.rb +10 -16
- data/tests/models/compute/server_tests.rb +30 -31
- data/tests/models/compute/servers_tests.rb +2 -4
- data/tests/models/compute/ticket_tests.rb +4 -6
- data/tests/models/compute/tickets_tests.rb +1 -3
- data/tests/requests/compute/current_time_tests.rb +2 -4
- data/tests/requests/compute/folder_destroy_tests.rb +5 -7
- data/tests/requests/compute/get_network_tests.rb +20 -23
- data/tests/requests/compute/list_child_snapshots_tests.rb +1 -2
- data/tests/requests/compute/list_clusters_tests.rb +5 -6
- data/tests/requests/compute/list_datastores_tests.rb +6 -7
- data/tests/requests/compute/list_hosts_tests.rb +3 -4
- data/tests/requests/compute/list_networks_tests.rb +6 -7
- data/tests/requests/compute/list_storage_pods_test.rb +3 -4
- data/tests/requests/compute/list_virtual_machines_tests.rb +16 -20
- data/tests/requests/compute/list_vm_cdroms_tests.rb +1 -2
- data/tests/requests/compute/list_vm_snapshots_tests.rb +1 -2
- data/tests/requests/compute/modify_vm_cdrom_tests.rb +3 -4
- data/tests/requests/compute/revert_to_snapshot_tests.rb +2 -4
- data/tests/requests/compute/set_vm_customvalue_tests.rb +0 -2
- data/tests/requests/compute/update_vm_tests.rb +13 -0
- data/tests/requests/compute/vm_clone_tests.rb +20 -20
- data/tests/requests/compute/vm_config_vnc_tests.rb +3 -4
- data/tests/requests/compute/vm_destroy_tests.rb +1 -4
- data/tests/requests/compute/vm_migrate_tests.rb +1 -2
- data/tests/requests/compute/vm_power_off_tests.rb +2 -4
- data/tests/requests/compute/vm_power_on_tests.rb +1 -3
- data/tests/requests/compute/vm_reboot_tests.rb +2 -4
- data/tests/requests/compute/vm_reconfig_cdrom_tests.rb +2 -3
- data/tests/requests/compute/vm_reconfig_cpus_tests.rb +1 -3
- data/tests/requests/compute/vm_reconfig_hardware_tests.rb +2 -4
- data/tests/requests/compute/vm_reconfig_memory_tests.rb +1 -3
- data/tests/requests/compute/vm_take_snapshot_tests.rb +1 -3
- metadata +9 -4
@@ -5,8 +5,8 @@ module Fog
|
|
5
5
|
def folder_destroy(path, datacenter_name)
|
6
6
|
folder = get_raw_vmfolder(path, datacenter_name)
|
7
7
|
raise Fog::Vsphere::Errors::NotFound, "No such folder #{path}" unless folder
|
8
|
-
raise Fog::Vsphere::Errors::ServiceError, "Folder #{path} is not empty"
|
9
|
-
|
8
|
+
raise Fog::Vsphere::Errors::ServiceError, "Folder #{path} is not empty" unless folder.childEntity.empty?
|
9
|
+
|
10
10
|
task = folder.Destroy_Task
|
11
11
|
task.wait_for_completion
|
12
12
|
{ 'task_state' => task.info.state }
|
@@ -15,7 +15,7 @@ module Fog
|
|
15
15
|
class Mock
|
16
16
|
def folder_destroy(path, datacenter_name)
|
17
17
|
vms = list_virtual_machines(folder: path, datacenter: datacenter_name)
|
18
|
-
|
18
|
+
unless vms.empty?
|
19
19
|
raise Fog::Vsphere::Errors::ServiceError, "Folder #{path} is not empty"
|
20
20
|
end
|
21
21
|
{ 'task_state' => 'success' }
|
@@ -18,8 +18,8 @@ module Fog
|
|
18
18
|
|
19
19
|
class Mock
|
20
20
|
def get_cluster(name, datacenter_name)
|
21
|
-
|
22
|
-
raise
|
21
|
+
data[:clusters].find { |c| c[:name] == name && c[:datacenter] == datacenter_name } ||
|
22
|
+
raise(Fog::Compute::Vsphere::NotFound)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -16,23 +16,23 @@ module Fog
|
|
16
16
|
end
|
17
17
|
|
18
18
|
class Mock
|
19
|
-
def get_compute_resource(
|
19
|
+
def get_compute_resource(_name, _datacenter_name)
|
20
20
|
{
|
21
|
-
:
|
22
|
-
:
|
23
|
-
:
|
24
|
-
:
|
25
|
-
:
|
26
|
-
:
|
27
|
-
:
|
28
|
-
:
|
29
|
-
:
|
30
|
-
:
|
31
|
-
:
|
32
|
-
:
|
33
|
-
:
|
34
|
-
:
|
35
|
-
:
|
21
|
+
id: 'domain-s7',
|
22
|
+
name: 'fake-host',
|
23
|
+
totalCpu: 33_504,
|
24
|
+
totalMemory: 154_604_142_592,
|
25
|
+
numCpuCores: 12,
|
26
|
+
numCpuThreads: 24,
|
27
|
+
effectiveCpu: 32_247,
|
28
|
+
effectiveMemory: 135_733,
|
29
|
+
numHosts: 1,
|
30
|
+
numEffectiveHosts: 1,
|
31
|
+
overallStatus: 'gray',
|
32
|
+
overallCpuUsage: 15_682,
|
33
|
+
overallMemoryUsage: 132_755,
|
34
|
+
effective: true,
|
35
|
+
isSingleHost: true
|
36
36
|
}
|
37
37
|
end
|
38
38
|
end
|
@@ -2,26 +2,26 @@ module Fog
|
|
2
2
|
module Compute
|
3
3
|
class Vsphere
|
4
4
|
class Real
|
5
|
-
def get_datacenter
|
5
|
+
def get_datacenter(name)
|
6
6
|
dc = find_raw_datacenter(name)
|
7
7
|
raise(Fog::Compute::Vsphere::NotFound) unless dc
|
8
|
-
{:
|
8
|
+
{ name: dc.name, status: dc.overallStatus, path: raw_getpathmo(dc) }
|
9
9
|
end
|
10
10
|
|
11
11
|
protected
|
12
12
|
|
13
|
-
def find_raw_datacenter
|
14
|
-
raw_datacenters.find {|d| d.name == name} || get_raw_datacenter(name)
|
13
|
+
def find_raw_datacenter(name)
|
14
|
+
raw_datacenters.find { |d| d.name == name } || get_raw_datacenter(name)
|
15
15
|
end
|
16
16
|
|
17
|
-
def get_raw_datacenter
|
17
|
+
def get_raw_datacenter(name)
|
18
18
|
connection.serviceInstance.find_datacenter(name)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
class Mock
|
23
|
-
def get_datacenter
|
24
|
-
dc =
|
23
|
+
def get_datacenter(name)
|
24
|
+
dc = data[:datacenters][name]
|
25
25
|
raise(Fog::Compute::Vsphere::NotFound) unless dc
|
26
26
|
dc
|
27
27
|
end
|
@@ -7,17 +7,17 @@ module Fog
|
|
7
7
|
|
8
8
|
# Cycle through all types of folders.
|
9
9
|
case type
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
10
|
+
when 'vm', :vm
|
11
|
+
# if you're a vm then grab the VM.
|
12
|
+
folder = get_raw_vmfolder(path, datacenter_name)
|
13
|
+
raise(Fog::Compute::Vsphere::NotFound) unless folder
|
14
|
+
folder_attributes(folder, datacenter_name)
|
15
|
+
when 'network', :network
|
16
|
+
raise 'not implemented'
|
17
|
+
when 'datastore', :datastore
|
18
|
+
raise 'not implemented'
|
19
|
+
else
|
20
|
+
raise ArgumentError, "#{type} is unknown"
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -30,8 +30,8 @@ module Fog
|
|
30
30
|
dc = find_raw_datacenter(datacenter_name)
|
31
31
|
dc_root_folder = dc.vmFolder
|
32
32
|
# Filter the root path for this datacenter not to be used."
|
33
|
-
dc_root_folder_path=dc_root_folder.path.map { |
|
34
|
-
paths
|
33
|
+
dc_root_folder_path = dc_root_folder.path.map { |_id, name| name }.join('/')
|
34
|
+
paths = path.sub(/^\/?#{Regexp.quote(dc_root_folder_path)}\/?/, '').split('/')
|
35
35
|
|
36
36
|
return dc_root_folder if paths.empty?
|
37
37
|
# Walk the tree resetting the folder pointer as we go
|
@@ -48,17 +48,17 @@ module Fog
|
|
48
48
|
|
49
49
|
def folder_attributes(folder, datacenter_name)
|
50
50
|
{
|
51
|
-
:
|
52
|
-
:
|
53
|
-
:
|
54
|
-
:
|
55
|
-
:
|
56
|
-
:
|
51
|
+
id: managed_obj_id(folder),
|
52
|
+
name: folder.name,
|
53
|
+
parent: folder.parent.name,
|
54
|
+
datacenter: datacenter_name,
|
55
|
+
type: folder_type(folder),
|
56
|
+
path: folder_path(folder)
|
57
57
|
}
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
def folder_path(folder)
|
61
|
-
|
61
|
+
'/' + folder.path.map(&:last).join('/')
|
62
62
|
end
|
63
63
|
|
64
64
|
def folder_type(folder)
|
@@ -70,9 +70,9 @@ module Fog
|
|
70
70
|
end
|
71
71
|
|
72
72
|
class Mock
|
73
|
-
def get_folder(path, datacenter_name,
|
74
|
-
|
75
|
-
raise
|
73
|
+
def get_folder(path, datacenter_name, _type = nil)
|
74
|
+
data[:folders].values.find { |f| (f['datacenter'] == datacenter_name) && f['path'].end_with?(path) } ||
|
75
|
+
raise(Fog::Compute::Vsphere::NotFound)
|
76
76
|
end
|
77
77
|
end
|
78
78
|
end
|
@@ -2,7 +2,6 @@ module Fog
|
|
2
2
|
module Compute
|
3
3
|
class Vsphere
|
4
4
|
class Real
|
5
|
-
|
6
5
|
def get_host(name, cluster_name, datacenter_name)
|
7
6
|
get_raw_host(name, cluster_name, datacenter_name)
|
8
7
|
end
|
@@ -11,8 +10,8 @@ module Fog
|
|
11
10
|
|
12
11
|
def get_raw_host(name, cluster_name, datacenter_name)
|
13
12
|
cluster = get_raw_cluster(cluster_name, datacenter_name)
|
14
|
-
cluster.host.find { |host| host.name == name }
|
15
|
-
|
13
|
+
cluster.host.find { |host| host.name == name } ||
|
14
|
+
raise(Fog::Compute::Vsphere::NotFound, "no such host #{name}")
|
16
15
|
end
|
17
16
|
end
|
18
17
|
end
|
@@ -2,12 +2,12 @@ module Fog
|
|
2
2
|
module Compute
|
3
3
|
class Vsphere
|
4
4
|
class Real
|
5
|
-
def get_interface_type(id, servertype, datacenter,
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
def get_interface_type(id, servertype, datacenter, _filter = {})
|
6
|
+
interfacetype = list_interface_types(filters = { id: id,
|
7
|
+
datacenter: datacenter,
|
8
|
+
servertype: servertype.id }).first
|
9
|
+
raise(Fog::Compute::Vsphere::NotFound) unless interfacetype
|
10
|
+
interfacetype
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
@@ -10,14 +10,13 @@ module Fog
|
|
10
10
|
|
11
11
|
protected
|
12
12
|
|
13
|
-
def get_raw_network(name, datacenter_name, distributedswitch=nil)
|
13
|
+
def get_raw_network(name, datacenter_name, distributedswitch = nil)
|
14
14
|
finder = choose_finder(name, distributedswitch)
|
15
15
|
get_all_raw_networks(datacenter_name).find { |n| finder.call(n) }
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
module Shared
|
20
|
-
|
21
20
|
protected
|
22
21
|
|
23
22
|
def get_all_raw_networks(datacenter_name)
|
@@ -28,24 +27,22 @@ module Fog
|
|
28
27
|
case distributedswitch
|
29
28
|
when String
|
30
29
|
# only the one will do
|
31
|
-
|
32
|
-
|
30
|
+
proc do |n|
|
31
|
+
n.is_a?(RbVmomi::VIM::DistributedVirtualPortgroup) && (n.name == name || n.key == name) &&
|
33
32
|
(n.config.distributedVirtualSwitch.name == distributedswitch)
|
34
|
-
|
33
|
+
end
|
35
34
|
when :dvs
|
36
35
|
# the first distributed virtual switch will do - selected by network - gives control to vsphere
|
37
|
-
|
36
|
+
proc { |n| (n.name == name || n.key == name) && (n.class.to_s == 'DistributedVirtualPortgroup') }
|
38
37
|
else
|
39
38
|
# the first matching network will do, seems like the non-distributed networks come first
|
40
|
-
|
39
|
+
proc { |n| (n.name == name || (n.is_a?(RbVmomi::VIM::DistributedVirtualPortgroup) && n.key == name)) }
|
41
40
|
end
|
42
41
|
end
|
43
|
-
|
44
42
|
end
|
45
43
|
|
46
44
|
class Mock
|
47
|
-
def get_network(id)
|
48
|
-
end
|
45
|
+
def get_network(id); end
|
49
46
|
end
|
50
47
|
end
|
51
48
|
end
|
@@ -2,29 +2,29 @@ module Fog
|
|
2
2
|
module Compute
|
3
3
|
class Vsphere
|
4
4
|
class Real
|
5
|
-
def get_server_type(id, datacenter,
|
6
|
-
server_type=get_raw_server_type(id, datacenter)
|
5
|
+
def get_server_type(id, datacenter, _filter = {})
|
6
|
+
server_type = get_raw_server_type(id, datacenter)
|
7
7
|
raise(Fog::Compute::Vsphere::NotFound) unless server_type
|
8
8
|
server_type_attributes(server_type, datacenter)
|
9
9
|
end
|
10
10
|
|
11
11
|
protected
|
12
12
|
|
13
|
-
def get_raw_server_type(id, datacenter,
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
def get_raw_server_type(id, datacenter, _filter = {})
|
14
|
+
types = raw_server_types(datacenter)
|
15
|
+
raise(Fog::Compute::Vsphere::NotFound) unless types
|
16
|
+
types = types.select { |servertype| servertype.id == id }.first
|
17
|
+
raise(Fog::Compute::Vsphere::NotFound) unless types
|
18
|
+
types
|
19
19
|
end
|
20
20
|
end
|
21
21
|
class Mock
|
22
|
-
def get_server_type(
|
23
|
-
{:
|
24
|
-
:
|
25
|
-
:
|
26
|
-
:
|
27
|
-
:
|
22
|
+
def get_server_type(_id)
|
23
|
+
{ id: 'rhel6Guest',
|
24
|
+
name: 'rhel6Guest',
|
25
|
+
family: 'linuxGuest',
|
26
|
+
fullname: 'Red Hat Enterprise Linux 6 (32-Bit)',
|
27
|
+
datacenter: 'Solutions' }
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -11,13 +11,13 @@ module Fog
|
|
11
11
|
protected
|
12
12
|
|
13
13
|
def get_raw_storage_pod(name, datacenter_name)
|
14
|
-
raw_storage_pods(datacenter_name).detect { |pod| pod.name == name}
|
14
|
+
raw_storage_pods(datacenter_name).detect { |pod| pod.name == name }
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
class Mock
|
19
19
|
def get_storage_pod(name, datacenter_name)
|
20
|
-
list_storage_pods(
|
20
|
+
list_storage_pods(datacenter: datacenter_name).detect { |h| h[:name] == name }
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -13,36 +13,36 @@ module Fog
|
|
13
13
|
raw_datacenter = find_raw_datacenter(dc) if dc
|
14
14
|
vm = case is_uuid?(id)
|
15
15
|
# UUID based
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
when true
|
17
|
+
params = { uuid: id, vmSearch: true, instanceUuid: true }
|
18
|
+
params[:datacenter] = raw_datacenter if dc
|
19
|
+
connection.searchIndex.FindByUuid(params)
|
20
|
+
else
|
21
|
+
# try to find based on VM name
|
22
|
+
if dc
|
23
|
+
get_vm_by_name(id, dc, folder, recursive)
|
20
24
|
else
|
21
|
-
|
22
|
-
|
23
|
-
get_vm_by_name(id, dc, folder, recursive)
|
24
|
-
else
|
25
|
-
raw_datacenters.map { |d| get_vm_by_name(id, d["name"], folder, recursive)}.compact.first
|
26
|
-
end
|
25
|
+
raw_datacenters.map { |d| get_vm_by_name(id, d['name'], folder, recursive) }.compact.first
|
26
|
+
end
|
27
27
|
end
|
28
28
|
vm ? vm : raise(Fog::Compute::Vsphere::NotFound, "#{id} was not found")
|
29
29
|
end
|
30
30
|
|
31
31
|
def get_vm_by_name(name, dc, folder, recursive)
|
32
|
-
if folder
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
32
|
+
vms = if folder
|
33
|
+
# This returns an Enumerator, which when called with .find will
|
34
|
+
# search only until it finds the VM we're looking for
|
35
|
+
raw_list_all_virtual_machines_in_folder(folder, dc, recursive)
|
36
|
+
else
|
37
|
+
raw_list_all_virtual_machines(dc)
|
38
|
+
end
|
39
39
|
|
40
40
|
if name.include?('/')
|
41
41
|
folder = File.dirname(name)
|
42
42
|
basename = File.basename(name)
|
43
43
|
vms.find do |v|
|
44
44
|
begin
|
45
|
-
v[
|
45
|
+
v['name'] == basename && v.parent.pretty_path.include?(folder)
|
46
46
|
rescue RbVmomi::VIM::ManagedObjectNotFound
|
47
47
|
false
|
48
48
|
end
|
@@ -50,7 +50,7 @@ module Fog
|
|
50
50
|
else
|
51
51
|
vms.find do |v|
|
52
52
|
begin
|
53
|
-
v[
|
53
|
+
v['name'] == name
|
54
54
|
rescue RbVmomi::VIM::ManagedObjectNotFound
|
55
55
|
false
|
56
56
|
end
|
@@ -60,13 +60,13 @@ module Fog
|
|
60
60
|
end
|
61
61
|
|
62
62
|
class Mock
|
63
|
-
def get_virtual_machine(id, datacenter_name = nil,
|
64
|
-
if is_uuid?(id)
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
63
|
+
def get_virtual_machine(id, datacenter_name = nil, _folder = nil, _recursive = false)
|
64
|
+
vm = if is_uuid?(id)
|
65
|
+
list_virtual_machines('instance_uuid' => id, 'datacenter' => datacenter_name).first
|
66
|
+
else
|
67
|
+
# try to find based on VM name. May need to handle the path of the VM
|
68
|
+
list_virtual_machines('name' => id, 'datacenter' => datacenter_name).first
|
69
|
+
end
|
70
70
|
vm ? vm : raise(Fog::Compute::Vsphere::NotFound, "#{id} was not found")
|
71
71
|
end
|
72
72
|
end
|