fog-vsphere 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +10 -0
  4. data/CONTRIBUTING.md +42 -5
  5. data/README.md +1 -0
  6. data/fog-vsphere.gemspec +3 -1
  7. data/lib/fog/vsphere/compute.rb +21 -0
  8. data/lib/fog/vsphere/models/compute/server.rb +1 -0
  9. data/lib/fog/vsphere/requests/compute/create_vm.rb +1 -1
  10. data/lib/fog/vsphere/requests/compute/get_network.rb +23 -8
  11. data/lib/fog/vsphere/requests/compute/list_networks.rb +1 -1
  12. data/lib/fog/vsphere/requests/compute/update_vm.rb +12 -5
  13. data/lib/fog/vsphere/requests/compute/vm_clone.rb +8 -6
  14. data/lib/fog/vsphere/version.rb +1 -1
  15. metadata +32 -88
  16. data/tests/class_from_string_tests.rb +0 -33
  17. data/tests/compute_tests.rb +0 -53
  18. data/tests/helper.rb +0 -9
  19. data/tests/helpers/mock_helper.rb +0 -9
  20. data/tests/helpers/succeeds_helper.rb +0 -9
  21. data/tests/models/compute/cluster_tests.rb +0 -18
  22. data/tests/models/compute/hosts_tests.rb +0 -11
  23. data/tests/models/compute/rules_tests.rb +0 -28
  24. data/tests/models/compute/server_tests.rb +0 -74
  25. data/tests/models/compute/server_unit_tests.rb +0 -13
  26. data/tests/models/compute/servers_tests.rb +0 -13
  27. data/tests/models/compute/ticket_tests.rb +0 -12
  28. data/tests/models/compute/tickets_tests.rb +0 -8
  29. data/tests/requests/compute/current_time_tests.rb +0 -10
  30. data/tests/requests/compute/folder_destroy_tests.rb +0 -19
  31. data/tests/requests/compute/get_network_tests.rb +0 -55
  32. data/tests/requests/compute/list_child_snapshots_tests.rb +0 -9
  33. data/tests/requests/compute/list_clusters_tests.rb +0 -10
  34. data/tests/requests/compute/list_datastores_tests.rb +0 -17
  35. data/tests/requests/compute/list_hosts_tests.rb +0 -10
  36. data/tests/requests/compute/list_networks_tests.rb +0 -17
  37. data/tests/requests/compute/list_storage_pods_test.rb +0 -9
  38. data/tests/requests/compute/list_virtual_machines_tests.rb +0 -34
  39. data/tests/requests/compute/list_vm_cdroms_tests.rb +0 -9
  40. data/tests/requests/compute/list_vm_snapshots_tests.rb +0 -9
  41. data/tests/requests/compute/modify_vm_cdrom_tests.rb +0 -20
  42. data/tests/requests/compute/revert_to_snapshot_tests.rb +0 -13
  43. data/tests/requests/compute/set_vm_customvalue_tests.rb +0 -18
  44. data/tests/requests/compute/update_vm_tests.rb +0 -13
  45. data/tests/requests/compute/vm_clone_tests.rb +0 -55
  46. data/tests/requests/compute/vm_config_vnc_tests.rb +0 -18
  47. data/tests/requests/compute/vm_destroy_tests.rb +0 -14
  48. data/tests/requests/compute/vm_migrate_tests.rb +0 -15
  49. data/tests/requests/compute/vm_power_off_tests.rb +0 -24
  50. data/tests/requests/compute/vm_power_on_tests.rb +0 -15
  51. data/tests/requests/compute/vm_reboot_tests.rb +0 -24
  52. data/tests/requests/compute/vm_reconfig_cdrom_tests.rb +0 -14
  53. data/tests/requests/compute/vm_reconfig_cpus_tests.rb +0 -17
  54. data/tests/requests/compute/vm_reconfig_hardware_tests.rb +0 -17
  55. data/tests/requests/compute/vm_reconfig_memory_tests.rb +0 -17
  56. data/tests/requests/compute/vm_suspend_tests.rb +0 -23
  57. data/tests/requests/compute/vm_take_snapshot_tests.rb +0 -17
@@ -1,33 +0,0 @@
1
- require_relative './helper'
2
-
3
- class A; class B; class C; end; end; end
4
-
5
- class TestClassFromString < Minitest::Test
6
- def test_empty_string
7
- assert_nil(Fog::Vsphere.class_from_string(''))
8
- end
9
-
10
- def test_nil
11
- assert_nil(Fog::Vsphere.class_from_string(nil))
12
- end
13
-
14
- def test_name_as_class
15
- assert_equal(A, Fog::Vsphere.class_from_string(A))
16
- end
17
-
18
- def test_name_as_string
19
- assert_equal(A, Fog::Vsphere.class_from_string('A'))
20
- end
21
-
22
- def test_unexpected_input
23
- assert_nil(Fog::Vsphere.class_from_string(8))
24
- end
25
-
26
- def test_nested_class_without_default_path
27
- assert_equal(A::B::C, Fog::Vsphere.class_from_string(A::B::C))
28
- end
29
-
30
- def test_nested_class_with_default_path
31
- assert_equal(A::B::C, Fog::Vsphere.class_from_string('C', 'A::B'))
32
- end
33
- end
@@ -1,53 +0,0 @@
1
- Shindo.tests('Fog::Compute[:vsphere]', ['vsphere']) do
2
- compute = Fog::Compute[:vsphere]
3
-
4
- tests('| convert_vm_mob_ref_to_attr_hash') do
5
- # Mock the RbVmomi::VIM::ManagedObject class
6
- class MockManagedObject
7
- attr_reader :parent, :_ref
8
-
9
- def initialize
10
- @parent = @_ref = 'vm-123'
11
- end
12
-
13
- # rubocop:disable Style/VariableName
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).is_a? 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
@@ -1,9 +0,0 @@
1
- require 'simplecov'
2
- SimpleCov.start
3
-
4
- require 'mocha/api'
5
- Shindo::Tests.send(:include, Mocha::API)
6
-
7
- require 'minitest/autorun'
8
-
9
- require File.expand_path('../../lib/fog/vsphere', __FILE__)
@@ -1,9 +0,0 @@
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
@@ -1,9 +0,0 @@
1
- module Shindo
2
- class Tests
3
- def succeeds
4
- test('succeeds') do
5
- !!instance_eval(&Proc.new)
6
- end
7
- end
8
- end
9
- end
@@ -1,18 +0,0 @@
1
- Shindo.tests('Fog::Compute[:vsphere] | cluster collection', ['vsphere']) do
2
- compute = Fog::Compute[:vsphere]
3
-
4
- tests('Cluster collection') do
5
- clusters = compute.datacenters.first.clusters
6
-
7
- test('should not be empty') { !clusters.empty? }
8
- test('should be a kind of Fog::Vsphere::Compute::Clusters') { clusters.is_a? Fog::Vsphere::Compute::Clusters }
9
- test('should get a cluster') { clusters.get('Solutionscluster').id == '1d4d9a3f-e4e8-4c40-b7fc-263850068fa4' }
10
- end
11
-
12
- tests('A cluster should') do
13
- cluster = compute.datacenters.first.clusters.get('Solutionscluster')
14
-
15
- test('have datastores') { cluster.datastores.first.is_a? Fog::Vsphere::Compute::Datastore }
16
- test('have networks') { cluster.networks.first.is_a? Fog::Vsphere::Compute::Network }
17
- end
18
- end
@@ -1,11 +0,0 @@
1
- Shindo.tests('Fog::Compute[:vsphere] | hosts collection', ['vsphere']) do
2
- compute = Fog::Compute[:vsphere]
3
- cluster = compute.datacenters.first.clusters.get('Solutionscluster')
4
- hosts = cluster.hosts
5
-
6
- tests('The hosts collection') do
7
- test('should not be empty') { !hosts.empty? }
8
- test('should be a kind of Fog::Vsphere::Compute::Hosts') { hosts.is_a? Fog::Vsphere::Compute::Hosts }
9
- test('should get hosts') { hosts.get('host1.example.com').name == 'host1.example.com' }
10
- end
11
- end
@@ -1,28 +0,0 @@
1
- Shindo.tests('Fog::Compute[:vsphere] | rules collection', ['vsphere']) do
2
- compute = Fog::Compute[:vsphere]
3
- cluster = compute.datacenters.first.clusters.get('Solutionscluster')
4
- servers = compute.servers
5
- rules = cluster.rules
6
-
7
- tests('The rules collection') do
8
- test('should not be empty') { !rules.empty? }
9
- test('should be a kind of Fog::Vsphere::Compute::Rules') { rules.is_a? Fog::Vsphere::Compute::Rules }
10
- test('should get rules') { rules.get('anti-affinity-foo').key == 4242 }
11
- test('should destroy rules') { rules.first.destroy; rules.reload; rules.empty? }
12
- test('should create rules') do
13
- r = rules.new(name: 'affinity-foo',
14
- enabled: true,
15
- type: RbVmomi::VIM::ClusterAffinityRuleSpec)
16
- r.vms = [servers.get('5032c8a5-9c5e-ba7a-3804-832a03e16381'), servers.get('502916a3-b42e-17c7-43ce-b3206e9524dc')]
17
- r.save
18
- rules.reload
19
- rules.get('affinity-foo').key > 0
20
- end
21
- raises(ArgumentError, 'should not create rules with <2 vms') do
22
- rules.create(name: 'affinity-foo',
23
- enabled: true,
24
- type: RbVmomi::VIM::ClusterAffinityRuleSpec,
25
- vm_ids: ['5032c8a5-9c5e-ba7a-3804-832a03e16381'])
26
- end
27
- end
28
- end
@@ -1,74 +0,0 @@
1
- Shindo.tests('Fog::Compute[:vsphere] | server model', ['vsphere']) do
2
- servers = Fog::Compute[:vsphere].servers
3
- server = servers.last
4
-
5
- tests('The server model should') do
6
- tests('have the action') do
7
- test('reload') { server.respond_to? 'reload' }
8
- %w[stop suspend destroy reboot].each do |action|
9
- test(action) { server.respond_to? action }
10
- test("#{action} returns successfully") { server.send(action.to_sym) ? true : false }
11
- end
12
- test('start') { server.respond_to?('start') }
13
- test('start returns false, because it is already poweredOn') { server.start ? true : false }
14
- test('guest_processes') { server.respond_to? 'guest_processes' }
15
- test('take_snapshot') do
16
- test('responds') { server.respond_to? 'take_snapshot' }
17
- test('returns successfully') { server.take_snapshot('name' => 'foobar').is_a? Hash }
18
- end
19
- test('snapshots') do
20
- test('responds') { server.respond_to? 'snapshots' }
21
- test('returns successfully') { server.snapshots.is_a? Fog::Vsphere::Compute::Snapshots }
22
- end
23
- test('find_snapshot') do
24
- test('responds') { server.respond_to? 'find_snapshot' }
25
- test('returns successfully') do
26
- server.find_snapshot('snapshot-0101').is_a? Fog::Vsphere::Compute::Snapshot
27
- end
28
- test('returns correct snapshot') do
29
- server.find_snapshot('snapshot-0101').ref == 'snapshot-0101'
30
- end
31
- end
32
- tests('revert_snapshot') do
33
- test('responds') { server.respond_to? 'revert_snapshot' }
34
- tests('returns correctly') do
35
- test('when correct input given') { server.revert_snapshot('snapshot-0101').is_a? Hash }
36
- test('when incorrect input given') do
37
- raises(ArgumentError) { server.revert_snapshot(1) }
38
- end
39
- end
40
- end
41
- test('tickets') do
42
- test('acquire ticket successfully') { server.acquire_ticket.is_a? Fog::Vsphere::Compute::Ticket }
43
- end
44
- end
45
- tests('have attributes') do
46
- model_attribute_hash = server.attributes
47
- attributes = %i[id
48
- instance_uuid
49
- uuid
50
- power_state
51
- tools_state
52
- mo_ref
53
- tools_version
54
- hostname
55
- mac_addresses
56
- operatingsystem
57
- connection_state
58
- hypervisor
59
- name
60
- public_ip_address]
61
- tests('The server model should respond to') do
62
- attributes.each do |attribute|
63
- test(attribute.to_s) { server.respond_to? attribute }
64
- end
65
- end
66
- tests('The attributes hash should have key') do
67
- attributes.each do |attribute|
68
- test(attribute.to_s) { model_attribute_hash.key? attribute }
69
- end
70
- end
71
- end
72
- test('be a kind of Fog::Vsphere::Compute::Server') { server.is_a? Fog::Vsphere::Compute::Server }
73
- end
74
- end
@@ -1,13 +0,0 @@
1
- require_relative '../../helper'
2
-
3
- require 'fog/vsphere/models/compute/server'
4
-
5
- class TestServer < Minitest::Test
6
- def test_tools_installed
7
- server = Fog::Vsphere::Compute::Server.new
8
- server.tools_state = 'toolsNotRunning'
9
- server.tools_version = 'guestToolsNotInstalled'
10
-
11
- assert_equal(false, server.tools_installed?)
12
- end
13
- end
@@ -1,13 +0,0 @@
1
- Shindo.tests('Fog::Compute[:vsphere] | servers collection', ['vsphere']) do
2
- servers = Fog::Compute[:vsphere].servers
3
-
4
- tests('The servers collection') do
5
- test('should not be empty') { !servers.empty? }
6
- test('should be a kind of Fog::Vsphere::Compute::Servers') { servers.is_a? Fog::Vsphere::Compute::Servers }
7
- tests('should be able to reload itself').succeeds { servers.reload }
8
- tests('should be able to get a model') do
9
- tests('by managed object reference').succeeds { servers.get 'jefftest' }
10
- tests('by instance uuid').succeeds { servers.get '5032c8a5-9c5e-ba7a-3804-832a03e16381' }
11
- end
12
- end
13
- end
@@ -1,12 +0,0 @@
1
- Shindo.tests('Fog::Compute[:vsphere] | hosts collection', ['vsphere']) do
2
- servers = Fog::Compute[:vsphere].servers
3
- server = servers.last
4
- ticket = server.acquire_ticket
5
-
6
- tests('A ticket') do
7
- test('should have a ticket') { !ticket.ticket.empty? }
8
- test('should have a host') { !ticket.host.empty? }
9
- test('should have a port') { ticket.port.is_a?(Integer) }
10
- test('should have a ssl ssl_thumbprint') { !ticket.ssl_thumbprint.empty? }
11
- end
12
- end
@@ -1,8 +0,0 @@
1
- Shindo.tests('Fog::Compute[:vsphere] | hosts collection', ['vsphere']) do
2
- service = Fog::Compute[:vsphere]
3
- server = service.servers.last
4
-
5
- tests('The tickets collection') do
6
- test('should create a ticket for a server') { service.tickets(server: server).create.is_a? Fog::Vsphere::Compute::Ticket }
7
- end
8
- end
@@ -1,10 +0,0 @@
1
- Shindo.tests('Fog::Compute[:vsphere] | current_time request', ['vsphere']) do
2
- compute = Fog::Compute[:vsphere]
3
-
4
- tests('The response should') do
5
- response = compute.current_time
6
- test('be a kind of Hash') { response.is_a? Hash }
7
- test('have a current_time key') { response.key? 'current_time' }
8
- test('have a current_time key with a Time value') { response['current_time'].is_a? Time }
9
- end
10
- end
@@ -1,19 +0,0 @@
1
- Shindo.tests('Fog::Compute[:vsphere] | folder_destroy request', ['vsphere']) do
2
- compute = Fog::Compute[:vsphere]
3
-
4
- empty_folder = '/Solutions/empty'
5
- full_folder = '/Solutions/wibble'
6
- datacenter = 'Solutions'
7
-
8
- tests('The response should') do
9
- response = compute.folder_destroy(empty_folder, datacenter)
10
- test('be a kind of Hash') { response.is_a? Hash }
11
- test('should have a task_state key') { response.key? 'task_state' }
12
- end
13
-
14
- tests('When folder is not empty') do
15
- raises(Fog::Vsphere::Errors::ServiceError, 'raises ServiceError') do
16
- compute.folder_destroy(full_folder, datacenter)
17
- end
18
- end
19
- end
@@ -1,55 +0,0 @@
1
- require 'ostruct'
2
-
3
- Shindo.tests('Fog::Compute[:vsphere] | get_network request', ['vsphere']) do
4
- compute = Fog::Compute[:vsphere]
5
-
6
- before do
7
- mocha_setup
8
- end
9
- after do
10
- mocha_teardown
11
- end
12
-
13
- def make_fake_dvs(args = {})
14
- config = OpenStruct.new(
15
- distributedVirtualSwitch: OpenStruct.new(name: args[:dvs_name])
16
- )
17
- network = stub(args.merge(config: config))
18
- network.expects('is_a?')
19
- .with(RbVmomi::VIM::DistributedVirtualPortgroup)
20
- .returns(true)
21
- network
22
- end
23
-
24
- def fake_networks
25
- [
26
- OpenStruct.new(name: 'non-dvs'),
27
- make_fake_dvs(name: 'web1', dvs_name: 'dvs5', key: '4001'),
28
- make_fake_dvs(name: 'web1', dvs_name: 'dvs11', key: '4001'),
29
- make_fake_dvs(name: 'other', dvs_name: 'other', key: '4001')
30
- ]
31
- end
32
-
33
- tests('#choose_finder should') do
34
- test('choose the network based on network name and dvs name') do
35
- finder = compute.send(:choose_finder, 'web1', 'dvs11')
36
- found_network = fake_networks.find { |n| finder.call(n) }
37
- found_network.name == 'web1' && found_network.dvs_name == 'dvs11'
38
- end
39
- test('choose the network based on network name and any dvs') do
40
- finder = compute.send(:choose_finder, 'web1', :dvs)
41
- found_network = fake_networks.find { |n| finder.call(n) }
42
- found_network.name == 'web1' && found_network.dvs_name == 'dvs5'
43
- end
44
- test('choose the network based on network name only') do
45
- finder = compute.send(:choose_finder, 'other', nil)
46
- found_network = fake_networks.find { |n| finder.call(n) }
47
- found_network.name == 'other' && found_network.dvs_name == 'other'
48
- end
49
- test('choose the network based on network name only for non-dvs') do
50
- finder = compute.send(:choose_finder, 'non-dvs', nil)
51
- found_network = fake_networks.find { |n| finder.call(n) }
52
- found_network.name == 'non-dvs' && found_network.class.name.to_s == 'OpenStruct'
53
- end
54
- end
55
- end
@@ -1,9 +0,0 @@
1
- Shindo.tests('Fog::Compute[:vsphere] | list_child_snapshots request', ['vsphere']) do
2
- compute = Fog::Compute[:vsphere]
3
-
4
- tests('The response should') do
5
- response = compute.list_child_snapshots('snapshot-0101')
6
- test('be a kind of Array') { response.is_a? Array }
7
- test('it should contains Hashes') { response.all? { |i| Hash === i } }
8
- end
9
- end
@@ -1,10 +0,0 @@
1
- Shindo.tests('Fog::Compute[:vsphere] | list_clusters request', ['vsphere']) do
2
- tests('When listing all clusters') do
3
- response = Fog::Compute[:vsphere].list_clusters
4
- test('Clusters extracted from folders... ') { response.length == 4 }
5
-
6
- tests('The response data format ...') do
7
- test('be a kind of Hash') { response.is_a? Array }
8
- end
9
- end
10
- end
@@ -1,17 +0,0 @@
1
- Shindo.tests('Fog::Compute[:vsphere] | list_datastores request', ['vsphere']) do
2
- compute = Fog::Compute[:vsphere]
3
-
4
- tests('The response with datastore filter should') do
5
- response = compute.list_datastores(datacenter: 'Solutions')
6
- test('be a kind of Array') { response.is_a? Array }
7
- test('contain Hashes') { response.all? { |i| Hash === i } }
8
- test('have 2 elements') { response.length == 2 }
9
- end
10
-
11
- tests('The response with cluster filter should') do
12
- response = compute.list_datastores(datacenter: 'Solutions', cluster: 'Solutionscluster')
13
- test('be a kind of Array') { response.is_a? Array }
14
- test('contain Hashes') { response.all? { |i| Hash === i } }
15
- test('have a single element') { response.length == 1 }
16
- end
17
- end
@@ -1,10 +0,0 @@
1
- Shindo.tests('Fog::Compute[:vsphere] | list_hosts request', ['vsphere']) do
2
- compute = Fog::Compute[:vsphere]
3
-
4
- tests('The response should') do
5
- response = compute.list_hosts(datacenter: 'Solutions', cluster: 'Solutionscluster')
6
- test('be a kind of Array') { response.is_a? Array }
7
- test('contain Hashes') { response.all? { |i| Hash === i } }
8
- test('have 1 element') { response.length == 1 }
9
- end
10
- end