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
@@ -2,9 +2,9 @@ module Fog
2
2
  module Compute
3
3
  class Vsphere
4
4
  class Real
5
- def list_templates(options = { })
5
+ def list_templates(options = {})
6
6
  options[:folder] ||= options['folder']
7
- if options[:folder] then
7
+ if options[:folder]
8
8
  list_all_templates_in_folder(options[:folder], options[:datacenter])
9
9
  else
10
10
  list_all_templates(options)
@@ -18,7 +18,7 @@ module Fog
18
18
 
19
19
  vms = folder.children.grep(RbVmomi::VIM::VirtualMachine)
20
20
  # remove all virtual machines that are not template
21
- vms.delete_if { |v| v.config.nil? or not v.config.template }
21
+ vms.delete_if { |v| v.config.nil? || !v.config.template }
22
22
 
23
23
  vms.map(&method(:convert_vm_mob_ref_to_attr_hash))
24
24
  end
@@ -36,8 +36,7 @@ module Fog
36
36
  end
37
37
  end
38
38
  class Mock
39
- def list_templates(filters = { })
40
- end
39
+ def list_templates(filters = {}); end
41
40
  end
42
41
  end
43
42
  end
@@ -2,22 +2,21 @@ module Fog
2
2
  module Compute
3
3
  class Vsphere
4
4
  class Real
5
- def list_virtual_machines(options = { })
5
+ def list_virtual_machines(options = {})
6
6
  # Listing all VM's can be quite slow and expensive. Try and optimize
7
7
  # based on the available options we have. These conditions are in
8
8
  # ascending order of time to complete for large deployments.
9
9
 
10
10
  options[:folder] ||= options['folder']
11
- if options['instance_uuid'] then
11
+ if options['instance_uuid']
12
12
  [get_virtual_machine(options['instance_uuid'])]
13
- elsif options[:folder] && options[:datacenter] then
13
+ elsif options[:folder] && options[:datacenter]
14
14
  list_all_virtual_machines_in_folder(options[:folder], options[:datacenter], options[:recursive])
15
15
  else
16
16
  list_all_virtual_machines(options)
17
17
  end
18
18
  end
19
19
 
20
-
21
20
  private
22
21
 
23
22
  def list_all_virtual_machines_in_folder(path, datacenter_name, recursive)
@@ -39,7 +38,7 @@ module Fog
39
38
  raw_folder.children.each do |child|
40
39
  case child
41
40
  when RbVmomi::VIM::Folder
42
- folder_enumerator(child, true).each {|item| yielder.yield item} if recursive
41
+ folder_enumerator(child, true).each { |item| yielder.yield item } if recursive
43
42
  when RbVmomi::VIM::VirtualMachine
44
43
  yielder.yield child
45
44
  end
@@ -47,7 +46,7 @@ module Fog
47
46
  end
48
47
  end
49
48
 
50
- def list_all_virtual_machines(options = { })
49
+ def list_all_virtual_machines(options = {})
51
50
  raw_vms = raw_list_all_virtual_machines(options[:datacenter])
52
51
  vms = convert_vm_view_to_attr_hash(raw_vms)
53
52
 
@@ -65,29 +64,30 @@ module Fog
65
64
  list_container_view(dc, 'VirtualMachine', :vmFolder)
66
65
  end.flatten
67
66
  end
67
+
68
68
  def get_folder_path(folder, root = nil)
69
- return if (!folder.methods.include?('parent')) || (folder == root)
69
+ return if !folder.methods.include?('parent') || (folder == root)
70
70
  "#{get_folder_path(folder.parent)}/#{folder.name}"
71
71
  end
72
72
  end
73
73
 
74
74
  class Mock
75
- def get_folder_path(folder, root = nil)
75
+ def get_folder_path(_folder, _root = nil)
76
76
  nil
77
77
  end
78
78
 
79
- def list_virtual_machines(options = { })
79
+ def list_virtual_machines(options = {})
80
80
  if options['instance_uuid']
81
- server = self.data[:servers][options['instance_uuid']]
81
+ server = data[:servers][options['instance_uuid']]
82
82
  server.nil? ? [] : [server]
83
83
  elsif options['mo_ref']
84
- self.data[:servers].values.select{|vm| vm['mo_ref'] == options['mo_ref']}
85
- elsif options[:folder] and options[:datacenter]
86
- self.data[:servers].values.select {|vm| vm['path'] == options[:folder] && vm['datacenter'] == options[:datacenter]}
84
+ data[:servers].values.select { |vm| vm['mo_ref'] == options['mo_ref'] }
85
+ elsif options[:folder] && options[:datacenter]
86
+ data[:servers].values.select { |vm| vm['path'] == options[:folder] && vm['datacenter'] == options[:datacenter] }
87
87
  else
88
88
  options.delete('datacenter') # real code iterates if this is missing
89
- options.reject! {|k,v| v.nil? } # ignore options with nil value
90
- self.data[:servers].values.select {|vm| options.all? {|k,v| vm[k.to_s] == v.to_s }}
89
+ options.reject! { |_k, v| v.nil? } # ignore options with nil value
90
+ data[:servers].values.select { |vm| options.all? { |k, v| vm[k.to_s] == v.to_s } }
91
91
  end
92
92
  end
93
93
  end
@@ -5,24 +5,28 @@ module Fog
5
5
  def list_vm_cdroms(vm_id)
6
6
  get_vm_ref(vm_id).config.hardware.device.select { |hw| hw.class == RbVmomi::VIM::VirtualCdrom }.map do |cdrom|
7
7
  {
8
- :filename => (cdrom.backing.fileName rescue(nil)),
9
- :name => cdrom.deviceInfo.label,
10
- :key => cdrom.key,
11
- :controller_key => cdrom.controllerKey,
12
- :unit_number => cdrom.unitNumber,
13
- :start_connected => cdrom.connectable.startConnected,
14
- :allow_guest_control => cdrom.connectable.allowGuestControl,
15
- :connected => cdrom.connectable.connected,
16
- :instance_uuid => vm_id,
8
+ filename: (begin
9
+ cdrom.backing.fileName
10
+ rescue
11
+ (nil)
12
+ end),
13
+ name: cdrom.deviceInfo.label,
14
+ key: cdrom.key,
15
+ controller_key: cdrom.controllerKey,
16
+ unit_number: cdrom.unitNumber,
17
+ start_connected: cdrom.connectable.startConnected,
18
+ allow_guest_control: cdrom.connectable.allowGuestControl,
19
+ connected: cdrom.connectable.connected,
20
+ instance_uuid: vm_id
17
21
  }
18
22
  end
19
23
  end
20
24
  end
21
25
  class Mock
22
26
  def list_vm_cdroms(vm_id)
23
- raise Fog::Compute::Vsphere::NotFound, 'VM not Found' unless self.data[:servers].key?(vm_id)
24
- return [] unless self.data[:servers][vm_id].key?('cdroms')
25
- self.data[:servers][vm_id]['cdroms'].map {|h| h.merge({:instance_uuid => vm_id}) }
27
+ raise Fog::Compute::Vsphere::NotFound, 'VM not Found' unless data[:servers].key?(vm_id)
28
+ return [] unless data[:servers][vm_id].key?('cdroms')
29
+ data[:servers][vm_id]['cdroms'].map { |h| h.merge(instance_uuid: vm_id) }
26
30
  end
27
31
  end
28
32
  end
@@ -5,15 +5,14 @@ module Fog
5
5
  def list_vm_customvalues(vm_id)
6
6
  get_vm_ref(vm_id).summary.customValue.map do |customvalue|
7
7
  {
8
- :key => customvalue.key.to_i,
9
- :value => customvalue.value,
8
+ key: customvalue.key.to_i,
9
+ value: customvalue.value
10
10
  }
11
11
  end
12
12
  end
13
13
  end
14
14
  class Mock
15
- def list_vm_customfields(vm_id)
16
- end
15
+ def list_vm_customfields(vm_id); end
17
16
  end
18
17
  end
19
18
  end
@@ -2,83 +2,81 @@ module Fog
2
2
  module Compute
3
3
  class Vsphere
4
4
  class Real
5
- # => VirtualE1000(
6
- #addressType: "assigned",
7
- #backing: VirtualEthernetCardNetworkBackingInfo(
8
- # deviceName: "VM Network",
9
- # dynamicProperty: [],
10
- # network: Network("network-163"),
11
- # useAutoDetect: false
12
- #),
13
- #connectable: VirtualDeviceConnectInfo(
14
- # allowGuestControl: true,
15
- # connected: true,
16
- # dynamicProperty: [],
17
- # startConnected: true,
18
- # status: "ok"
19
- #),
20
- #controllerKey: 100,
21
- #deviceInfo: Description(
22
- # dynamicProperty: [],
23
- # label: "Network adapter 1",
24
- # summary: "VM Network"
25
- #),
26
- #dynamicProperty: [],
27
- #key: 4000,
28
- #macAddress: "00:50:56:a9:00:28",
29
- #unitNumber: 7,
30
- #
5
+ # => VirtualE1000(
6
+ # addressType: "assigned",
7
+ # backing: VirtualEthernetCardNetworkBackingInfo(
8
+ # deviceName: "VM Network",
9
+ # dynamicProperty: [],
10
+ # network: Network("network-163"),
11
+ # useAutoDetect: false
12
+ # ),
13
+ # connectable: VirtualDeviceConnectInfo(
14
+ # allowGuestControl: true,
15
+ # connected: true,
16
+ # dynamicProperty: [],
17
+ # startConnected: true,
18
+ # status: "ok"
19
+ # ),
20
+ # controllerKey: 100,
21
+ # deviceInfo: Description(
22
+ # dynamicProperty: [],
23
+ # label: "Network adapter 1",
24
+ # summary: "VM Network"
25
+ # ),
26
+ # dynamicProperty: [],
27
+ # key: 4000,
28
+ # macAddress: "00:50:56:a9:00:28",
29
+ # unitNumber: 7,
30
+ #
31
31
  def list_vm_interfaces(vm_id, datacenter = nil)
32
- get_raw_interfaces(vm_id, datacenter).map {|nic| raw_to_hash nic}
32
+ get_raw_interfaces(vm_id, datacenter).map { |nic| raw_to_hash nic }
33
33
  end
34
34
 
35
- def get_vm_interface(vm_id, options={})
35
+ def get_vm_interface(vm_id, options = {})
36
36
  raw = get_raw_interface(vm_id, options)
37
- if raw
38
- raw_to_hash(raw)
39
- else
40
- nil
41
- end
37
+ raw_to_hash(raw) if raw
42
38
  end
43
-
39
+
44
40
  def get_raw_interfaces(vm_id, datacenter = nil)
45
41
  get_vm_ref(vm_id, datacenter).config.hardware.device.grep(RbVmomi::VIM::VirtualEthernetCard)
46
42
  end
47
-
48
- def get_raw_interface(vm_id, options={})
49
- raise ArgumentError, "instance id is a required parameter" unless vm_id
43
+
44
+ def get_raw_interface(vm_id, options = {})
45
+ raise ArgumentError, 'instance id is a required parameter' unless vm_id
46
+
50
47
  if options.is_a? Fog::Compute::Vsphere::Interface
51
48
  options
49
+
52
50
  else
53
- raise ArgumentError, "Either key or name is a required parameter. options: #{options}" unless options.key? :key or options.key? :mac or options.key? :name
54
- get_raw_interfaces(vm_id).find do |nic|
55
- (options.key? :key and nic.key==options[:key].to_i) or
56
- (options.key? :mac and nic.macAddress==options[:mac]) or
57
- (options.key? :name and nic.deviceInfo.label==options[:name])
51
+ raise ArgumentError, "Either key or name is a required parameter. options: #{options}" unless options.key?(:key) || options.key?(:mac) || options.key?(:name)
52
+ raise ArgumentError, "'datacenter' is a required parameter in options: #{options}" unless options.key?(:datacenter)
53
+
54
+ get_raw_interfaces(vm_id, options[:datacenter]).find do |nic|
55
+ (options.key?(:key) && (nic.key == options[:key].to_i)) ||
56
+ (options.key?(:mac) && (nic.macAddress == options[:mac])) ||
57
+ (options.key?(:name) && (nic.deviceInfo.label == options[:name]))
58
58
  end
59
59
  end
60
60
  end
61
-
61
+
62
62
  private
63
-
63
+
64
64
  def raw_to_hash(nic)
65
65
  {
66
- :name => nic.deviceInfo.label,
67
- :mac => nic.macAddress,
68
- :network => nic.backing.respond_to?("network") ? nic.backing.network.name : nic.backing.port.portgroupKey,
69
- :status => nic.connectable.status,
70
- :connected => nic.connectable.connected,
71
- :summary => nic.deviceInfo.summary,
72
- :type => nic.class,
73
- :key => nic.key,
66
+ name: nic.deviceInfo.label,
67
+ mac: nic.macAddress,
68
+ network: nic.backing.respond_to?('network') ? nic.backing.network.name : nic.backing.port.portgroupKey,
69
+ status: nic.connectable.status,
70
+ connected: nic.connectable.connected,
71
+ summary: nic.deviceInfo.summary,
72
+ type: nic.class,
73
+ key: nic.key
74
74
  }
75
75
  end
76
-
77
76
  end
78
-
77
+
79
78
  class Mock
80
- def list_vm_interfaces(vm_id)
81
- end
79
+ def list_vm_interfaces(vm_id); end
82
80
  end
83
81
  end
84
82
  end
@@ -11,19 +11,19 @@ module Fog
11
11
  def list_vm_scsi_controllers_raw(vm_id)
12
12
  get_vm_ref(vm_id).config.hardware.device.grep(RbVmomi::VIM::VirtualSCSIController).map do |ctrl|
13
13
  {
14
- :type => ctrl.class.to_s,
15
- :shared_bus => ctrl.sharedBus.to_s,
16
- :unit_number => ctrl.scsiCtlrUnitNumber,
17
- :key => ctrl.key,
14
+ type: ctrl.class.to_s,
15
+ shared_bus: ctrl.sharedBus.to_s,
16
+ unit_number: ctrl.scsiCtlrUnitNumber,
17
+ key: ctrl.key
18
18
  }
19
19
  end
20
20
  end
21
21
  end
22
22
  class Mock
23
23
  def list_vm_scsi_controllers(vm_id)
24
- raise Fog::Compute::Vsphere::NotFound, 'VM not Found' unless self.data[:servers].key?(vm_id)
25
- return [] unless self.data[:servers][vm_id].key?('scsi_controllers')
26
- self.data[:servers][vm_id]['scsi_controllers'].map {|h| h.merge(:server_id => vm_id) }
24
+ raise Fog::Compute::Vsphere::NotFound, 'VM not Found' unless data[:servers].key?(vm_id)
25
+ return [] unless data[:servers][vm_id].key?('scsi_controllers')
26
+ data[:servers][vm_id]['scsi_controllers'].map { |h| h.merge(server_id: vm_id) }
27
27
  end
28
28
  end
29
29
  end
@@ -20,48 +20,48 @@ module Fog
20
20
 
21
21
  protected
22
22
 
23
- def snapshot_info(snap_tree, vm_id)
24
- {
25
- :name => snap_tree.name,
26
- :quiesced => snap_tree.quiesced,
27
- :description => snap_tree.description,
28
- :create_time => snap_tree.createTime,
29
- :power_state => snap_tree.state,
30
- :ref => snap_tree.snapshot._ref,
31
- :mo_ref => snap_tree.snapshot,
32
- :tree_node => snap_tree,
33
- :ref_chain => "#{vm_id}/#{snap_tree.snapshot._ref}",
34
- :snapshot_name_chain => "#{vm_id}/#{snap_tree.name}",
35
- :server_id => vm_id
36
- }
37
- end
23
+ def snapshot_info(snap_tree, vm_id)
24
+ {
25
+ name: snap_tree.name,
26
+ quiesced: snap_tree.quiesced,
27
+ description: snap_tree.description,
28
+ create_time: snap_tree.createTime,
29
+ power_state: snap_tree.state,
30
+ ref: snap_tree.snapshot._ref,
31
+ mo_ref: snap_tree.snapshot,
32
+ tree_node: snap_tree,
33
+ ref_chain: "#{vm_id}/#{snap_tree.snapshot._ref}",
34
+ snapshot_name_chain: "#{vm_id}/#{snap_tree.name}",
35
+ server_id: vm_id
36
+ }
37
+ end
38
38
  end
39
39
  class Mock
40
- def list_vm_snapshots(vm_id, opts = {})
40
+ def list_vm_snapshots(vm_id, _opts = {})
41
41
  [
42
42
  {
43
- :name => 'clean',
44
- :quiesced => false,
45
- :description => '',
46
- :create_time => Time.now.utc,
47
- :power_state => 'poweredOn',
48
- :ref => 'snapshot-0101',
49
- :mo_ref => nil,
50
- :tree_node => nil,
51
- :snapshot_name_chain => '123/clean',
52
- :ref_chain => "#{vm_id}/snapshot-0101"
43
+ name: 'clean',
44
+ quiesced: false,
45
+ description: '',
46
+ create_time: Time.now.utc,
47
+ power_state: 'poweredOn',
48
+ ref: 'snapshot-0101',
49
+ mo_ref: nil,
50
+ tree_node: nil,
51
+ snapshot_name_chain: '123/clean',
52
+ ref_chain: "#{vm_id}/snapshot-0101"
53
53
  },
54
54
  {
55
- :name => 'dirty',
56
- :quiesced => false,
57
- :description => '',
58
- :create_time => Time.now.utc,
59
- :power_state => 'poweredOn',
60
- :ref => 'snapshot-0102',
61
- :mo_ref => nil,
62
- :tree_node => nil,
63
- :snapshot_name_chain => '123/dirty',
64
- :ref_chain => "#{vm_id}/snapshot-0102"
55
+ name: 'dirty',
56
+ quiesced: false,
57
+ description: '',
58
+ create_time: Time.now.utc,
59
+ power_state: 'poweredOn',
60
+ ref: 'snapshot-0102',
61
+ mo_ref: nil,
62
+ tree_node: nil,
63
+ snapshot_name_chain: '123/dirty',
64
+ ref_chain: "#{vm_id}/snapshot-0102"
65
65
  }
66
66
  ]
67
67
  end
@@ -2,51 +2,58 @@ module Fog
2
2
  module Compute
3
3
  class Vsphere
4
4
  class Real
5
- # [VirtualDisk(
6
- # backing: VirtualDiskFlatVer2BackingInfo(
7
- # contentId: "a172d19487e878e17d6b16ff2505d7eb",
8
- # datastore: Datastore("datastore-162"),
9
- # diskMode: "persistent",
10
- # dynamicProperty: [],
11
- # fileName: "[Storage1] rhel6-mfojtik/rhel6-mfojtik.vmdk",
12
- # split: false,
13
- # thinProvisioned: true,
14
- # uuid: "6000C29c-a47d-4cd9-5249-c371de775f06",
15
- # writeThrough: false
16
- # ),
17
- # capacityInKB: 8388608,
18
- # controllerKey: 1000,
19
- # deviceInfo: Description(
20
- # dynamicProperty: [],
21
- # label: "Hard disk 1",
22
- # summary: "8,388,608 KB"
23
- # ),
24
- # dynamicProperty: [],
25
- # key: 2001,
26
- # shares: SharesInfo( dynamicProperty: [], level: "normal", shares: 1000 ),
27
- # unitNumber: 1
28
- #)]
5
+ # [VirtualDisk(
6
+ # backing: VirtualDiskFlatVer2BackingInfo(
7
+ # contentId: "a172d19487e878e17d6b16ff2505d7eb",
8
+ # datastore: Datastore("datastore-162"),
9
+ # diskMode: "persistent",
10
+ # dynamicProperty: [],
11
+ # fileName: "[Storage1] rhel6-mfojtik/rhel6-mfojtik.vmdk",
12
+ # split: false,
13
+ # thinProvisioned: true,
14
+ # uuid: "6000C29c-a47d-4cd9-5249-c371de775f06",
15
+ # writeThrough: false
16
+ # ),
17
+ # capacityInKB: 8388608,
18
+ # controllerKey: 1000,
19
+ # deviceInfo: Description(
20
+ # dynamicProperty: [],
21
+ # label: "Hard disk 1",
22
+ # summary: "8,388,608 KB"
23
+ # ),
24
+ # dynamicProperty: [],
25
+ # key: 2001,
26
+ # shares: SharesInfo( dynamicProperty: [], level: "normal", shares: 1000 ),
27
+ # unitNumber: 1
28
+ # )]
29
29
 
30
30
  def list_vm_volumes(vm_id)
31
31
  get_vm_ref(vm_id).disks.map do |vol|
32
32
  {
33
- :id => vol.backing.uuid,
34
- :thin => (vol.backing.thinProvisioned rescue(nil)),
35
- :mode => vol.backing.diskMode,
36
- :filename => vol.backing.fileName,
37
- :datastore => (vol.backing.datastore.name rescue(nil)),
38
- :size => vol.capacityInKB,
39
- :name => vol.deviceInfo.label,
40
- :key => vol.key,
41
- :unit_number => vol.unitNumber,
42
- :controller_key => vol.controllerKey
33
+ id: vol.backing.uuid,
34
+ thin: (begin
35
+ vol.backing.thinProvisioned
36
+ rescue
37
+ (nil)
38
+ end),
39
+ mode: vol.backing.diskMode,
40
+ filename: vol.backing.fileName,
41
+ datastore: (begin
42
+ vol.backing.datastore.name
43
+ rescue
44
+ (nil)
45
+ end),
46
+ size: vol.capacityInKB,
47
+ name: vol.deviceInfo.label,
48
+ key: vol.key,
49
+ unit_number: vol.unitNumber,
50
+ controller_key: vol.controllerKey
43
51
  }
44
52
  end
45
53
  end
46
54
  end
47
55
  class Mock
48
- def list_vm_volumes(vm_id)
49
- end
56
+ def list_vm_volumes(vm_id); end
50
57
  end
51
58
  end
52
59
  end