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,45 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
4
+ class Real
5
+ def vm_config_vnc(options = { })
6
+ raise ArgumentError, "instance_uuid is a required parameter" unless options.key? 'instance_uuid'
7
+
8
+ search_filter = { :uuid => options['instance_uuid'], 'vmSearch' => true, 'instanceUuid' => true }
9
+ vm_mob_ref = @connection.searchIndex.FindAllByUuid(search_filter).first
10
+ task = vm_mob_ref.ReconfigVM_Task(:spec => {
11
+ :extraConfig => [
12
+ { :key => 'RemoteDisplay.vnc.enabled', :value => options[:enabled] ? 'true' : 'false' },
13
+ { :key => 'RemoteDisplay.vnc.password', :value => options[:password].to_s },
14
+ { :key => 'RemoteDisplay.vnc.port', :value => options[:port].to_s || '5910' }
15
+ ]
16
+ })
17
+ task.wait_for_completion
18
+ { 'task_state' => task.info.state }
19
+ end
20
+
21
+ # return a hash of VNC attributes required to view the console
22
+ def vm_get_vnc uuid
23
+ search_filter = { :uuid => uuid, 'vmSearch' => true, 'instanceUuid' => true }
24
+ vm = @connection.searchIndex.FindAllByUuid(search_filter).first
25
+ Hash[vm.config.extraConfig.map do |config|
26
+ if config.key =~ /^RemoteDisplay\.vnc\.(\w+)$/
27
+ [$1.to_sym, config.value]
28
+ end
29
+ end.compact]
30
+ end
31
+ end
32
+
33
+ class Mock
34
+ def vm_config_vnc(options = { })
35
+ raise ArgumentError, "instance_uuid is a required parameter" unless options.key? 'instance_uuid'
36
+ { 'task_state' => 'success' }
37
+ end
38
+
39
+ def vm_get_vnc uuid
40
+ {:password => 'secret', :port => '5900', :enabled => 'true'}
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,23 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
4
+ class Real
5
+ def vm_destroy(options = {})
6
+ raise ArgumentError, "instance_uuid is a required parameter" unless options.key? 'instance_uuid'
7
+
8
+ vm_mob_ref = get_vm_ref(options['instance_uuid'])
9
+ task = vm_mob_ref.Destroy_Task
10
+ task.wait_for_completion
11
+ { 'task_state' => task.info.state }
12
+ end
13
+ end
14
+
15
+ class Mock
16
+ def vm_destroy(options = {})
17
+ raise ArgumentError, "instance_uuid is a required parameter" unless options.key? 'instance_uuid'
18
+ { 'task_state' => 'success' }
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,47 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
4
+ class Real
5
+ # NOTE: you must be using vsphere_rev 5.0 or greater to use this functionality
6
+ # e.g. Fog::Compute.new(provider: "vsphere", vsphere_rev: "5.5", etc)
7
+ # * options<~Hash>:
8
+ # * 'instance_uuid'<~String> - *REQUIRED* the instance uuid you would like to operate on
9
+ # * 'command'<~String> *REQUIRED* the command to execute
10
+ # * 'args'<~String> arguments to pass the command
11
+ # * 'working_dir'<~String> path to the working directory
12
+ # * 'user'<~String> *REQUIRED* the ssh username you would like to login as
13
+ # * 'password'<~String> *REQUIRED* the ssh password for the user you would like to log in as
14
+ def vm_execute(options = {})
15
+ raise ArgumentError, "instance_uuid is a required parameter" unless options.key? 'instance_uuid'
16
+ raise ArgumentError, "command is a required parameter" unless options.key? 'command'
17
+ raise ArgumentError, "user is a required parameter" unless options.key? 'user'
18
+ raise ArgumentError, "password is a required parameter" unless options.key? 'password'
19
+
20
+ search_filter = { :uuid => options['instance_uuid'], 'vmSearch' => true, 'instanceUuid' => true }
21
+ vm_mob_ref = @connection.searchIndex.FindAllByUuid(search_filter).first
22
+
23
+ auth = RbVmomi::VIM::NamePasswordAuthentication(:interactiveSession => false,
24
+ :username => options['user'],
25
+ :password => options['password'])
26
+
27
+ spec = RbVmomi::VIM::GuestProgramSpec(:programPath => options['command'],
28
+ :arguments => options['args'],
29
+ :workingDirectory => options['working_dir'])
30
+
31
+ gom = @connection.serviceContent.guestOperationsManager
32
+ gom.processManager.StartProgramInGuest(:vm => vm_mob_ref, :auth => auth, :spec => spec)
33
+ end
34
+ end
35
+
36
+ class Mock
37
+ def vm_execute(options = {})
38
+ raise ArgumentError, "instance_uuid is a required parameter" unless options.key? 'instance_uuid'
39
+ raise ArgumentError, "command is a required parameter" unless options.key? 'command'
40
+ raise ArgumentError, "user is a required parameter" unless options.key? 'user'
41
+ raise ArgumentError, "password is a required parameter" unless options.key? 'password'
42
+ return 12345
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,33 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
4
+ class Real
5
+ def vm_migrate(options = {})
6
+ #priority is the only required option, and it has a sane default option.
7
+ priority = options['priority'].nil? ? 'defaultPriority' : options["priority"]
8
+ raise ArgumentError, "instance_uuid is a required parameter" unless options.key? 'instance_uuid'
9
+
10
+ # Find the VM Object
11
+ search_filter = { :uuid => options['instance_uuid'], 'vmSearch' => true, 'instanceUuid' => true }
12
+ vm_mob_ref = @connection.searchIndex.FindAllByUuid(search_filter).first
13
+
14
+ unless vm_mob_ref.kind_of? RbVmomi::VIM::VirtualMachine
15
+ raise Fog::Vsphere::Errors::NotFound,
16
+ "Could not find VirtualMachine with instance uuid #{options['instance_uuid']}"
17
+ end
18
+ task = vm_mob_ref.MigrateVM_Task(:pool => options['pool'], :host => options['host'], :priority => "#{priority}", :state => options['state'] )
19
+ task.wait_for_completion
20
+ { 'task_state' => task.info.state }
21
+ end
22
+ end
23
+
24
+ class Mock
25
+ def vm_migrate(options = {})
26
+ priority = options['priority'].nil? ? 'defaultPriority' : options["priority"]
27
+ raise ArgumentError, "instance_uuid is a required parameter" unless options.key? 'instance_uuid'
28
+ { 'task_state' => 'success' }
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,39 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
4
+ class Real
5
+ def vm_power_off(options = {})
6
+ options = { 'force' => false }.merge(options)
7
+ raise ArgumentError, "instance_uuid is a required parameter" unless options.key? 'instance_uuid'
8
+
9
+ search_filter = { :uuid => options['instance_uuid'], 'vmSearch' => true, 'instanceUuid' => true }
10
+ vm_mob_ref = @connection.searchIndex.FindAllByUuid(search_filter).first
11
+
12
+ if options['force'] then
13
+ task = vm_mob_ref.PowerOffVM_Task
14
+ task.wait_for_completion
15
+ { 'task_state' => task.info.result, 'power_off_type' => 'cut_power' }
16
+ else
17
+ vm_mob_ref.ShutdownGuest
18
+ {
19
+ 'task_state' => "running",
20
+ 'power_off_type' => 'shutdown_guest',
21
+ }
22
+ end
23
+ end
24
+ end
25
+
26
+ class Mock
27
+ def vm_power_off(options = {})
28
+ raise ArgumentError, "instance_uuid is a required parameter" unless options.key? 'instance_uuid'
29
+ vm = get_virtual_machine(options['instance_uuid'])
30
+ vm["power_state"] = "poweredOff"
31
+ {
32
+ 'task_state' => "running",
33
+ 'power_off_type' => options['force'] ? 'cut_power' : 'shutdown_guest',
34
+ }
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,26 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
4
+ class Real
5
+ def vm_power_on(options = {})
6
+ raise ArgumentError, "instance_uuid is a required parameter" unless options.key? 'instance_uuid'
7
+
8
+ search_filter = { :uuid => options['instance_uuid'], 'vmSearch' => true, 'instanceUuid' => true }
9
+ vm_mob_ref = @connection.searchIndex.FindAllByUuid(search_filter).first
10
+
11
+ task = vm_mob_ref.PowerOnVM_Task
12
+ task.wait_for_completion
13
+ # 'success', 'running', 'queued', 'error'
14
+ { 'task_state' => task.info.state }
15
+ end
16
+ end
17
+
18
+ class Mock
19
+ def vm_power_on(options = {})
20
+ raise ArgumentError, "instance_uuid is a required parameter" unless options.key? 'instance_uuid'
21
+ { 'task_state' => 'success' }
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,31 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
4
+ class Real
5
+ def vm_reboot(options = {})
6
+ options = { 'force' => false }.merge(options)
7
+ raise ArgumentError, "instance_uuid is a required parameter" unless options.key? 'instance_uuid'
8
+
9
+ search_filter = { :uuid => options['instance_uuid'], 'vmSearch' => true, 'instanceUuid' => true }
10
+ vm_mob_ref = @connection.searchIndex.FindAllByUuid(search_filter).first
11
+
12
+ if options['force'] then
13
+ task = vm_mob_ref.ResetVM_Task
14
+ task.wait_for_completion
15
+ { 'task_state' => task.info.result, 'reboot_type' => 'reset_power' }
16
+ else
17
+ vm_mob_ref.RebootGuest
18
+ { 'task_state' => "running", 'reboot_type' => 'reboot_guest' }
19
+ end
20
+ end
21
+ end
22
+
23
+ class Mock
24
+ def vm_reboot(options = {})
25
+ raise ArgumentError, "instance_uuid is a required parameter" unless options.key? 'instance_uuid'
26
+ { 'task_state' => "running", 'reboot_type' => options['force'] ? 'reset_power' : 'reboot_guest' }
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,23 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
4
+ class Real
5
+ def vm_reconfig_cpus(options = {})
6
+ raise ArgumentError, "cpus is a required parameter" unless options.key? 'cpus'
7
+ raise ArgumentError, "instance_uuid is a required parameter" unless options.key? 'instance_uuid'
8
+ hardware_spec={'numCPUs' => options['cpus'], 'numCoresPerSocket' => options['corespersocket']}
9
+ vm_reconfig_hardware('instance_uuid' => options['instance_uuid'], 'hardware_spec' => hardware_spec )
10
+ end
11
+ end
12
+
13
+ class Mock
14
+ def vm_reconfig_cpus(options = {})
15
+ raise ArgumentError, "cpus is a required parameter" unless options.key? 'cpus'
16
+ raise ArgumentError, "instance_uuid is a required parameter" unless options.key? 'instance_uuid'
17
+ hardware_spec={'numCPUs' => options['cpus'], 'numCoresPerSocket' => options['corespersocket']}
18
+ vm_reconfig_hardware('instance_uuid' => options['instance_uuid'], 'hardware_spec' => hardware_spec )
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,24 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
4
+ class Real
5
+ def vm_reconfig_hardware(options = {})
6
+ raise ArgumentError, "hardware_spec is a required parameter" unless options.key? 'hardware_spec'
7
+ raise ArgumentError, "instance_uuid is a required parameter" unless options.key? 'instance_uuid'
8
+ vm_mob_ref = get_vm_ref(options['instance_uuid'])
9
+ task = vm_mob_ref.ReconfigVM_Task(:spec => RbVmomi::VIM.VirtualMachineConfigSpec(options['hardware_spec']))
10
+ task.wait_for_completion
11
+ { 'task_state' => task.info.state }
12
+ end
13
+ end
14
+
15
+ class Mock
16
+ def vm_reconfig_hardware(options = {})
17
+ raise ArgumentError, "hardware_spec is a required parameter" unless options.key? 'hardware_spec'
18
+ raise ArgumentError, "instance_uuid is a required parameter" unless options.key? 'instance_uuid'
19
+ { 'task_state' => 'success' }
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,23 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
4
+ class Real
5
+ def vm_reconfig_memory(options = {})
6
+ raise ArgumentError, "memory is a required parameter" unless options.key? 'memory'
7
+ raise ArgumentError, "instance_uuid is a required parameter" unless options.key? 'instance_uuid'
8
+ hardware_spec={'memoryMB' => options['memory']}
9
+ vm_reconfig_hardware('instance_uuid' => options['instance_uuid'], 'hardware_spec' => hardware_spec )
10
+ end
11
+ end
12
+
13
+ class Mock
14
+ def vm_reconfig_memory(options = {})
15
+ raise ArgumentError, "memory is a required parameter" unless options.key? 'memory'
16
+ raise ArgumentError, "instance_uuid is a required parameter" unless options.key? 'instance_uuid'
17
+ hardware_spec={'memoryMB' => options['memory']}
18
+ vm_reconfig_hardware('instance_uuid' => options['instance_uuid'], 'hardware_spec' => hardware_spec )
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,37 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
4
+ class Real
5
+ def vm_take_snapshot(options = {})
6
+ raise ArgumentError, "instance_uuid is a required parameter" unless options.key? 'instance_uuid'
7
+ raise ArgumentError, "name is a required parameter" unless options.key? 'name'
8
+ vm = get_vm_ref(options['instance_uuid'])
9
+ task = vm.CreateSnapshot_Task(
10
+ :name => options['name'],
11
+ :description => options['description'] || '',
12
+ :memory => options['memory'] || true,
13
+ :quiesce => options['quiesce'] || false
14
+ )
15
+
16
+ task.wait_for_completion
17
+
18
+ {
19
+ 'task_state' => task.info.state,
20
+ 'was_cancelled' => task.info.cancelled
21
+ }
22
+ end
23
+ end
24
+
25
+ class Mock
26
+ def vm_take_snapshot(options = {})
27
+ raise ArgumentError, "instance_uuid is a required parameter" unless options.key? 'instance_uuid'
28
+ raise ArgumentError, "name is a required parameter" unless options.key? 'name'
29
+ {
30
+ 'task_state' => 'success',
31
+ 'was_cancelled' => false
32
+ }
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,5 @@
1
+ module Fog
2
+ module Vsphere
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,53 @@
1
+ Shindo.tests('Fog::Compute[:vsphere]', ['vsphere']) do
2
+
3
+ compute = Fog::Compute[:vsphere]
4
+
5
+ tests("| convert_vm_mob_ref_to_attr_hash") do
6
+ # Mock the RbVmomi::VIM::ManagedObject class
7
+ class MockManagedObject
8
+ attr_reader :parent, :_ref
9
+
10
+ def initialize
11
+ @parent = @_ref = 'vm-123'
12
+ end
13
+
14
+ def collect! *pathSet
15
+ { '_ref' => 'vm-123', 'name' => 'fakevm' }
16
+ end
17
+ end
18
+
19
+ fake_vm_mob_ref = MockManagedObject.new
20
+
21
+ tests("When converting an incomplete vm object") do
22
+ test("it should return a Hash") do
23
+ compute.send(:convert_vm_mob_ref_to_attr_hash, fake_vm_mob_ref).kind_of? Hash
24
+ end
25
+ tests("The converted Hash should") do
26
+ attr_hash = compute.send(:convert_vm_mob_ref_to_attr_hash, fake_vm_mob_ref)
27
+ test("have a name") { attr_hash['name'] == 'fakevm' }
28
+ test("have a mo_ref") {attr_hash['mo_ref'] == 'vm-123' }
29
+ test("have an id") { attr_hash['id'] == 'vm-123' }
30
+ test("not have a instance_uuid") { attr_hash['instance_uuid'].nil? }
31
+ end
32
+ end
33
+
34
+ tests("When passed a nil object") do
35
+ attr_hash = compute.send :convert_vm_mob_ref_to_attr_hash, nil
36
+ test("it should return a nil object") do
37
+ attr_hash.nil?
38
+ end
39
+ end
40
+ end
41
+
42
+ tests("Compute attributes") do
43
+ %w{ vsphere_is_vcenter vsphere_rev vsphere_username vsphere_server }.each do |attr|
44
+ test("it should respond to #{attr}") { compute.respond_to? attr }
45
+ end
46
+ end
47
+
48
+ tests("Compute collections") do
49
+ %w{ servers }.each do |collection|
50
+ test("it should respond to #{collection}") { compute.respond_to? collection }
51
+ end
52
+ end
53
+ end
data/tests/helper.rb ADDED
@@ -0,0 +1,8 @@
1
+ begin
2
+ require 'codeclimate-test-reporter'
3
+ CodeClimate::TestReporter.start
4
+ rescue LoadError => e
5
+ $stderr.puts "not recording test coverage: #{e.inspect}"
6
+ end
7
+
8
+ require File.expand_path('../../lib/fog/vsphere', __FILE__)
@@ -0,0 +1,9 @@
1
+ Fog.mock! if ENV['FOG_MOCK'] == 'true'
2
+
3
+ if Fog.mock?
4
+ Fog.credentials = {
5
+ :vsphere_server => 'fake_vsphere_server',
6
+ :vsphere_username => 'fake_vsphere_username',
7
+ :vsphere_password => 'fake_vsphere_password'
8
+ }.merge(Fog.credentials)
9
+ end