fog-vsphere 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/.travis.yml +32 -0
  4. data/CONTRIBUTING.md +18 -0
  5. data/CONTRIBUTORS.md +59 -0
  6. data/Gemfile +5 -0
  7. data/LICENSE.md +20 -0
  8. data/README.md +31 -0
  9. data/Rakefile +8 -0
  10. data/fog-vsphere.gemspec +32 -0
  11. data/gemfiles/Gemfile.1.9.2+ +8 -0
  12. data/gemfiles/Gemfile.1.9.2- +11 -0
  13. data/lib/fog/vsphere.rb +41 -0
  14. data/lib/fog/vsphere/compute.rb +473 -0
  15. data/lib/fog/vsphere/models/compute/cluster.rb +28 -0
  16. data/lib/fog/vsphere/models/compute/clusters.rb +22 -0
  17. data/lib/fog/vsphere/models/compute/customfield.rb +16 -0
  18. data/lib/fog/vsphere/models/compute/customfields.rb +23 -0
  19. data/lib/fog/vsphere/models/compute/customvalue.rb +14 -0
  20. data/lib/fog/vsphere/models/compute/customvalues.rb +33 -0
  21. data/lib/fog/vsphere/models/compute/datacenter.rb +44 -0
  22. data/lib/fog/vsphere/models/compute/datacenters.rb +19 -0
  23. data/lib/fog/vsphere/models/compute/datastore.rb +21 -0
  24. data/lib/fog/vsphere/models/compute/datastores.rb +21 -0
  25. data/lib/fog/vsphere/models/compute/folder.rb +24 -0
  26. data/lib/fog/vsphere/models/compute/folders.rb +23 -0
  27. data/lib/fog/vsphere/models/compute/interface.rb +91 -0
  28. data/lib/fog/vsphere/models/compute/interfaces.rb +66 -0
  29. data/lib/fog/vsphere/models/compute/interfacetype.rb +22 -0
  30. data/lib/fog/vsphere/models/compute/interfacetypes.rb +34 -0
  31. data/lib/fog/vsphere/models/compute/network.rb +18 -0
  32. data/lib/fog/vsphere/models/compute/networks.rb +22 -0
  33. data/lib/fog/vsphere/models/compute/process.rb +17 -0
  34. data/lib/fog/vsphere/models/compute/resource_pool.rb +19 -0
  35. data/lib/fog/vsphere/models/compute/resource_pools.rb +22 -0
  36. data/lib/fog/vsphere/models/compute/scsicontroller.rb +16 -0
  37. data/lib/fog/vsphere/models/compute/server.rb +325 -0
  38. data/lib/fog/vsphere/models/compute/servers.rb +36 -0
  39. data/lib/fog/vsphere/models/compute/servertype.rb +36 -0
  40. data/lib/fog/vsphere/models/compute/servertypes.rb +23 -0
  41. data/lib/fog/vsphere/models/compute/snapshot.rb +35 -0
  42. data/lib/fog/vsphere/models/compute/snapshots.rb +27 -0
  43. data/lib/fog/vsphere/models/compute/template.rb +11 -0
  44. data/lib/fog/vsphere/models/compute/templates.rb +19 -0
  45. data/lib/fog/vsphere/models/compute/volume.rb +99 -0
  46. data/lib/fog/vsphere/models/compute/volumes.rb +53 -0
  47. data/lib/fog/vsphere/requests/compute/cloudinit_to_customspec.rb +65 -0
  48. data/lib/fog/vsphere/requests/compute/create_folder.rb +22 -0
  49. data/lib/fog/vsphere/requests/compute/create_vm.rb +169 -0
  50. data/lib/fog/vsphere/requests/compute/current_time.rb +18 -0
  51. data/lib/fog/vsphere/requests/compute/get_cluster.rb +25 -0
  52. data/lib/fog/vsphere/requests/compute/get_compute_resource.rb +41 -0
  53. data/lib/fog/vsphere/requests/compute/get_datacenter.rb +31 -0
  54. data/lib/fog/vsphere/requests/compute/get_datastore.rb +30 -0
  55. data/lib/fog/vsphere/requests/compute/get_folder.rb +74 -0
  56. data/lib/fog/vsphere/requests/compute/get_interface_type.rb +15 -0
  57. data/lib/fog/vsphere/requests/compute/get_network.rb +59 -0
  58. data/lib/fog/vsphere/requests/compute/get_resource_pool.rb +26 -0
  59. data/lib/fog/vsphere/requests/compute/get_server_type.rb +32 -0
  60. data/lib/fog/vsphere/requests/compute/get_template.rb +16 -0
  61. data/lib/fog/vsphere/requests/compute/get_virtual_machine.rb +57 -0
  62. data/lib/fog/vsphere/requests/compute/get_vm_first_scsi_controller.rb +26 -0
  63. data/lib/fog/vsphere/requests/compute/list_child_snapshots.rb +71 -0
  64. data/lib/fog/vsphere/requests/compute/list_clusters.rb +72 -0
  65. data/lib/fog/vsphere/requests/compute/list_compute_resources.rb +92 -0
  66. data/lib/fog/vsphere/requests/compute/list_customfields.rb +21 -0
  67. data/lib/fog/vsphere/requests/compute/list_datacenters.rb +53 -0
  68. data/lib/fog/vsphere/requests/compute/list_datastores.rb +40 -0
  69. data/lib/fog/vsphere/requests/compute/list_folders.rb +44 -0
  70. data/lib/fog/vsphere/requests/compute/list_interface_types.rb +25 -0
  71. data/lib/fog/vsphere/requests/compute/list_networks.rb +38 -0
  72. data/lib/fog/vsphere/requests/compute/list_processes.rb +40 -0
  73. data/lib/fog/vsphere/requests/compute/list_resource_pools.rb +38 -0
  74. data/lib/fog/vsphere/requests/compute/list_server_types.rb +54 -0
  75. data/lib/fog/vsphere/requests/compute/list_templates.rb +48 -0
  76. data/lib/fog/vsphere/requests/compute/list_virtual_machines.rb +80 -0
  77. data/lib/fog/vsphere/requests/compute/list_vm_customvalues.rb +20 -0
  78. data/lib/fog/vsphere/requests/compute/list_vm_interfaces.rb +63 -0
  79. data/lib/fog/vsphere/requests/compute/list_vm_snapshots.rb +66 -0
  80. data/lib/fog/vsphere/requests/compute/list_vm_volumes.rb +52 -0
  81. data/lib/fog/vsphere/requests/compute/modify_vm_interface.rb +59 -0
  82. data/lib/fog/vsphere/requests/compute/modify_vm_volume.rb +25 -0
  83. data/lib/fog/vsphere/requests/compute/revert_to_snapshot.rb +30 -0
  84. data/lib/fog/vsphere/requests/compute/set_vm_customvalue.rb +17 -0
  85. data/lib/fog/vsphere/requests/compute/vm_clone.rb +727 -0
  86. data/lib/fog/vsphere/requests/compute/vm_config_vnc.rb +45 -0
  87. data/lib/fog/vsphere/requests/compute/vm_destroy.rb +23 -0
  88. data/lib/fog/vsphere/requests/compute/vm_execute.rb +47 -0
  89. data/lib/fog/vsphere/requests/compute/vm_migrate.rb +33 -0
  90. data/lib/fog/vsphere/requests/compute/vm_power_off.rb +39 -0
  91. data/lib/fog/vsphere/requests/compute/vm_power_on.rb +26 -0
  92. data/lib/fog/vsphere/requests/compute/vm_reboot.rb +31 -0
  93. data/lib/fog/vsphere/requests/compute/vm_reconfig_cpus.rb +23 -0
  94. data/lib/fog/vsphere/requests/compute/vm_reconfig_hardware.rb +24 -0
  95. data/lib/fog/vsphere/requests/compute/vm_reconfig_memory.rb +23 -0
  96. data/lib/fog/vsphere/requests/compute/vm_take_snapshot.rb +37 -0
  97. data/lib/fog/vsphere/version.rb +5 -0
  98. data/tests/compute_tests.rb +53 -0
  99. data/tests/helper.rb +8 -0
  100. data/tests/helpers/mock_helper.rb +9 -0
  101. data/tests/helpers/succeeds_helper.rb +9 -0
  102. data/tests/models/compute/server_tests.rb +70 -0
  103. data/tests/models/compute/servers_tests.rb +15 -0
  104. data/tests/requests/compute/current_time_tests.rb +12 -0
  105. data/tests/requests/compute/get_network_tests.rb +50 -0
  106. data/tests/requests/compute/list_child_snapshots_tests.rb +10 -0
  107. data/tests/requests/compute/list_clusters_tests.rb +11 -0
  108. data/tests/requests/compute/list_virtual_machines_tests.rb +38 -0
  109. data/tests/requests/compute/list_vm_snapshots_tests.rb +10 -0
  110. data/tests/requests/compute/revert_to_snapshot_tests.rb +15 -0
  111. data/tests/requests/compute/set_vm_customvalue_tests.rb +20 -0
  112. data/tests/requests/compute/vm_clone_tests.rb +50 -0
  113. data/tests/requests/compute/vm_config_vnc_tests.rb +19 -0
  114. data/tests/requests/compute/vm_destroy_tests.rb +17 -0
  115. data/tests/requests/compute/vm_migrate_tests.rb +16 -0
  116. data/tests/requests/compute/vm_power_off_tests.rb +26 -0
  117. data/tests/requests/compute/vm_power_on_tests.rb +17 -0
  118. data/tests/requests/compute/vm_reboot_tests.rb +26 -0
  119. data/tests/requests/compute/vm_reconfig_cpus_tests.rb +19 -0
  120. data/tests/requests/compute/vm_reconfig_hardware_tests.rb +19 -0
  121. data/tests/requests/compute/vm_reconfig_memory_tests.rb +19 -0
  122. data/tests/requests/compute/vm_take_snapshot_tests.rb +19 -0
  123. metadata +289 -0
@@ -0,0 +1,40 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
4
+ class Real
5
+ def list_processes(vm_id, opts)
6
+ vm = get_vm_ref(vm_id)
7
+
8
+ auth = RbVmomi::VIM::NamePasswordAuthentication(
9
+ :username => opts[:user],
10
+ :password => opts[:password],
11
+ :interactiveSession => false
12
+ )
13
+
14
+ p_manager = @connection.serviceContent.guestOperationsManager.processManager
15
+ processes = p_manager.ListProcessesInGuest(:vm => vm, :auth => auth)
16
+ processes.map do |pi|
17
+ Process.new(
18
+ :cmd_line => pi.cmdLine,
19
+ :end_time => pi.endTime,
20
+ :exit_code => pi.exitCode,
21
+ :name => pi.name,
22
+ :owner => pi.owner,
23
+ :pid => pi.pid,
24
+ :start_time => pi.startTime
25
+ )
26
+ end
27
+ end
28
+ end
29
+
30
+ class Mock
31
+ def list_processes(vm_id, opts = {})
32
+ [
33
+ Process.new(:name => 'winlogon'),
34
+ Process.new(:name => 'init')
35
+ ]
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,38 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
4
+ class Real
5
+ def list_resource_pools(filters = { })
6
+ datacenter_name = filters[:datacenter]
7
+ cluster_name = filters[:cluster]
8
+ cluster = get_raw_cluster(cluster_name, datacenter_name)
9
+ list_raw_resource_pools(cluster).map do |resource_pool|
10
+ resource_pool_attributes(resource_pool, cluster_name, datacenter_name)
11
+ end
12
+ end
13
+
14
+ protected
15
+
16
+ # root ResourcePool + Children if they exists
17
+ def list_raw_resource_pools(cluster)
18
+ [cluster.resourcePool, cluster.resourcePool.resourcePool].flatten
19
+ end
20
+
21
+ def resource_pool_attributes resource_pool, cluster, datacenter
22
+ {
23
+ :id => managed_obj_id(resource_pool),
24
+ :name => resource_pool.name,
25
+ :configured_memory_mb => resource_pool.summary.configuredMemoryMB,
26
+ :overall_status => resource_pool.overallStatus,
27
+ :cluster => cluster,
28
+ :datacenter => datacenter
29
+ }
30
+ end
31
+ end
32
+ class Mock
33
+ def list_resource_pools(filters = { })
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,54 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
4
+ class Real
5
+ def list_server_types(filters={})
6
+ datacenter_name = filters[:datacenter]
7
+ servertypes=raw_server_types(datacenter_name)
8
+ if servertypes
9
+ servertypes.map do | servertype |
10
+ server_type_attributes(servertype, datacenter_name)
11
+ end.compact
12
+ else
13
+ nil
14
+ end
15
+ #select{ | guestdesc | guestdesc.select{ | k, v | filter.has_key?(k) and filter[k] == v }==filter }
16
+ end
17
+
18
+ def raw_server_types(datacenter_name, filter={})
19
+ datacenter=find_raw_datacenter(datacenter_name)
20
+ environmentBrowser=datacenter.hostFolder.childEntity.grep(RbVmomi::VIM::ComputeResource).first.environmentBrowser
21
+ if environmentBrowser
22
+ environmentBrowser.QueryConfigOption[:guestOSDescriptor]
23
+ end
24
+ end
25
+
26
+ protected
27
+
28
+ def server_type_attributes(servertype, datacenter)
29
+ {
30
+ :id => servertype.id,
31
+ :name => servertype.id,
32
+ :family => servertype.family,
33
+ :fullname => servertype.fullName,
34
+ :datacenter => datacenter,
35
+ }
36
+ end
37
+ end
38
+ class Mock
39
+ def list_server_types(datacenter_name)
40
+ [{:id=>"rhel6Guest",
41
+ :name=>"rhel6Guest",
42
+ :family=>"linuxGuest",
43
+ :fullname=>"Red Hat Enterprise Linux 6 (32-Bit)",
44
+ :datacenter=>"Solutions"},
45
+ {:id=>"rhel5_64Guest",
46
+ :name=>"rhel5_64Guest",
47
+ :family=>"linuxGuest",
48
+ :fullname=>"Red Hat Enterprise Linux 5 (64-Bit)",
49
+ :datacenter=>"Solutions"}]
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,48 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
4
+ class Real
5
+ def list_templates(options = { })
6
+ options[:folder] ||= options['folder']
7
+ if options[:folder] then
8
+ list_all_templates_in_folder(options[:folder], options[:datacenter])
9
+ else
10
+ list_all_templates(options)
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def list_all_templates_in_folder(path, datacenter_name)
17
+ folder = get_raw_vmfolder(path, datacenter_name)
18
+
19
+ vms = folder.children.grep(RbVmomi::VIM::VirtualMachine)
20
+ # remove all virtual machines that are not template
21
+ vms.delete_if { |v| v.config.nil? or not v.config.template }
22
+
23
+ vms.map(&method(:convert_vm_mob_ref_to_attr_hash))
24
+ end
25
+
26
+ def list_all_templates(options = {})
27
+ datacenters = find_datacenters(options[:datacenter])
28
+
29
+ vms = datacenters.map do |dc|
30
+ @connection.serviceContent.viewManager.CreateContainerView({
31
+ :container => dc.vmFolder,
32
+ :type => ["VirtualMachine"],
33
+ :recursive => true
34
+ }).view
35
+ end.flatten
36
+ # remove all virtual machines that are not templates
37
+ vms.delete_if { |v| v.config.nil? or not v.config.template }
38
+
39
+ vms.map(&method(:convert_vm_mob_ref_to_attr_hash))
40
+ end
41
+ end
42
+ class Mock
43
+ def list_templates(filters = { })
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,80 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
4
+ class Real
5
+ def list_virtual_machines(options = { })
6
+ # Listing all VM's can be quite slow and expensive. Try and optimize
7
+ # based on the available options we have. These conditions are in
8
+ # ascending order of time to complete for large deployments.
9
+
10
+ options[:folder] ||= options['folder']
11
+ if options['instance_uuid'] then
12
+ [get_virtual_machine(options['instance_uuid'])]
13
+ elsif options[:folder] && options[:datacenter] then
14
+ list_all_virtual_machines_in_folder(options[:folder], options[:datacenter])
15
+ else
16
+ list_all_virtual_machines(options)
17
+ end
18
+ end
19
+
20
+
21
+ private
22
+
23
+ def list_all_virtual_machines_in_folder(path, datacenter_name)
24
+ folder = get_raw_vmfolder(path, datacenter_name)
25
+
26
+ vms = folder.children.grep(RbVmomi::VIM::VirtualMachine)
27
+ # remove all template based virtual machines
28
+ vms.delete_if { |v| v.config.nil? or v.config.template }
29
+ vms.map(&method(:convert_vm_mob_ref_to_attr_hash))
30
+ end
31
+
32
+ def list_all_virtual_machines(options = { })
33
+ raw_vms = raw_list_all_virtual_machines(options[:datacenter])
34
+ vms = convert_vm_view_to_attr_hash(raw_vms)
35
+
36
+ # remove all template based virtual machines
37
+ vms.delete_if { |v| v['template'] }
38
+ vms
39
+ end
40
+
41
+ def raw_list_all_virtual_machines(datacenter_name = nil)
42
+ ## Moved this to its own function since trying to get a list of all virtual machines
43
+ ## to parse for a find function took way too long. The raw list returned will make it
44
+ ## much faster to interact for some functions.
45
+ datacenters = find_datacenters(datacenter_name)
46
+ datacenters.map do |dc|
47
+ @connection.serviceContent.viewManager.CreateContainerView({
48
+ :container => dc.vmFolder,
49
+ :type => ["VirtualMachine"],
50
+ :recursive => true
51
+ }).view
52
+ end.flatten
53
+ end
54
+ def get_folder_path(folder, root = nil)
55
+ if (not folder.methods.include?('parent')) or (folder == root)
56
+ return
57
+ end
58
+ "#{get_folder_path(folder.parent)}/#{folder.name}"
59
+ end
60
+ end
61
+
62
+ class Mock
63
+ def get_folder_path(folder, root = nil)
64
+ nil
65
+ end
66
+
67
+ def list_virtual_machines(options = { })
68
+ if options['instance_uuid'].nil? and options['mo_ref'].nil?
69
+ self.data[:servers].values
70
+ elsif !options['instance_uuid'].nil?
71
+ server = self.data[:servers][options['instance_uuid']]
72
+ server.nil? ? [] : [server]
73
+ else
74
+ self.data[:servers].values.select{|vm| vm['mo_ref'] == options['mo_ref']}
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,20 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
4
+ class Real
5
+ def list_vm_customvalues(vm_id)
6
+ get_vm_ref(vm_id).summary.customValue.map do |customvalue|
7
+ {
8
+ :key => customvalue.key.to_i,
9
+ :value => customvalue.value,
10
+ }
11
+ end
12
+ end
13
+ end
14
+ class Mock
15
+ def list_vm_customfields(vm_id)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,63 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
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
+ #
31
+ def list_vm_interfaces(vm_id, datacenter = nil)
32
+ get_vm_ref(vm_id, datacenter).config.hardware.device.grep(RbVmomi::VIM::VirtualEthernetCard).map do |nic|
33
+ {
34
+ :name => nic.deviceInfo.label,
35
+ :mac => nic.macAddress,
36
+ :network => nic.backing.respond_to?("network") ? nic.backing.network.name : nic.backing.port.portgroupKey,
37
+ :status => nic.connectable.status,
38
+ :summary => nic.deviceInfo.summary,
39
+ :type => nic.class,
40
+ :key => nic.key,
41
+ }
42
+ end
43
+ end
44
+
45
+ def get_vm_interface(vm_id, options={})
46
+ raise ArgumentError, "instance id is a required parameter" unless vm_id
47
+ if options.is_a? Fog::Compute::Vsphere::Interface
48
+ options
49
+ else
50
+ raise ArgumentError, "Either key or name is a required parameter. options: #{options}" unless options.key? :key or options.key? :mac or options.key? :name
51
+ list_vm_interfaces(vm_id).find do | nic |
52
+ (options.key? :key and nic[:key]==options[:key].to_i) or (options.key? :mac and nic[:mac]==options[:mac]) or (options.key? :name and nic[:name]==options[:name])
53
+ end
54
+ end
55
+ end
56
+ end
57
+ class Mock
58
+ def list_vm_interfaces(vm_id)
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,66 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
4
+ class Real
5
+ def list_vm_snapshots(vm_id, opts = {})
6
+ root_snapshots = get_vm_ref(vm_id).snapshot.rootSnapshotList.map do |snap|
7
+ item = snapshot_info(snap, vm_id)
8
+ [
9
+ item,
10
+ opts[:recursive] ? list_child_snapshots(item, opts) : nil
11
+ ]
12
+ end
13
+
14
+ root_snapshots.flatten.compact
15
+ end
16
+
17
+ protected
18
+
19
+ def snapshot_info(snap_tree, vm_id)
20
+ {
21
+ :name => snap_tree.name,
22
+ :quiesced => snap_tree.quiesced,
23
+ :description => snap_tree.description,
24
+ :create_time => snap_tree.createTime,
25
+ :power_state => snap_tree.state,
26
+ :ref => snap_tree.snapshot._ref,
27
+ :mo_ref => snap_tree.snapshot,
28
+ :tree_node => snap_tree,
29
+ :ref_chain => "#{vm_id}/#{snap_tree.snapshot._ref}",
30
+ :snapshot_name_chain => "#{vm_id}/#{snap_tree.name}"
31
+ }
32
+ end
33
+ end
34
+ class Mock
35
+ def list_vm_snapshots(vm_id, opts = {})
36
+ [
37
+ {
38
+ :name => 'clean',
39
+ :quiesced => false,
40
+ :description => '',
41
+ :create_time => Time.now.utc,
42
+ :power_state => 'poweredOn',
43
+ :ref => 'snapshot-0101',
44
+ :mo_ref => nil,
45
+ :tree_node => nil,
46
+ :snapshot_name_chain => '123/clean',
47
+ :ref_chain => "#{vm_id}/snapshot-0101"
48
+ },
49
+ {
50
+ :name => 'dirty',
51
+ :quiesced => false,
52
+ :description => '',
53
+ :create_time => Time.now.utc,
54
+ :power_state => 'poweredOn',
55
+ :ref => 'snapshot-0102',
56
+ :mo_ref => nil,
57
+ :tree_node => nil,
58
+ :snapshot_name_chain => '123/dirty',
59
+ :ref_chain => "#{vm_id}/snapshot-0102"
60
+ }
61
+ ]
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,52 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
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
+ #)]
29
+
30
+ def list_vm_volumes(vm_id)
31
+ get_vm_ref(vm_id).disks.map do |vol|
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
+ }
43
+ end
44
+ end
45
+ end
46
+ class Mock
47
+ def list_vm_volumes(vm_id)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end