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.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +8 -0
  3. data/.rubocop_todo.yml +217 -0
  4. data/.travis.yml +1 -0
  5. data/CHANGELOG.md +4 -0
  6. data/Rakefile +10 -1
  7. data/fog-vsphere.gemspec +2 -2
  8. data/lib/fog/bin/vsphere.rb +1 -1
  9. data/lib/fog/vsphere/compute.rb +320 -301
  10. data/lib/fog/vsphere/models/compute/cdrom.rb +10 -10
  11. data/lib/fog/vsphere/models/compute/cdroms.rb +2 -2
  12. data/lib/fog/vsphere/models/compute/cluster.rb +20 -20
  13. data/lib/fog/vsphere/models/compute/clusters.rb +1 -1
  14. data/lib/fog/vsphere/models/compute/customfields.rb +4 -4
  15. data/lib/fog/vsphere/models/compute/customvalues.rb +8 -8
  16. data/lib/fog/vsphere/models/compute/datacenter.rb +16 -16
  17. data/lib/fog/vsphere/models/compute/datastores.rb +1 -1
  18. data/lib/fog/vsphere/models/compute/folder.rb +2 -2
  19. data/lib/fog/vsphere/models/compute/folders.rb +2 -2
  20. data/lib/fog/vsphere/models/compute/hosts.rb +4 -4
  21. data/lib/fog/vsphere/models/compute/interface.rb +12 -12
  22. data/lib/fog/vsphere/models/compute/interfaces.rb +14 -16
  23. data/lib/fog/vsphere/models/compute/interfacetype.rb +2 -2
  24. data/lib/fog/vsphere/models/compute/interfacetypes.rb +6 -8
  25. data/lib/fog/vsphere/models/compute/networks.rb +1 -1
  26. data/lib/fog/vsphere/models/compute/resource_pools.rb +1 -1
  27. data/lib/fog/vsphere/models/compute/rule.rb +8 -9
  28. data/lib/fog/vsphere/models/compute/rules.rb +9 -10
  29. data/lib/fog/vsphere/models/compute/scsicontroller.rb +1 -1
  30. data/lib/fog/vsphere/models/compute/server.rb +68 -80
  31. data/lib/fog/vsphere/models/compute/servers.rb +12 -13
  32. data/lib/fog/vsphere/models/compute/servertype.rb +6 -6
  33. data/lib/fog/vsphere/models/compute/servertypes.rb +2 -2
  34. data/lib/fog/vsphere/models/compute/snapshot.rb +5 -6
  35. data/lib/fog/vsphere/models/compute/snapshots.rb +1 -1
  36. data/lib/fog/vsphere/models/compute/ticket.rb +0 -1
  37. data/lib/fog/vsphere/models/compute/volume.rb +12 -14
  38. data/lib/fog/vsphere/models/compute/volumes.rb +10 -10
  39. data/lib/fog/vsphere/requests/compute/cloudinit_to_customspec.rb +8 -8
  40. data/lib/fog/vsphere/requests/compute/create_folder.rb +5 -5
  41. data/lib/fog/vsphere/requests/compute/create_group.rb +16 -16
  42. data/lib/fog/vsphere/requests/compute/create_rule.rb +13 -13
  43. data/lib/fog/vsphere/requests/compute/create_vm.rb +117 -119
  44. data/lib/fog/vsphere/requests/compute/destroy_group.rb +8 -8
  45. data/lib/fog/vsphere/requests/compute/destroy_rule.rb +8 -8
  46. data/lib/fog/vsphere/requests/compute/folder_destroy.rb +3 -3
  47. data/lib/fog/vsphere/requests/compute/get_cluster.rb +2 -2
  48. data/lib/fog/vsphere/requests/compute/get_compute_resource.rb +16 -16
  49. data/lib/fog/vsphere/requests/compute/get_datacenter.rb +7 -7
  50. data/lib/fog/vsphere/requests/compute/get_datastore.rb +1 -2
  51. data/lib/fog/vsphere/requests/compute/get_folder.rb +24 -24
  52. data/lib/fog/vsphere/requests/compute/get_host.rb +2 -3
  53. data/lib/fog/vsphere/requests/compute/get_interface_type.rb +6 -6
  54. data/lib/fog/vsphere/requests/compute/get_network.rb +7 -10
  55. data/lib/fog/vsphere/requests/compute/get_resource_pool.rb +1 -2
  56. data/lib/fog/vsphere/requests/compute/get_server_type.rb +14 -14
  57. data/lib/fog/vsphere/requests/compute/get_storage_pod.rb +2 -2
  58. data/lib/fog/vsphere/requests/compute/get_template.rb +1 -2
  59. data/lib/fog/vsphere/requests/compute/get_virtual_machine.rb +26 -26
  60. data/lib/fog/vsphere/requests/compute/get_vm_first_scsi_controller.rb +6 -7
  61. data/lib/fog/vsphere/requests/compute/host_finish_maintenance.rb +1 -1
  62. data/lib/fog/vsphere/requests/compute/host_shutdown.rb +1 -1
  63. data/lib/fog/vsphere/requests/compute/host_start_maintenance.rb +1 -1
  64. data/lib/fog/vsphere/requests/compute/list_child_snapshots.rb +37 -39
  65. data/lib/fog/vsphere/requests/compute/list_clusters.rb +8 -9
  66. data/lib/fog/vsphere/requests/compute/list_compute_resources.rb +57 -59
  67. data/lib/fog/vsphere/requests/compute/list_customfields.rb +5 -6
  68. data/lib/fog/vsphere/requests/compute/list_datacenters.rb +17 -17
  69. data/lib/fog/vsphere/requests/compute/list_datastores.rb +16 -15
  70. data/lib/fog/vsphere/requests/compute/list_folders.rb +4 -4
  71. data/lib/fog/vsphere/requests/compute/list_groups.rb +5 -5
  72. data/lib/fog/vsphere/requests/compute/list_hosts.rb +30 -14
  73. data/lib/fog/vsphere/requests/compute/list_interface_types.rb +7 -7
  74. data/lib/fog/vsphere/requests/compute/list_networks.rb +12 -16
  75. data/lib/fog/vsphere/requests/compute/list_processes.rb +14 -14
  76. data/lib/fog/vsphere/requests/compute/list_resource_pools.rb +13 -14
  77. data/lib/fog/vsphere/requests/compute/list_rules.rb +4 -4
  78. data/lib/fog/vsphere/requests/compute/list_server_types.rb +24 -26
  79. data/lib/fog/vsphere/requests/compute/list_storage_pods.rb +8 -8
  80. data/lib/fog/vsphere/requests/compute/list_templates.rb +4 -5
  81. data/lib/fog/vsphere/requests/compute/list_virtual_machines.rb +15 -15
  82. data/lib/fog/vsphere/requests/compute/list_vm_cdroms.rb +16 -12
  83. data/lib/fog/vsphere/requests/compute/list_vm_customvalues.rb +3 -4
  84. data/lib/fog/vsphere/requests/compute/list_vm_interfaces.rb +54 -56
  85. data/lib/fog/vsphere/requests/compute/list_vm_scsi_controllers.rb +7 -7
  86. data/lib/fog/vsphere/requests/compute/list_vm_snapshots.rb +36 -36
  87. data/lib/fog/vsphere/requests/compute/list_vm_volumes.rb +43 -36
  88. data/lib/fog/vsphere/requests/compute/modify_vm_cdrom.rb +4 -4
  89. data/lib/fog/vsphere/requests/compute/modify_vm_controller.rb +2 -2
  90. data/lib/fog/vsphere/requests/compute/modify_vm_interface.rb +26 -19
  91. data/lib/fog/vsphere/requests/compute/modify_vm_volume.rb +7 -7
  92. data/lib/fog/vsphere/requests/compute/revert_to_snapshot.rb +2 -2
  93. data/lib/fog/vsphere/requests/compute/set_vm_customvalue.rb +2 -2
  94. data/lib/fog/vsphere/requests/compute/update_vm.rb +111 -0
  95. data/lib/fog/vsphere/requests/compute/upload_iso.rb +10 -10
  96. data/lib/fog/vsphere/requests/compute/vm_acquire_ticket.rb +3 -3
  97. data/lib/fog/vsphere/requests/compute/vm_clone.rb +245 -247
  98. data/lib/fog/vsphere/requests/compute/vm_config_vnc.rb +15 -15
  99. data/lib/fog/vsphere/requests/compute/vm_destroy.rb +2 -2
  100. data/lib/fog/vsphere/requests/compute/vm_execute.rb +16 -16
  101. data/lib/fog/vsphere/requests/compute/vm_migrate.rb +11 -11
  102. data/lib/fog/vsphere/requests/compute/vm_power_off.rb +8 -8
  103. data/lib/fog/vsphere/requests/compute/vm_power_on.rb +2 -2
  104. data/lib/fog/vsphere/requests/compute/vm_reboot.rb +5 -5
  105. data/lib/fog/vsphere/requests/compute/vm_reconfig_cdrom.rb +11 -11
  106. data/lib/fog/vsphere/requests/compute/vm_reconfig_cpus.rb +8 -8
  107. data/lib/fog/vsphere/requests/compute/vm_reconfig_hardware.rb +6 -6
  108. data/lib/fog/vsphere/requests/compute/vm_reconfig_memory.rb +8 -8
  109. data/lib/fog/vsphere/requests/compute/vm_reconfig_volumes.rb +14 -16
  110. data/lib/fog/vsphere/requests/compute/vm_relocate.rb +8 -8
  111. data/lib/fog/vsphere/requests/compute/vm_remove_snapshot.rb +2 -2
  112. data/lib/fog/vsphere/requests/compute/vm_rename.rb +5 -5
  113. data/lib/fog/vsphere/requests/compute/vm_revert_snapshot.rb +1 -1
  114. data/lib/fog/vsphere/requests/compute/vm_take_snapshot.rb +8 -8
  115. data/lib/fog/vsphere/version.rb +1 -1
  116. data/tests/compute_tests.rb +16 -17
  117. data/tests/helpers/mock_helper.rb +3 -3
  118. data/tests/models/compute/cluster_tests.rb +4 -5
  119. data/tests/models/compute/hosts_tests.rb +2 -4
  120. data/tests/models/compute/rules_tests.rb +10 -16
  121. data/tests/models/compute/server_tests.rb +30 -31
  122. data/tests/models/compute/servers_tests.rb +2 -4
  123. data/tests/models/compute/ticket_tests.rb +4 -6
  124. data/tests/models/compute/tickets_tests.rb +1 -3
  125. data/tests/requests/compute/current_time_tests.rb +2 -4
  126. data/tests/requests/compute/folder_destroy_tests.rb +5 -7
  127. data/tests/requests/compute/get_network_tests.rb +20 -23
  128. data/tests/requests/compute/list_child_snapshots_tests.rb +1 -2
  129. data/tests/requests/compute/list_clusters_tests.rb +5 -6
  130. data/tests/requests/compute/list_datastores_tests.rb +6 -7
  131. data/tests/requests/compute/list_hosts_tests.rb +3 -4
  132. data/tests/requests/compute/list_networks_tests.rb +6 -7
  133. data/tests/requests/compute/list_storage_pods_test.rb +3 -4
  134. data/tests/requests/compute/list_virtual_machines_tests.rb +16 -20
  135. data/tests/requests/compute/list_vm_cdroms_tests.rb +1 -2
  136. data/tests/requests/compute/list_vm_snapshots_tests.rb +1 -2
  137. data/tests/requests/compute/modify_vm_cdrom_tests.rb +3 -4
  138. data/tests/requests/compute/revert_to_snapshot_tests.rb +2 -4
  139. data/tests/requests/compute/set_vm_customvalue_tests.rb +0 -2
  140. data/tests/requests/compute/update_vm_tests.rb +13 -0
  141. data/tests/requests/compute/vm_clone_tests.rb +20 -20
  142. data/tests/requests/compute/vm_config_vnc_tests.rb +3 -4
  143. data/tests/requests/compute/vm_destroy_tests.rb +1 -4
  144. data/tests/requests/compute/vm_migrate_tests.rb +1 -2
  145. data/tests/requests/compute/vm_power_off_tests.rb +2 -4
  146. data/tests/requests/compute/vm_power_on_tests.rb +1 -3
  147. data/tests/requests/compute/vm_reboot_tests.rb +2 -4
  148. data/tests/requests/compute/vm_reconfig_cdrom_tests.rb +2 -3
  149. data/tests/requests/compute/vm_reconfig_cpus_tests.rb +1 -3
  150. data/tests/requests/compute/vm_reconfig_hardware_tests.rb +2 -4
  151. data/tests/requests/compute/vm_reconfig_memory_tests.rb +1 -3
  152. data/tests/requests/compute/vm_take_snapshot_tests.rb +1 -3
  153. 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" if folder.childEntity.size > 0
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
- if vms.length > 0
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
- self.data[:clusters].find {|c| c[:name] == name && c[:datacenter] == datacenter_name} or
22
- raise Fog::Compute::Vsphere::NotFound
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(name, datacenter_name)
19
+ def get_compute_resource(_name, _datacenter_name)
20
20
  {
21
- :id=>"domain-s7",
22
- :name=>"fake-host",
23
- :totalCpu=>33504,
24
- :totalMemory=>154604142592,
25
- :numCpuCores=>12,
26
- :numCpuThreads=>24,
27
- :effectiveCpu=>32247,
28
- :effectiveMemory=>135733,
29
- :numHosts=>1,
30
- :numEffectiveHosts=>1,
31
- :overallStatus=>"gray",
32
- :overallCpuUsage=>15682,
33
- :overallMemoryUsage=>132755,
34
- :effective=>true,
35
- :isSingleHost=>true
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 name
5
+ def get_datacenter(name)
6
6
  dc = find_raw_datacenter(name)
7
7
  raise(Fog::Compute::Vsphere::NotFound) unless dc
8
- {:name => dc.name, :status => dc.overallStatus, :path => raw_getpathmo(dc) }
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 name
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 name
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 name
24
- dc = self.data[:datacenters][name]
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
@@ -20,8 +20,7 @@ module Fog
20
20
  end
21
21
 
22
22
  class Mock
23
- def get_datastore(name, datacenter_name)
24
- end
23
+ def get_datastore(name, datacenter_name); end
25
24
  end
26
25
  end
27
26
  end
@@ -7,17 +7,17 @@ module Fog
7
7
 
8
8
  # Cycle through all types of folders.
9
9
  case type
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"
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 { | id, name | name }.join("/")
34
- paths = path.sub(/^\/?#{Regexp.quote(dc_root_folder_path)}\/?/, '').split('/')
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
- :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),
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
- "/"+folder.path.map(&:last).join('/')
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, type = nil)
74
- self.data[:folders].values.find {|f| f['datacenter'] == datacenter_name and f['path'].end_with? path} or
75
- raise Fog::Compute::Vsphere::NotFound
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 } or
15
- raise Fog::Compute::Vsphere::NotFound, "no such host #{name}"
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, 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
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
- Proc.new { |n| (n.name == name) &&
32
- (n.class.to_s == "DistributedVirtualPortgroup") &&
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
- Proc.new { |n| (n.name == name) && (n.class.to_s == "DistributedVirtualPortgroup") }
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
- Proc.new { |n| (n.name == name) }
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
@@ -18,8 +18,7 @@ module Fog
18
18
  end
19
19
 
20
20
  class Mock
21
- def get_resource_pool(name, cluster_name, datacenter_name)
22
- end
21
+ def get_resource_pool(name, cluster_name, datacenter_name); end
23
22
  end
24
23
  end
25
24
  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, filter={})
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, 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
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(id)
23
- {:id=>"rhel6Guest",
24
- :name=>"rhel6Guest",
25
- :family=>"linuxGuest",
26
- :fullname=>"Red Hat Enterprise Linux 6 (32-Bit)",
27
- :datacenter=>"Solutions"}
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({datacenter: datacenter_name}).detect { |h| h[:name] == name }
20
+ list_storage_pods(datacenter: datacenter_name).detect { |h| h[:name] == name }
21
21
  end
22
22
  end
23
23
  end
@@ -8,8 +8,7 @@ module Fog
8
8
  end
9
9
 
10
10
  class Mock
11
- def get_template(id, datacenter_name = nil)
12
- end
11
+ def get_template(id, datacenter_name = nil); end
13
12
  end
14
13
  end
15
14
  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
- when true
17
- params = {:uuid => id, :vmSearch => true, :instanceUuid => true}
18
- params[:datacenter] = raw_datacenter if dc
19
- connection.searchIndex.FindByUuid(params)
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
- # try to find based on VM name
22
- if dc
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
- # This returns an Enumerator, which when called with .find will
34
- # search only until it finds the VM we're looking for
35
- vms = raw_list_all_virtual_machines_in_folder(folder, dc, recursive)
36
- else
37
- vms = raw_list_all_virtual_machines(dc)
38
- end
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["name"] == basename && v.parent.pretty_path.include?(folder)
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["name"] == name
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, folder = nil, recursive = false)
64
- if is_uuid?(id)
65
- vm = 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
- vm = list_virtual_machines({ 'name' => id, 'datacenter' => datacenter_name }).first
69
- end
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