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,71 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
4
+ class Real
5
+ def list_child_snapshots(snapshot, opts = {})
6
+ normalized_snapshot = Hash === snapshot ?
7
+ Snapshot.new(snapshot.update(:service => self)) : snapshot
8
+
9
+ child_snapshots = normalized_snapshot.tree_node.childSnapshotList.map do |snap|
10
+ item = child_snapshot_info(snap, normalized_snapshot)
11
+ [
12
+ item,
13
+ opts[:recursive] ? list_child_snapshots(item, opts) : nil
14
+ ]
15
+ end
16
+
17
+ child_snapshots.flatten.compact
18
+ end
19
+
20
+ protected
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
+ }
37
+ end
38
+ end
39
+ class Mock
40
+ def list_child_snapshots(snapshot, opts = {})
41
+ [
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 => '123/snap-0101'
53
+ },
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 => '123/snap-0102'
65
+ }
66
+ ]
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,72 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
4
+ class Real
5
+ def list_clusters(filters = { })
6
+ datacenter_name = filters[:datacenter]
7
+
8
+ raw_clusters(datacenter_name).map do |cluster|
9
+ cluster_attributes(cluster, datacenter_name)
10
+ end
11
+ end
12
+
13
+ def raw_clusters(datacenter)
14
+ folder ||= find_raw_datacenter(datacenter).hostFolder
15
+ @raw_clusters = get_raw_clusters_from_folder(folder)
16
+ end
17
+
18
+ protected
19
+
20
+ def get_raw_clusters_from_folder(folder)
21
+ folder.childEntity.map do |child_entity|
22
+ if child_entity.is_a? RbVmomi::VIM::ComputeResource
23
+ child_entity
24
+ elsif child_entity.is_a? RbVmomi::VIM::Folder
25
+ get_raw_clusters_from_folder(child_entity)
26
+ end
27
+ end.flatten
28
+ end
29
+
30
+ def cluster_attributes cluster, datacenter_name
31
+ {
32
+ :id => managed_obj_id(cluster),
33
+ :name => cluster.name,
34
+ :full_path => cluster_path(cluster, datacenter_name),
35
+ :num_host => cluster.summary.numHosts,
36
+ :num_cpu_cores => cluster.summary.numCpuCores,
37
+ :overall_status => cluster.summary.overallStatus,
38
+ :datacenter => datacenter_name || parent_attribute(cluster.path, :datacenter)[1],
39
+ }
40
+ end
41
+
42
+ def cluster_path(cluster, datacenter_name)
43
+ datacenter = find_raw_datacenter(datacenter_name)
44
+ cluster.pretty_path.gsub(/(#{datacenter_name}|#{datacenter.hostFolder.name})\//,'')
45
+ end
46
+ end
47
+
48
+ class Mock
49
+ def list_clusters(filters = { })
50
+ raw_clusters.map do |cluster|
51
+ cluster
52
+ end
53
+ end
54
+
55
+ def raw_clusters
56
+ folder = self.data[:clusters]
57
+ @raw_clusters = get_raw_clusters_from_folder(folder)
58
+ end
59
+
60
+ def get_raw_clusters_from_folder(folder)
61
+ folder.map do |child|
62
+ if child[:klass] == "RbVmomi::VIM::ComputeResource"
63
+ child
64
+ elsif child[:klass] == "RbVmomi::VIM::Folder"
65
+ get_raw_clusters_from_folder(child[:clusters])
66
+ end
67
+ end.flatten
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,92 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
4
+ class Real
5
+ def list_compute_resources(filters = { })
6
+ datacenter_name = filters[:datacenter]
7
+ # default to show all compute_resources
8
+ only_active = filters[:effective] || false
9
+ compute_resources = raw_compute_resources datacenter_name
10
+
11
+ compute_resources.map do |compute_resource|
12
+ summary = compute_resource.summary
13
+ next if only_active and summary.numEffectiveHosts == 0
14
+ compute_resource_attributes(compute_resource, datacenter_name)
15
+ end.compact
16
+ end
17
+
18
+ def raw_compute_resources(datacenter_name)
19
+ find_raw_datacenter(datacenter_name).find_compute_resource('').children
20
+ end
21
+
22
+ protected
23
+
24
+ def compute_resource_attributes compute_resource, datacenter
25
+ overall_usage = compute_resource.host.inject({:overallCpuUsage=>0, :overallMemoryUsage=>0}) do |sum, host|
26
+ {
27
+ :overallCpuUsage => sum[:overallCpuUsage]+(host.summary.quickStats.overallCpuUsage || 0),
28
+ :overallMemoryUsage=> sum[:overallMemoryUsage]+(host.summary.quickStats.overallMemoryUsage || 0)
29
+ }
30
+ end
31
+ {
32
+ :id => managed_obj_id(compute_resource),
33
+ :name => compute_resource.name,
34
+ :totalCpu => compute_resource.summary.totalCpu,
35
+ :totalMemory => compute_resource.summary.totalMemory,
36
+ :numCpuCores => compute_resource.summary.numCpuCores,
37
+ :numCpuThreads => compute_resource.summary.numCpuThreads,
38
+ :effectiveCpu => compute_resource.summary.effectiveCpu,
39
+ :effectiveMemory => compute_resource.summary.effectiveMemory,
40
+ :numHosts => compute_resource.summary.numHosts,
41
+ :numEffectiveHosts => compute_resource.summary.numEffectiveHosts,
42
+ :overallStatus => compute_resource.summary.overallStatus,
43
+ :overallCpuUsage => overall_usage[:overallCpuUsage],
44
+ :overallMemoryUsage => overall_usage[:overallMemoryUsage],
45
+ :effective => compute_resource.summary.numEffectiveHosts > 0,
46
+ :isSingleHost => compute_resource.summary.numHosts == 1
47
+ }
48
+ end
49
+
50
+ end
51
+ class Mock
52
+ def list_compute_resources(filters = { })
53
+ [
54
+ {
55
+ :id=>"domain-s7",
56
+ :name=>"fake-host",
57
+ :totalCpu=>33504,
58
+ :totalMemory=>154604142592,
59
+ :numCpuCores=>12,
60
+ :numCpuThreads=>24,
61
+ :effectiveCpu=>32247,
62
+ :effectiveMemory=>135733,
63
+ :numHosts=>1,
64
+ :numEffectiveHosts=>1,
65
+ :overallStatus=>"gray",
66
+ :overallCpuUsage=>15682,
67
+ :overallMemoryUsage=>132755,
68
+ :effective=>true,
69
+ :isSingleHost=>true
70
+ }, {
71
+ :id=>"domain-s74",
72
+ :name=>"fake-cluster",
73
+ :totalCpu=>41484,
74
+ :totalMemory=>51525996544,
75
+ :numCpuCores=>12,
76
+ :numCpuThreads=>24,
77
+ :effectiveCpu=>37796,
78
+ :effectiveMemory=>45115,
79
+ :numHosts=>2,
80
+ :numEffectiveHosts=>2,
81
+ :overallStatus=>"gray",
82
+ :overallCpuUsage=>584,
83
+ :overallMemoryUsage=>26422,
84
+ :effective=>true,
85
+ :isSingleHost=>false
86
+ }
87
+ ]
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,21 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
4
+ class Real
5
+ def list_customfields()
6
+ @connection.serviceContent.customFieldsManager.field.map do |customfield|
7
+ {
8
+ :key => customfield.key.to_i,
9
+ :name => customfield.name,
10
+ :type => customfield.type
11
+ }
12
+ end
13
+ end
14
+ end
15
+ class Mock
16
+ def list_vm_customfields()
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,53 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
4
+ class Real
5
+ def list_datacenters filters = {}
6
+ raw_datacenters.map do |dc|
7
+ {
8
+ :id => managed_obj_id(dc),
9
+ :name => dc.name,
10
+ :path => raw_getpathmo(dc),
11
+ :status => dc.overallStatus
12
+ }
13
+ end
14
+ end
15
+
16
+ protected
17
+
18
+ def raw_getpathmo mo
19
+ if mo.parent == nil or mo.parent.name == @connection.rootFolder.name then
20
+ [ mo.name ]
21
+ else
22
+ [ raw_getpathmo(mo.parent), mo.name ].flatten
23
+ end
24
+ end
25
+
26
+ def raw_datacenters folder=nil
27
+ folder ||= @connection.rootFolder
28
+ @raw_datacenters ||= get_raw_datacenters_from_folder folder
29
+ end
30
+
31
+ def get_raw_datacenters_from_folder folder=nil
32
+ folder.childEntity.map do | childE |
33
+ if childE.is_a? RbVmomi::VIM::Datacenter
34
+ childE
35
+ elsif childE.is_a? RbVmomi::VIM::Folder
36
+ get_raw_datacenters_from_folder childE
37
+ end
38
+ end.flatten
39
+ end
40
+
41
+ def find_datacenters name=nil
42
+ name ? [find_raw_datacenter(name)] : raw_datacenters
43
+ end
44
+ end
45
+
46
+ class Mock
47
+ def list_datacenters filters = {}
48
+ [ {:name => "Solutions", :status => "grey"}, {:name => "Solutions2", :status => "green" }]
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,40 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
4
+ class Real
5
+ def list_datastores(filters = { })
6
+ datacenter_name = filters[:datacenter]
7
+ # default to show all datastores
8
+ only_active = filters[:accessible] || false
9
+ raw_datastores(datacenter_name).map do |datastore|
10
+ next if only_active and !datastore.summary.accessible
11
+ datastore_attributes(datastore, datacenter_name)
12
+ end.compact
13
+ end
14
+
15
+ def raw_datastores(datacenter_name)
16
+ find_raw_datacenter(datacenter_name).datastore
17
+ end
18
+ protected
19
+
20
+ def datastore_attributes datastore, datacenter
21
+ {
22
+ :id => managed_obj_id(datastore),
23
+ :name => datastore.name,
24
+ :accessible => datastore.summary.accessible,
25
+ :type => datastore.summary.type,
26
+ :freespace => datastore.summary.freeSpace,
27
+ :capacity => datastore.summary.capacity,
28
+ :uncommitted => datastore.summary.uncommitted,
29
+ :datacenter => datacenter,
30
+ }
31
+ end
32
+ end
33
+ class Mock
34
+ def list_datastores(datacenter_name)
35
+ []
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,44 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
4
+ class Real
5
+ # Grabs all sub folders within a given path folder.
6
+ #
7
+ # ==== Parameters
8
+ # * filters<~Hash>:
9
+ # * :datacenter<~String> - *REQUIRED* Your datacenter where you're
10
+ # looking for folders. Example: 'my-datacenter-name' (passed if you
11
+ # are using the models/collections)
12
+ # eg: vspconn.datacenters.first.vm_folders('mypath')
13
+ # * :path<~String> - Your path where you're looking for
14
+ # more folders, if return = none you will get an error. If you don't
15
+ # define it will look in the main datacenter folder for any folders
16
+ # in that datacenter.
17
+ #
18
+ # Example Usage Testing Only:
19
+ # vspconn = Fog::Compute[:vsphere]
20
+ # mydc = vspconn.datacenters.first
21
+ # folders = mydc.vm_folders
22
+ #
23
+ def list_folders(filters = { })
24
+ path = filters[:path] || filters['path'] || ''
25
+ datacenter_name = filters[:datacenter]
26
+ get_raw_vmfolders(path, datacenter_name).map do |folder|
27
+ folder_attributes(folder, datacenter_name)
28
+ end
29
+ end
30
+
31
+ protected
32
+
33
+ def get_raw_vmfolders(path, datacenter_name)
34
+ folder = get_raw_vmfolder(path, datacenter_name)
35
+ child_folders(folder).flatten.compact
36
+ end
37
+
38
+ def child_folders folder
39
+ [folder, folder.childEntity.grep(RbVmomi::VIM::Folder).map(&method(:child_folders)).flatten]
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,25 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
4
+ class Real
5
+ def list_interface_types(filters={})
6
+ datacenter_name = filters[:datacenter]
7
+ servertype_name = filters[:servertype]
8
+ get_raw_server_type(servertype_name, datacenter_name)[:supportedEthernetCard].map do | nictype |
9
+ next if filters.key?(:id) and filters[:id] != nictype
10
+ interface_type_attributes(nictype, servertype_name, datacenter_name)
11
+ end.compact
12
+ end
13
+
14
+ def interface_type_attributes(nic, servertype, datacenter)
15
+ {
16
+ :id => nic,
17
+ :name => nic,
18
+ :datacenter => datacenter,
19
+ :servertype => servertype
20
+ }
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,38 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
4
+ class Real
5
+ def list_networks(filters = { })
6
+ datacenter_name = filters[:datacenter]
7
+ # default to show all networks
8
+ only_active = filters[:accessible] || false
9
+ raw_networks(datacenter_name).map do |network|
10
+ next if only_active and !network.summary.accessible
11
+ network_attributes(network, datacenter_name)
12
+ end.compact
13
+ end
14
+
15
+ def raw_networks(datacenter_name)
16
+ find_raw_datacenter(datacenter_name).network
17
+ end
18
+
19
+ protected
20
+
21
+ def network_attributes network, datacenter
22
+ {
23
+ :id => managed_obj_id(network),
24
+ :name => network.name,
25
+ :accessible => network.summary.accessible,
26
+ :datacenter => datacenter,
27
+ :virtualswitch => network.class.name == "DistributedVirtualPortgroup" ? network.config.distributedVirtualSwitch.name : nil
28
+ }
29
+ end
30
+ end
31
+ class Mock
32
+ def list_networks(datacenter_name)
33
+ []
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end