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
@@ -8,18 +8,17 @@ module Fog
8
8
  end
9
9
 
10
10
  def get_vm_first_scsi_controller_raw(vm_id)
11
- ctrl=get_vm_ref(vm_id).config.hardware.device.grep(RbVmomi::VIM::VirtualSCSIController).select{ | ctrl | ctrl.key == 1000 }.first
11
+ ctrl = get_vm_ref(vm_id).config.hardware.device.grep(RbVmomi::VIM::VirtualSCSIController).select { |ctrl| ctrl.key == 1000 }.first
12
12
  {
13
- :type => ctrl.class.to_s,
14
- :shared_bus => ctrl.sharedBus.to_s,
15
- :unit_number => ctrl.scsiCtlrUnitNumber,
16
- :key => ctrl.key,
13
+ type: ctrl.class.to_s,
14
+ shared_bus: ctrl.sharedBus.to_s,
15
+ unit_number: ctrl.scsiCtlrUnitNumber,
16
+ key: ctrl.key
17
17
  }
18
18
  end
19
19
  end
20
20
  class Mock
21
- def get_vm_first_scsi_controller(vm_id)
22
- end
21
+ def get_vm_first_scsi_controller(vm_id); end
23
22
  end
24
23
  end
25
24
  end
@@ -4,7 +4,7 @@ module Fog
4
4
  class Real
5
5
  def host_finish_maintenance(name, cluster_name, datacenter_name, timeout = 0)
6
6
  host_ref = get_host(name, cluster_name, datacenter_name)
7
- task = host_ref.ExitMaintenanceMode_Task(:timeout => timeout)
7
+ task = host_ref.ExitMaintenanceMode_Task(timeout: timeout)
8
8
  task.wait_for_completion
9
9
  { 'task_state' => task.info.state }
10
10
  end
@@ -4,7 +4,7 @@ module Fog
4
4
  class Real
5
5
  def host_shutdown(name, cluster_name, datacenter_name, force = false)
6
6
  host_ref = get_host(name, cluster_name, datacenter_name)
7
- task = host_ref.ShutdownHost_Task(:force => force)
7
+ task = host_ref.ShutdownHost_Task(force: force)
8
8
  task.wait_for_completion
9
9
  { 'task_state' => task.info.state }
10
10
  end
@@ -4,7 +4,7 @@ module Fog
4
4
  class Real
5
5
  def host_start_maintenance(name, cluster_name, datacenter_name, timeout = 0, evacuate_powered_off_vms = false)
6
6
  host_ref = get_host(name, cluster_name, datacenter_name)
7
- task = host_ref.EnterMaintenanceMode_Task(:timeout => timeout, :evacuatePoweredOffVms => evacuate_powered_off_vms)
7
+ task = host_ref.EnterMaintenanceMode_Task(timeout: timeout, evacuatePoweredOffVms: evacuate_powered_off_vms)
8
8
  task.wait_for_completion
9
9
  { 'task_state' => task.info.state }
10
10
  end
@@ -4,7 +4,7 @@ module Fog
4
4
  class Real
5
5
  def list_child_snapshots(snapshot, opts = {})
6
6
  normalized_snapshot = Hash === snapshot ?
7
- Snapshot.new(snapshot.update(:service => self)) : snapshot
7
+ Snapshot.new(snapshot.update(service: self)) : snapshot
8
8
 
9
9
  child_snapshots = normalized_snapshot.tree_node.childSnapshotList.map do |snap|
10
10
  item = child_snapshot_info(snap, normalized_snapshot)
@@ -19,50 +19,48 @@ module Fog
19
19
 
20
20
  protected
21
21
 
22
- def child_snapshot_info(snap_tree, parent_snap)
23
- {
24
- :name => snap_tree.name,
25
- :quiesced => snap_tree.quiesced,
26
- :description => snap_tree.description,
27
- :create_time => snap_tree.createTime,
28
- :power_state => snap_tree.state,
29
- :ref => snap_tree.snapshot._ref,
30
- :mo_ref => snap_tree.snapshot,
31
- :tree_node => snap_tree,
32
- :snapshot_name_chain =>
33
- "#{parent_snap.snapshot_name_chain}/#{snap_tree.name}",
34
- :ref_chain =>
35
- "#{parent_snap.ref_chain}/#{snap_tree.snapshot._ref}",
36
- :server_id => parent_snap.server_id
37
- }
38
- end
22
+ def child_snapshot_info(snap_tree, parent_snap)
23
+ {
24
+ name: snap_tree.name,
25
+ quiesced: snap_tree.quiesced,
26
+ description: snap_tree.description,
27
+ create_time: snap_tree.createTime,
28
+ power_state: snap_tree.state,
29
+ ref: snap_tree.snapshot._ref,
30
+ mo_ref: snap_tree.snapshot,
31
+ tree_node: snap_tree,
32
+ snapshot_name_chain: "#{parent_snap.snapshot_name_chain}/#{snap_tree.name}",
33
+ ref_chain: "#{parent_snap.ref_chain}/#{snap_tree.snapshot._ref}",
34
+ server_id: parent_snap.server_id
35
+ }
36
+ end
39
37
  end
40
38
  class Mock
41
- def list_child_snapshots(snapshot, opts = {})
39
+ def list_child_snapshots(_snapshot, _opts = {})
42
40
  [
43
41
  {
44
- :name => 'clean',
45
- :quiesced => false,
46
- :description => '',
47
- :create_time => Time.now.utc,
48
- :power_state => 'poweredOn',
49
- :ref => 'snapshot-0101',
50
- :mo_ref => nil,
51
- :tree_node => nil,
52
- :snapshot_name_chain => '123/clean',
53
- :ref_chain => '123/snap-0101'
42
+ name: 'clean',
43
+ quiesced: false,
44
+ description: '',
45
+ create_time: Time.now.utc,
46
+ power_state: 'poweredOn',
47
+ ref: 'snapshot-0101',
48
+ mo_ref: nil,
49
+ tree_node: nil,
50
+ snapshot_name_chain: '123/clean',
51
+ ref_chain: '123/snap-0101'
54
52
  },
55
53
  {
56
- :name => 'dirty',
57
- :quiesced => false,
58
- :description => '',
59
- :create_time => Time.now.utc,
60
- :power_state => 'poweredOn',
61
- :ref => 'snapshot-0102',
62
- :mo_ref => nil,
63
- :tree_node => nil,
64
- :snapshot_name_chain => '123/dirty',
65
- :ref_chain => '123/snap-0102'
54
+ name: 'dirty',
55
+ quiesced: false,
56
+ description: '',
57
+ create_time: Time.now.utc,
58
+ power_state: 'poweredOn',
59
+ ref: 'snapshot-0102',
60
+ mo_ref: nil,
61
+ tree_node: nil,
62
+ snapshot_name_chain: '123/dirty',
63
+ ref_chain: '123/snap-0102'
66
64
  }
67
65
  ]
68
66
  end
@@ -2,11 +2,10 @@ module Fog
2
2
  module Compute
3
3
  class Vsphere
4
4
  class Real
5
-
6
5
  def list_clusters(filters = {})
7
6
  datacenter_name = filters[:datacenter] if filters.key? :datacenter
8
7
  if datacenter_name.nil?
9
- list_datacenters.map { |dc| list_clusters(:datacenter => dc[:name]) }.flatten
8
+ list_datacenters.map { |dc| list_clusters(datacenter: dc[:name]) }.flatten
10
9
  else
11
10
  raw_clusters(datacenter_name).map do |cluster|
12
11
  if cluster.instance_of? RbVmomi::VIM::ClusterComputeResource
@@ -35,13 +34,13 @@ module Fog
35
34
 
36
35
  def cluster_attributes(cluster, datacenter_name)
37
36
  {
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,
43
- :overall_status => cluster.summary.overallStatus,
44
- :datacenter => datacenter_name || parent_attribute(cluster.path, :datacenter)[1]
37
+ id: managed_obj_id(cluster),
38
+ name: cluster.name,
39
+ full_path: cluster_path(cluster, datacenter_name),
40
+ num_host: cluster.summary.numHosts,
41
+ num_cpu_cores: cluster.summary.numCpuCores,
42
+ overall_status: cluster.summary.overallStatus,
43
+ datacenter: datacenter_name || parent_attribute(cluster.path, :datacenter)[1]
45
44
  }
46
45
  end
47
46
 
@@ -2,89 +2,87 @@ module Fog
2
2
  module Compute
3
3
  class Vsphere
4
4
  class Real
5
- def list_compute_resources(filters = { })
5
+ def list_compute_resources(filters = {})
6
6
  datacenter_name = filters[:datacenter]
7
7
  # default to show all compute_resources
8
8
  only_active = filters[:effective] || false
9
9
  compute_resources = raw_compute_resources datacenter_name
10
-
10
+
11
11
  compute_resources.map do |compute_resource|
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
12
+ next if compute_resource.instance_of? RbVmomi::VIM::Folder
13
+ summary = compute_resource.summary
14
+ next if only_active && (summary.numEffectiveHosts == 0)
15
+ compute_resource_attributes(compute_resource, datacenter_name)
17
16
  end.compact
18
17
  end
19
-
18
+
20
19
  def raw_compute_resources(datacenter_name)
21
20
  find_raw_datacenter(datacenter_name).find_compute_resource('').children
22
21
  end
23
22
 
24
23
  protected
25
24
 
26
- def compute_resource_attributes compute_resource, datacenter
27
- overall_usage = compute_resource.host.inject({:overallCpuUsage=>0, :overallMemoryUsage=>0}) do |sum, host|
25
+ def compute_resource_attributes(compute_resource, _datacenter)
26
+ overall_usage = compute_resource.host.inject(overallCpuUsage: 0, overallMemoryUsage: 0) do |sum, host|
28
27
  {
29
- :overallCpuUsage => sum[:overallCpuUsage]+(host.summary.quickStats.overallCpuUsage || 0),
30
- :overallMemoryUsage=> sum[:overallMemoryUsage]+(host.summary.quickStats.overallMemoryUsage || 0)
28
+ overallCpuUsage: sum[:overallCpuUsage] + (host.summary.quickStats.overallCpuUsage || 0),
29
+ overallMemoryUsage: sum[:overallMemoryUsage] + (host.summary.quickStats.overallMemoryUsage || 0)
31
30
  }
32
31
  end
33
32
  {
34
- :id => managed_obj_id(compute_resource),
35
- :name => compute_resource.name,
36
- :totalCpu => compute_resource.summary.totalCpu,
37
- :totalMemory => compute_resource.summary.totalMemory,
38
- :numCpuCores => compute_resource.summary.numCpuCores,
39
- :numCpuThreads => compute_resource.summary.numCpuThreads,
40
- :effectiveCpu => compute_resource.summary.effectiveCpu,
41
- :effectiveMemory => compute_resource.summary.effectiveMemory,
42
- :numHosts => compute_resource.summary.numHosts,
43
- :numEffectiveHosts => compute_resource.summary.numEffectiveHosts,
44
- :overallStatus => compute_resource.summary.overallStatus,
45
- :overallCpuUsage => overall_usage[:overallCpuUsage],
46
- :overallMemoryUsage => overall_usage[:overallMemoryUsage],
47
- :effective => compute_resource.summary.numEffectiveHosts > 0,
48
- :isSingleHost => compute_resource.summary.numHosts == 1
33
+ id: managed_obj_id(compute_resource),
34
+ name: compute_resource.name,
35
+ totalCpu: compute_resource.summary.totalCpu,
36
+ totalMemory: compute_resource.summary.totalMemory,
37
+ numCpuCores: compute_resource.summary.numCpuCores,
38
+ numCpuThreads: compute_resource.summary.numCpuThreads,
39
+ effectiveCpu: compute_resource.summary.effectiveCpu,
40
+ effectiveMemory: compute_resource.summary.effectiveMemory,
41
+ numHosts: compute_resource.summary.numHosts,
42
+ numEffectiveHosts: compute_resource.summary.numEffectiveHosts,
43
+ overallStatus: compute_resource.summary.overallStatus,
44
+ overallCpuUsage: overall_usage[:overallCpuUsage],
45
+ overallMemoryUsage: overall_usage[:overallMemoryUsage],
46
+ effective: compute_resource.summary.numEffectiveHosts > 0,
47
+ isSingleHost: compute_resource.summary.numHosts == 1
49
48
  }
50
49
  end
51
-
52
50
  end
53
51
  class Mock
54
- def list_compute_resources(filters = { })
52
+ def list_compute_resources(_filters = {})
55
53
  [
56
54
  {
57
- :id=>"domain-s7",
58
- :name=>"fake-host",
59
- :totalCpu=>33504,
60
- :totalMemory=>154604142592,
61
- :numCpuCores=>12,
62
- :numCpuThreads=>24,
63
- :effectiveCpu=>32247,
64
- :effectiveMemory=>135733,
65
- :numHosts=>1,
66
- :numEffectiveHosts=>1,
67
- :overallStatus=>"gray",
68
- :overallCpuUsage=>15682,
69
- :overallMemoryUsage=>132755,
70
- :effective=>true,
71
- :isSingleHost=>true
55
+ id: 'domain-s7',
56
+ name: 'fake-host',
57
+ totalCpu: 33_504,
58
+ totalMemory: 154_604_142_592,
59
+ numCpuCores: 12,
60
+ numCpuThreads: 24,
61
+ effectiveCpu: 32_247,
62
+ effectiveMemory: 135_733,
63
+ numHosts: 1,
64
+ numEffectiveHosts: 1,
65
+ overallStatus: 'gray',
66
+ overallCpuUsage: 15_682,
67
+ overallMemoryUsage: 132_755,
68
+ effective: true,
69
+ isSingleHost: true
72
70
  }, {
73
- :id=>"domain-s74",
74
- :name=>"fake-cluster",
75
- :totalCpu=>41484,
76
- :totalMemory=>51525996544,
77
- :numCpuCores=>12,
78
- :numCpuThreads=>24,
79
- :effectiveCpu=>37796,
80
- :effectiveMemory=>45115,
81
- :numHosts=>2,
82
- :numEffectiveHosts=>2,
83
- :overallStatus=>"gray",
84
- :overallCpuUsage=>584,
85
- :overallMemoryUsage=>26422,
86
- :effective=>true,
87
- :isSingleHost=>false
71
+ id: 'domain-s74',
72
+ name: 'fake-cluster',
73
+ totalCpu: 41_484,
74
+ totalMemory: 51_525_996_544,
75
+ numCpuCores: 12,
76
+ numCpuThreads: 24,
77
+ effectiveCpu: 37_796,
78
+ effectiveMemory: 45_115,
79
+ numHosts: 2,
80
+ numEffectiveHosts: 2,
81
+ overallStatus: 'gray',
82
+ overallCpuUsage: 584,
83
+ overallMemoryUsage: 26_422,
84
+ effective: true,
85
+ isSingleHost: false
88
86
  }
89
87
  ]
90
88
  end
@@ -2,19 +2,18 @@ module Fog
2
2
  module Compute
3
3
  class Vsphere
4
4
  class Real
5
- def list_customfields()
5
+ def list_customfields
6
6
  connection.serviceContent.customFieldsManager.field.map do |customfield|
7
7
  {
8
- :key => customfield.key.to_i,
9
- :name => customfield.name,
10
- :type => customfield.type
8
+ key: customfield.key.to_i,
9
+ name: customfield.name,
10
+ type: customfield.type
11
11
  }
12
12
  end
13
13
  end
14
14
  end
15
15
  class Mock
16
- def list_vm_customfields()
17
- end
16
+ def list_vm_customfields; end
18
17
  end
19
18
  end
20
19
  end
@@ -2,50 +2,50 @@ module Fog
2
2
  module Compute
3
3
  class Vsphere
4
4
  class Real
5
- def list_datacenters filters = {}
5
+ def list_datacenters(_filters = {})
6
6
  raw_datacenters.map do |dc|
7
7
  {
8
- :id => managed_obj_id(dc),
9
- :name => dc.name,
10
- :path => raw_getpathmo(dc),
11
- :status => dc.overallStatus
8
+ id: managed_obj_id(dc),
9
+ name: dc.name,
10
+ path: raw_getpathmo(dc),
11
+ status: dc.overallStatus
12
12
  }
13
13
  end
14
14
  end
15
15
 
16
16
  protected
17
17
 
18
- def raw_getpathmo mo
19
- if mo.parent == nil or mo.parent.name == connection.rootFolder.name then
20
- [ mo.name ]
18
+ def raw_getpathmo(mo)
19
+ if mo.parent.nil? || (mo.parent.name == connection.rootFolder.name)
20
+ [mo.name]
21
21
  else
22
- [ raw_getpathmo(mo.parent), mo.name ].flatten
22
+ [raw_getpathmo(mo.parent), mo.name].flatten
23
23
  end
24
24
  end
25
25
 
26
- def raw_datacenters folder=nil
26
+ def raw_datacenters(folder = nil)
27
27
  folder ||= connection.rootFolder
28
28
  @raw_datacenters ||= get_raw_datacenters_from_folder folder
29
29
  end
30
30
 
31
- def get_raw_datacenters_from_folder folder=nil
32
- folder.childEntity.map do | childE |
31
+ def get_raw_datacenters_from_folder(folder = nil)
32
+ folder.childEntity.map do |childE|
33
33
  if childE.is_a? RbVmomi::VIM::Datacenter
34
- childE
34
+ childE
35
35
  elsif childE.is_a? RbVmomi::VIM::Folder
36
- get_raw_datacenters_from_folder childE
36
+ get_raw_datacenters_from_folder childE
37
37
  end
38
38
  end.flatten
39
39
  end
40
40
 
41
- def find_datacenters name=nil
41
+ def find_datacenters(name = nil)
42
42
  name ? [find_raw_datacenter(name)] : raw_datacenters
43
43
  end
44
44
  end
45
45
 
46
46
  class Mock
47
- def list_datacenters filters = {}
48
- self.data[:datacenters].values
47
+ def list_datacenters(_filters = {})
48
+ data[:datacenters].values
49
49
  end
50
50
  end
51
51
  end
@@ -2,13 +2,13 @@ module Fog
2
2
  module Compute
3
3
  class Vsphere
4
4
  class Real
5
- def list_datastores(filters = { })
5
+ def list_datastores(filters = {})
6
6
  datacenter_name = filters[:datacenter]
7
7
  cluster_name = filters.fetch(:cluster, nil)
8
8
  # default to show all datastores
9
9
  only_active = filters[:accessible] || false
10
10
  raw_datastores(datacenter_name, cluster_name).map do |datastore|
11
- next if only_active and !datastore.summary.accessible
11
+ next if only_active && !datastore.summary.accessible
12
12
  datastore_attributes(datastore, datacenter_name)
13
13
  end.compact
14
14
  end
@@ -20,18 +20,19 @@ module Fog
20
20
  get_raw_cluster(cluster, datacenter_name).datastore
21
21
  end
22
22
  end
23
+
23
24
  protected
24
25
 
25
- def datastore_attributes datastore, datacenter
26
+ def datastore_attributes(datastore, datacenter)
26
27
  {
27
- :id => managed_obj_id(datastore),
28
- :name => datastore.name,
29
- :accessible => datastore.summary.accessible,
30
- :type => datastore.summary.type,
31
- :freespace => datastore.summary.freeSpace,
32
- :capacity => datastore.summary.capacity,
33
- :uncommitted => datastore.summary.uncommitted,
34
- :datacenter => datacenter,
28
+ id: managed_obj_id(datastore),
29
+ name: datastore.name,
30
+ accessible: datastore.summary.accessible,
31
+ type: datastore.summary.type,
32
+ freespace: datastore.summary.freeSpace,
33
+ capacity: datastore.summary.capacity,
34
+ uncommitted: datastore.summary.uncommitted,
35
+ datacenter: datacenter
35
36
  }
36
37
  end
37
38
  end
@@ -40,11 +41,11 @@ module Fog
40
41
  datacenter_name = filters[:datacenter]
41
42
  cluster_name = filters.fetch(:cluster, nil)
42
43
  if cluster_name.nil?
43
- self.data[:datastores].values.select { |d| d['datacenter'] == datacenter_name } or
44
- raise Fog::Compute::Vsphere::NotFound
44
+ data[:datastores].values.select { |d| d['datacenter'] == datacenter_name } ||
45
+ raise(Fog::Compute::Vsphere::NotFound)
45
46
  else
46
- self.data[:datastores].values.select { |d| d['datacenter'] == datacenter_name && d['cluster'].include?(cluster_name) } or
47
- raise Fog::Compute::Vsphere::NotFound
47
+ data[:datastores].values.select { |d| d['datacenter'] == datacenter_name && d['cluster'].include?(cluster_name) } ||
48
+ raise(Fog::Compute::Vsphere::NotFound)
48
49
  end
49
50
  end
50
51
  end