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.
- checksums.yaml +4 -4
- data/.rubocop.yml +8 -0
- data/.rubocop_todo.yml +217 -0
- data/.travis.yml +1 -0
- data/CHANGELOG.md +4 -0
- data/Rakefile +10 -1
- data/fog-vsphere.gemspec +2 -2
- data/lib/fog/bin/vsphere.rb +1 -1
- data/lib/fog/vsphere/compute.rb +320 -301
- data/lib/fog/vsphere/models/compute/cdrom.rb +10 -10
- data/lib/fog/vsphere/models/compute/cdroms.rb +2 -2
- data/lib/fog/vsphere/models/compute/cluster.rb +20 -20
- data/lib/fog/vsphere/models/compute/clusters.rb +1 -1
- data/lib/fog/vsphere/models/compute/customfields.rb +4 -4
- data/lib/fog/vsphere/models/compute/customvalues.rb +8 -8
- data/lib/fog/vsphere/models/compute/datacenter.rb +16 -16
- data/lib/fog/vsphere/models/compute/datastores.rb +1 -1
- data/lib/fog/vsphere/models/compute/folder.rb +2 -2
- data/lib/fog/vsphere/models/compute/folders.rb +2 -2
- data/lib/fog/vsphere/models/compute/hosts.rb +4 -4
- data/lib/fog/vsphere/models/compute/interface.rb +12 -12
- data/lib/fog/vsphere/models/compute/interfaces.rb +14 -16
- data/lib/fog/vsphere/models/compute/interfacetype.rb +2 -2
- data/lib/fog/vsphere/models/compute/interfacetypes.rb +6 -8
- data/lib/fog/vsphere/models/compute/networks.rb +1 -1
- data/lib/fog/vsphere/models/compute/resource_pools.rb +1 -1
- data/lib/fog/vsphere/models/compute/rule.rb +8 -9
- data/lib/fog/vsphere/models/compute/rules.rb +9 -10
- data/lib/fog/vsphere/models/compute/scsicontroller.rb +1 -1
- data/lib/fog/vsphere/models/compute/server.rb +68 -80
- data/lib/fog/vsphere/models/compute/servers.rb +12 -13
- data/lib/fog/vsphere/models/compute/servertype.rb +6 -6
- data/lib/fog/vsphere/models/compute/servertypes.rb +2 -2
- data/lib/fog/vsphere/models/compute/snapshot.rb +5 -6
- data/lib/fog/vsphere/models/compute/snapshots.rb +1 -1
- data/lib/fog/vsphere/models/compute/ticket.rb +0 -1
- data/lib/fog/vsphere/models/compute/volume.rb +12 -14
- data/lib/fog/vsphere/models/compute/volumes.rb +10 -10
- data/lib/fog/vsphere/requests/compute/cloudinit_to_customspec.rb +8 -8
- data/lib/fog/vsphere/requests/compute/create_folder.rb +5 -5
- data/lib/fog/vsphere/requests/compute/create_group.rb +16 -16
- data/lib/fog/vsphere/requests/compute/create_rule.rb +13 -13
- data/lib/fog/vsphere/requests/compute/create_vm.rb +117 -119
- data/lib/fog/vsphere/requests/compute/destroy_group.rb +8 -8
- data/lib/fog/vsphere/requests/compute/destroy_rule.rb +8 -8
- data/lib/fog/vsphere/requests/compute/folder_destroy.rb +3 -3
- data/lib/fog/vsphere/requests/compute/get_cluster.rb +2 -2
- data/lib/fog/vsphere/requests/compute/get_compute_resource.rb +16 -16
- data/lib/fog/vsphere/requests/compute/get_datacenter.rb +7 -7
- data/lib/fog/vsphere/requests/compute/get_datastore.rb +1 -2
- data/lib/fog/vsphere/requests/compute/get_folder.rb +24 -24
- data/lib/fog/vsphere/requests/compute/get_host.rb +2 -3
- data/lib/fog/vsphere/requests/compute/get_interface_type.rb +6 -6
- data/lib/fog/vsphere/requests/compute/get_network.rb +7 -10
- data/lib/fog/vsphere/requests/compute/get_resource_pool.rb +1 -2
- data/lib/fog/vsphere/requests/compute/get_server_type.rb +14 -14
- data/lib/fog/vsphere/requests/compute/get_storage_pod.rb +2 -2
- data/lib/fog/vsphere/requests/compute/get_template.rb +1 -2
- data/lib/fog/vsphere/requests/compute/get_virtual_machine.rb +26 -26
- data/lib/fog/vsphere/requests/compute/get_vm_first_scsi_controller.rb +6 -7
- data/lib/fog/vsphere/requests/compute/host_finish_maintenance.rb +1 -1
- data/lib/fog/vsphere/requests/compute/host_shutdown.rb +1 -1
- data/lib/fog/vsphere/requests/compute/host_start_maintenance.rb +1 -1
- data/lib/fog/vsphere/requests/compute/list_child_snapshots.rb +37 -39
- data/lib/fog/vsphere/requests/compute/list_clusters.rb +8 -9
- data/lib/fog/vsphere/requests/compute/list_compute_resources.rb +57 -59
- data/lib/fog/vsphere/requests/compute/list_customfields.rb +5 -6
- data/lib/fog/vsphere/requests/compute/list_datacenters.rb +17 -17
- data/lib/fog/vsphere/requests/compute/list_datastores.rb +16 -15
- data/lib/fog/vsphere/requests/compute/list_folders.rb +4 -4
- data/lib/fog/vsphere/requests/compute/list_groups.rb +5 -5
- data/lib/fog/vsphere/requests/compute/list_hosts.rb +30 -14
- data/lib/fog/vsphere/requests/compute/list_interface_types.rb +7 -7
- data/lib/fog/vsphere/requests/compute/list_networks.rb +12 -16
- data/lib/fog/vsphere/requests/compute/list_processes.rb +14 -14
- data/lib/fog/vsphere/requests/compute/list_resource_pools.rb +13 -14
- data/lib/fog/vsphere/requests/compute/list_rules.rb +4 -4
- data/lib/fog/vsphere/requests/compute/list_server_types.rb +24 -26
- data/lib/fog/vsphere/requests/compute/list_storage_pods.rb +8 -8
- data/lib/fog/vsphere/requests/compute/list_templates.rb +4 -5
- data/lib/fog/vsphere/requests/compute/list_virtual_machines.rb +15 -15
- data/lib/fog/vsphere/requests/compute/list_vm_cdroms.rb +16 -12
- data/lib/fog/vsphere/requests/compute/list_vm_customvalues.rb +3 -4
- data/lib/fog/vsphere/requests/compute/list_vm_interfaces.rb +54 -56
- data/lib/fog/vsphere/requests/compute/list_vm_scsi_controllers.rb +7 -7
- data/lib/fog/vsphere/requests/compute/list_vm_snapshots.rb +36 -36
- data/lib/fog/vsphere/requests/compute/list_vm_volumes.rb +43 -36
- data/lib/fog/vsphere/requests/compute/modify_vm_cdrom.rb +4 -4
- data/lib/fog/vsphere/requests/compute/modify_vm_controller.rb +2 -2
- data/lib/fog/vsphere/requests/compute/modify_vm_interface.rb +26 -19
- data/lib/fog/vsphere/requests/compute/modify_vm_volume.rb +7 -7
- data/lib/fog/vsphere/requests/compute/revert_to_snapshot.rb +2 -2
- data/lib/fog/vsphere/requests/compute/set_vm_customvalue.rb +2 -2
- data/lib/fog/vsphere/requests/compute/update_vm.rb +111 -0
- data/lib/fog/vsphere/requests/compute/upload_iso.rb +10 -10
- data/lib/fog/vsphere/requests/compute/vm_acquire_ticket.rb +3 -3
- data/lib/fog/vsphere/requests/compute/vm_clone.rb +245 -247
- data/lib/fog/vsphere/requests/compute/vm_config_vnc.rb +15 -15
- data/lib/fog/vsphere/requests/compute/vm_destroy.rb +2 -2
- data/lib/fog/vsphere/requests/compute/vm_execute.rb +16 -16
- data/lib/fog/vsphere/requests/compute/vm_migrate.rb +11 -11
- data/lib/fog/vsphere/requests/compute/vm_power_off.rb +8 -8
- data/lib/fog/vsphere/requests/compute/vm_power_on.rb +2 -2
- data/lib/fog/vsphere/requests/compute/vm_reboot.rb +5 -5
- data/lib/fog/vsphere/requests/compute/vm_reconfig_cdrom.rb +11 -11
- data/lib/fog/vsphere/requests/compute/vm_reconfig_cpus.rb +8 -8
- data/lib/fog/vsphere/requests/compute/vm_reconfig_hardware.rb +6 -6
- data/lib/fog/vsphere/requests/compute/vm_reconfig_memory.rb +8 -8
- data/lib/fog/vsphere/requests/compute/vm_reconfig_volumes.rb +14 -16
- data/lib/fog/vsphere/requests/compute/vm_relocate.rb +8 -8
- data/lib/fog/vsphere/requests/compute/vm_remove_snapshot.rb +2 -2
- data/lib/fog/vsphere/requests/compute/vm_rename.rb +5 -5
- data/lib/fog/vsphere/requests/compute/vm_revert_snapshot.rb +1 -1
- data/lib/fog/vsphere/requests/compute/vm_take_snapshot.rb +8 -8
- data/lib/fog/vsphere/version.rb +1 -1
- data/tests/compute_tests.rb +16 -17
- data/tests/helpers/mock_helper.rb +3 -3
- data/tests/models/compute/cluster_tests.rb +4 -5
- data/tests/models/compute/hosts_tests.rb +2 -4
- data/tests/models/compute/rules_tests.rb +10 -16
- data/tests/models/compute/server_tests.rb +30 -31
- data/tests/models/compute/servers_tests.rb +2 -4
- data/tests/models/compute/ticket_tests.rb +4 -6
- data/tests/models/compute/tickets_tests.rb +1 -3
- data/tests/requests/compute/current_time_tests.rb +2 -4
- data/tests/requests/compute/folder_destroy_tests.rb +5 -7
- data/tests/requests/compute/get_network_tests.rb +20 -23
- data/tests/requests/compute/list_child_snapshots_tests.rb +1 -2
- data/tests/requests/compute/list_clusters_tests.rb +5 -6
- data/tests/requests/compute/list_datastores_tests.rb +6 -7
- data/tests/requests/compute/list_hosts_tests.rb +3 -4
- data/tests/requests/compute/list_networks_tests.rb +6 -7
- data/tests/requests/compute/list_storage_pods_test.rb +3 -4
- data/tests/requests/compute/list_virtual_machines_tests.rb +16 -20
- data/tests/requests/compute/list_vm_cdroms_tests.rb +1 -2
- data/tests/requests/compute/list_vm_snapshots_tests.rb +1 -2
- data/tests/requests/compute/modify_vm_cdrom_tests.rb +3 -4
- data/tests/requests/compute/revert_to_snapshot_tests.rb +2 -4
- data/tests/requests/compute/set_vm_customvalue_tests.rb +0 -2
- data/tests/requests/compute/update_vm_tests.rb +13 -0
- data/tests/requests/compute/vm_clone_tests.rb +20 -20
- data/tests/requests/compute/vm_config_vnc_tests.rb +3 -4
- data/tests/requests/compute/vm_destroy_tests.rb +1 -4
- data/tests/requests/compute/vm_migrate_tests.rb +1 -2
- data/tests/requests/compute/vm_power_off_tests.rb +2 -4
- data/tests/requests/compute/vm_power_on_tests.rb +1 -3
- data/tests/requests/compute/vm_reboot_tests.rb +2 -4
- data/tests/requests/compute/vm_reconfig_cdrom_tests.rb +2 -3
- data/tests/requests/compute/vm_reconfig_cpus_tests.rb +1 -3
- data/tests/requests/compute/vm_reconfig_hardware_tests.rb +2 -4
- data/tests/requests/compute/vm_reconfig_memory_tests.rb +1 -3
- data/tests/requests/compute/vm_take_snapshot_tests.rb +1 -3
- metadata +9 -4
@@ -8,7 +8,7 @@ module Fog
|
|
8
8
|
attr_accessor :datacenter, :cluster
|
9
9
|
|
10
10
|
def all(filters = {})
|
11
|
-
load service.list_resource_pools(filters.merge(:
|
11
|
+
load service.list_resource_pools(filters.merge(datacenter: datacenter, cluster: cluster))
|
12
12
|
end
|
13
13
|
|
14
14
|
def get(id)
|
@@ -4,7 +4,7 @@ module Fog
|
|
4
4
|
# ClusterRuleInfo
|
5
5
|
class Rule < Fog::Model
|
6
6
|
identity :key
|
7
|
-
|
7
|
+
|
8
8
|
attribute :datacenter
|
9
9
|
attribute :cluster
|
10
10
|
attribute :name
|
@@ -15,32 +15,31 @@ module Fog
|
|
15
15
|
# - RbVmomi::VIM::ClusterVmHostRuleInfo
|
16
16
|
attribute :type
|
17
17
|
attribute :vm_ids
|
18
|
-
|
18
|
+
|
19
19
|
def vms
|
20
|
-
vm_ids.map {|id| service.servers.get(id, datacenter) }
|
20
|
+
vm_ids.map { |id| service.servers.get(id, datacenter) }
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def vms=(vms)
|
24
24
|
self.vm_ids = vms.map(&:instance_uuid)
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
def save
|
28
28
|
requires :datacenter, :cluster, :name, :enabled, :type, :vm_ids
|
29
29
|
if vm_ids.length < 2
|
30
|
-
raise ArgumentError,
|
30
|
+
raise ArgumentError, 'A rule must have at least 2 VMs'
|
31
31
|
end
|
32
32
|
if persisted?
|
33
|
-
raise
|
33
|
+
raise 'Update is not supported yet'
|
34
34
|
else
|
35
35
|
self.key = service.create_rule(attributes)
|
36
36
|
end
|
37
37
|
reload
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def destroy
|
41
41
|
service.destroy_rule(attributes)
|
42
42
|
end
|
43
|
-
|
44
43
|
end
|
45
44
|
end
|
46
45
|
end
|
@@ -3,27 +3,26 @@ module Fog
|
|
3
3
|
class Vsphere
|
4
4
|
class Rules < Fog::Collection
|
5
5
|
autoload :Rule, File.expand_path('../rule', __FILE__)
|
6
|
-
|
6
|
+
|
7
7
|
model Fog::Compute::Vsphere::Rule
|
8
8
|
attribute :datacenter
|
9
9
|
attribute :cluster
|
10
|
-
|
11
|
-
def all(
|
10
|
+
|
11
|
+
def all(_filters = {})
|
12
12
|
requires :datacenter, :cluster
|
13
|
-
load service.list_rules(:
|
13
|
+
load service.list_rules(datacenter: datacenter, cluster: cluster)
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def get(key_or_name)
|
17
|
-
all.find {|rule| [rule.key, rule.name].include? key_or_name }
|
18
|
-
raise
|
17
|
+
all.find { |rule| [rule.key, rule.name].include? key_or_name } ||
|
18
|
+
raise(Fog::Compute::Vsphere::NotFound, "no such rule #{key_or_name}")
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
# Pass datacenter/cluster to every new rule
|
22
|
-
def new(attributes={})
|
22
|
+
def new(attributes = {})
|
23
23
|
requires :datacenter, :cluster
|
24
24
|
super(attributes.merge(datacenter: datacenter, cluster: cluster))
|
25
25
|
end
|
26
|
-
|
27
26
|
end
|
28
27
|
end
|
29
28
|
end
|
@@ -24,12 +24,12 @@ module Fog
|
|
24
24
|
attribute :uuid
|
25
25
|
attribute :hostname
|
26
26
|
attribute :operatingsystem
|
27
|
-
attribute :public_ip_address, :
|
28
|
-
attribute :power_state, :
|
29
|
-
attribute :tools_state, :
|
27
|
+
attribute :public_ip_address, aliases: 'ipaddress'
|
28
|
+
attribute :power_state, aliases: 'power'
|
29
|
+
attribute :tools_state, aliases: 'tools'
|
30
30
|
attribute :tools_version
|
31
|
-
attribute :mac_addresses, :
|
32
|
-
attribute :hypervisor, :
|
31
|
+
attribute :mac_addresses, aliases: 'macs'
|
32
|
+
attribute :hypervisor, aliases: 'host'
|
33
33
|
attribute :connection_state
|
34
34
|
attribute :mo_ref
|
35
35
|
attribute :path
|
@@ -39,20 +39,20 @@ module Fog
|
|
39
39
|
attribute :interfaces
|
40
40
|
attribute :volumes
|
41
41
|
attribute :customvalues
|
42
|
-
attribute :overall_status, :
|
42
|
+
attribute :overall_status, aliases: 'status'
|
43
43
|
attribute :cluster
|
44
44
|
attribute :datacenter
|
45
45
|
attribute :resource_pool
|
46
46
|
attribute :instance_uuid # move this --> id
|
47
47
|
attribute :guest_id
|
48
48
|
attribute :hardware_version
|
49
|
-
attribute :scsi_controllers, :
|
49
|
+
attribute :scsi_controllers, type: :array
|
50
50
|
attribute :cpuHotAddEnabled
|
51
51
|
attribute :memoryHotAddEnabled
|
52
52
|
attribute :firmware
|
53
53
|
attribute :annotation
|
54
54
|
|
55
|
-
def initialize(attributes={}
|
55
|
+
def initialize(attributes = {})
|
56
56
|
super defaults.merge(attributes)
|
57
57
|
self.instance_uuid ||= id # TODO: remvoe instance_uuid as it can be replaced with simple id
|
58
58
|
initialize_interfaces
|
@@ -62,7 +62,7 @@ module Fog
|
|
62
62
|
end
|
63
63
|
|
64
64
|
# Lazy Loaded Attributes
|
65
|
-
[
|
65
|
+
%i[datacenter cluster hypervisor resource_pool mac_addresses].each do |attr|
|
66
66
|
define_method attr do
|
67
67
|
attributes[attr] = attributes[attr].call if attributes[attr].is_a?(Proc)
|
68
68
|
attributes[attr]
|
@@ -75,45 +75,45 @@ module Fog
|
|
75
75
|
service.vm_rename('instance_uuid' => instance_uuid, 'name' => name)
|
76
76
|
end
|
77
77
|
|
78
|
-
def vm_reconfig_memory(
|
78
|
+
def vm_reconfig_memory(_options = {})
|
79
79
|
requires :instance_uuid, :memory
|
80
80
|
service.vm_reconfig_memory('instance_uuid' => instance_uuid, 'memory' => memory_mb)
|
81
81
|
end
|
82
82
|
|
83
|
-
def vm_reconfig_cpus(
|
83
|
+
def vm_reconfig_cpus(_options = {})
|
84
84
|
requires :instance_uuid, :cpus, :corespersocket
|
85
85
|
service.vm_reconfig_cpus('instance_uuid' => instance_uuid, 'cpus' => cpus, 'corespersocket' => corespersocket)
|
86
86
|
end
|
87
87
|
|
88
|
-
def vm_reconfig_volumes(
|
88
|
+
def vm_reconfig_volumes(_options = {})
|
89
89
|
requires :instance_uuid, :volumes
|
90
90
|
service.vm_reconfig_volumes('instance_uuid' => instance_uuid, 'volumes' => volumes)
|
91
91
|
end
|
92
92
|
|
93
|
-
def vm_reconfig_hardware(hardware_spec,
|
93
|
+
def vm_reconfig_hardware(hardware_spec, _options = {})
|
94
94
|
requires :instance_uuid
|
95
95
|
service.vm_reconfig_hardware('instance_uuid' => instance_uuid, 'hardware_spec' => hardware_spec)
|
96
96
|
end
|
97
97
|
|
98
|
-
def start(
|
98
|
+
def start(_options = {})
|
99
99
|
requires :instance_uuid
|
100
100
|
service.vm_power_on('instance_uuid' => instance_uuid) unless ready?
|
101
101
|
end
|
102
102
|
|
103
103
|
def stop(options = {})
|
104
|
-
options = { :
|
104
|
+
options = { force: !tools_installed? || !tools_running? }.merge(options)
|
105
105
|
requires :instance_uuid
|
106
106
|
service.vm_power_off('instance_uuid' => instance_uuid, 'force' => options[:force]) unless power_state == 'poweredOff'
|
107
107
|
end
|
108
108
|
|
109
109
|
def suspend(options = {})
|
110
|
-
options = { :
|
110
|
+
options = { force: !tools_installed? || !tools_running? }.merge(options)
|
111
111
|
requires :instance_uuid
|
112
112
|
service.vm_suspend('instance_uuid' => instance_uuid, 'force' => options[:force])
|
113
113
|
end
|
114
114
|
|
115
115
|
def reboot(options = {})
|
116
|
-
options = { :
|
116
|
+
options = { force: false }.merge(options)
|
117
117
|
requires :instance_uuid
|
118
118
|
service.vm_reboot('instance_uuid' => instance_uuid, 'force' => options[:force])
|
119
119
|
end
|
@@ -129,15 +129,15 @@ module Fog
|
|
129
129
|
end
|
130
130
|
|
131
131
|
def migrate(options = {})
|
132
|
-
options = { :
|
132
|
+
options = { priority: 'defaultPriority' }.merge(options)
|
133
133
|
requires :instance_uuid
|
134
134
|
|
135
135
|
# Convert symbols to strings
|
136
|
-
req_options = options.
|
136
|
+
req_options = options.each_with_object({}) { |(k, v), hsh| hsh[k.to_s] = v; }
|
137
137
|
req_options['cluster'] ||= cluster
|
138
|
-
req_options['datacenter'] =
|
138
|
+
req_options['datacenter'] = datacenter.to_s
|
139
139
|
req_options['instance_uuid'] = instance_uuid
|
140
|
-
|
140
|
+
|
141
141
|
service.vm_migrate(req_options)
|
142
142
|
end
|
143
143
|
|
@@ -152,22 +152,22 @@ module Fog
|
|
152
152
|
requires :name, :datacenter, :path
|
153
153
|
|
154
154
|
# Convert symbols to strings
|
155
|
-
req_options = options.
|
155
|
+
req_options = options.each_with_object({}) { |(k, v), hsh| hsh[k.to_s] = v; }
|
156
156
|
|
157
157
|
# Give our path to the request
|
158
|
-
req_options['template_path'] ="#{relative_path}/#{name}"
|
159
|
-
req_options['datacenter'] =
|
158
|
+
req_options['template_path'] = "#{relative_path}/#{name}"
|
159
|
+
req_options['datacenter'] = datacenter.to_s
|
160
160
|
|
161
161
|
# Perform the actual clone
|
162
162
|
clone_results = service.vm_clone(req_options)
|
163
163
|
|
164
164
|
# We need to assign the service, otherwise we can't reload the model
|
165
165
|
# Create the new VM model. TODO This only works when "wait=true"
|
166
|
-
new_vm = self.class.new(clone_results['new_vm'].merge(:
|
166
|
+
new_vm = self.class.new(clone_results['new_vm'].merge(service: service))
|
167
167
|
|
168
168
|
# We need to assign the collection otherwise we
|
169
169
|
# cannot reload the model.
|
170
|
-
new_vm.collection =
|
170
|
+
new_vm.collection = collection
|
171
171
|
|
172
172
|
# Return the new VM model.
|
173
173
|
new_vm
|
@@ -179,7 +179,7 @@ module Fog
|
|
179
179
|
end
|
180
180
|
|
181
181
|
def ready?
|
182
|
-
power_state ==
|
182
|
+
power_state == 'poweredOn'
|
183
183
|
end
|
184
184
|
|
185
185
|
def tools_installed?
|
@@ -187,7 +187,7 @@ module Fog
|
|
187
187
|
end
|
188
188
|
|
189
189
|
def tools_running?
|
190
|
-
[
|
190
|
+
%w[toolsOk toolsOld].include? tools_state
|
191
191
|
end
|
192
192
|
|
193
193
|
# defines VNC attributes on the hypervisor
|
@@ -215,36 +215,36 @@ module Fog
|
|
215
215
|
end
|
216
216
|
|
217
217
|
def interfaces
|
218
|
-
attributes[:interfaces] ||= id.nil? ? [] : service.interfaces(
|
218
|
+
attributes[:interfaces] ||= id.nil? ? [] : service.interfaces(server_id: id)
|
219
219
|
end
|
220
220
|
|
221
|
-
def interface_ready?
|
222
|
-
(attrs.is_a?
|
221
|
+
def interface_ready?(attrs)
|
222
|
+
(attrs.is_a?(Hash) && attrs[:blocking]) || attrs.is_a?(Fog::Compute::Vsphere::Interface)
|
223
223
|
end
|
224
224
|
|
225
|
-
def add_interface
|
226
|
-
Fog::Logger.deprecation(
|
225
|
+
def add_interface(attrs)
|
226
|
+
Fog::Logger.deprecation('<server>.add_interface is deprecated. Call <server>.interfaces.create instead.')
|
227
227
|
|
228
228
|
interfaces.create(attrs)
|
229
229
|
end
|
230
230
|
|
231
|
-
def update_interface
|
232
|
-
wait_for {
|
231
|
+
def update_interface(attrs)
|
232
|
+
wait_for { !ready? } if interface_ready? attrs
|
233
233
|
service.update_vm_interface(id, attrs)
|
234
234
|
end
|
235
235
|
|
236
|
-
def destroy_interface
|
237
|
-
Fog::Logger.deprecation(
|
236
|
+
def destroy_interface(attrs)
|
237
|
+
Fog::Logger.deprecation('<server>.destroy_vm_interface is deprecated. Call <server>.interfaces.get(:key => <nic_key>).destroy instead.')
|
238
238
|
|
239
239
|
interfaces.get(attrs[:key] || attrs['key']).destroy
|
240
240
|
end
|
241
241
|
|
242
242
|
def volumes
|
243
|
-
attributes[:volumes] ||= id.nil? ? [] : service.volumes(:
|
243
|
+
attributes[:volumes] ||= id.nil? ? [] : service.volumes(server_id: id)
|
244
244
|
end
|
245
245
|
|
246
246
|
def snapshots(opts = {})
|
247
|
-
service.snapshots(:
|
247
|
+
service.snapshots(server_id: id).all(opts)
|
248
248
|
end
|
249
249
|
|
250
250
|
def find_snapshot(snapshot_ref)
|
@@ -258,12 +258,12 @@ module Fog
|
|
258
258
|
when String
|
259
259
|
service.revert_to_snapshot(find_snapshot(snapshot))
|
260
260
|
else
|
261
|
-
|
261
|
+
raise ArgumentError, 'snapshot has to be kind of Snapshot or String class'
|
262
262
|
end
|
263
263
|
end
|
264
264
|
|
265
265
|
def cdroms(opts = {})
|
266
|
-
service.cdroms(:
|
266
|
+
service.cdroms(instance_uuid: id).all(opts)
|
267
267
|
end
|
268
268
|
|
269
269
|
def cdrom(key)
|
@@ -271,16 +271,16 @@ module Fog
|
|
271
271
|
end
|
272
272
|
|
273
273
|
def guest_processes(opts = {})
|
274
|
-
|
275
|
-
service.list_processes(
|
274
|
+
raise 'VM tools must be running' unless tools_running?
|
275
|
+
service.list_processes(id, opts)
|
276
276
|
end
|
277
277
|
|
278
278
|
def customvalues
|
279
|
-
attributes[:customvalues] ||= id.nil? ? [] : service.customvalues(
|
279
|
+
attributes[:customvalues] ||= id.nil? ? [] : service.customvalues(vm: self)
|
280
280
|
end
|
281
281
|
|
282
282
|
def scsi_controllers
|
283
|
-
|
283
|
+
attributes[:scsi_controllers] ||= service.list_vm_scsi_controllers(id)
|
284
284
|
end
|
285
285
|
|
286
286
|
def scsi_controller
|
@@ -288,21 +288,17 @@ module Fog
|
|
288
288
|
end
|
289
289
|
|
290
290
|
def folder
|
291
|
-
return nil unless datacenter
|
292
|
-
attributes[:folder] ||= service.folders(:
|
291
|
+
return nil unless datacenter && path
|
292
|
+
attributes[:folder] ||= service.folders(datacenter: datacenter, type: :vm).get(path)
|
293
293
|
end
|
294
294
|
|
295
295
|
def save
|
296
296
|
requires :name, :cluster, :datacenter
|
297
297
|
if persisted?
|
298
|
-
|
299
|
-
vm_reconfig_cpus if attribute_changed?(:cpus) || attribute_changed?(:corespersocket)
|
300
|
-
vm_reconfig_memory if attribute_changed?(:memory_mb)
|
301
|
-
vm_reconfig_volumes if attribute_changed?(:volumes)
|
298
|
+
service.update_vm(self)
|
302
299
|
else
|
303
300
|
self.id = service.create_vm(attributes)
|
304
301
|
end
|
305
|
-
@old = nil
|
306
302
|
reload
|
307
303
|
end
|
308
304
|
|
@@ -312,8 +308,8 @@ module Fog
|
|
312
308
|
|
313
309
|
def reload
|
314
310
|
# reload does not re-read assoiciated attributes, so we clear it manually
|
315
|
-
[
|
316
|
-
|
311
|
+
%i[interfaces volumes].each do |attr|
|
312
|
+
attributes.delete(attr)
|
317
313
|
end
|
318
314
|
super
|
319
315
|
end
|
@@ -321,67 +317,59 @@ module Fog
|
|
321
317
|
def relative_path
|
322
318
|
requires :path, :datacenter
|
323
319
|
|
324
|
-
(path.split('/').reject
|
320
|
+
(path.split('/').reject(&:empty?) - ['Datacenters', datacenter, 'vm']).join('/')
|
325
321
|
end
|
326
322
|
|
327
|
-
def acquire_ticket(
|
328
|
-
service.tickets(:
|
323
|
+
def acquire_ticket(_type = nil)
|
324
|
+
service.tickets(server: self).create
|
329
325
|
end
|
330
326
|
|
331
327
|
private
|
332
328
|
|
333
329
|
def defaults
|
334
330
|
{
|
335
|
-
:
|
336
|
-
# :corespersocket => 1,
|
337
|
-
:
|
338
|
-
:
|
339
|
-
:
|
331
|
+
cpus: 1,
|
332
|
+
# :corespersocket => 1,
|
333
|
+
memory_mb: 512,
|
334
|
+
guest_id: 'otherGuest',
|
335
|
+
path: '/'
|
340
336
|
}
|
341
337
|
end
|
342
338
|
|
343
339
|
def initialize_interfaces
|
344
|
-
if attributes[:interfaces]
|
345
|
-
|
340
|
+
if attributes[:interfaces] && attributes[:interfaces].is_a?(Array)
|
341
|
+
attributes[:interfaces].map! { |nic| nic.is_a?(Hash) ? service.interfaces.new(nic) : nic }
|
346
342
|
end
|
347
343
|
end
|
348
344
|
|
349
345
|
def initialize_volumes
|
350
|
-
if attributes[:volumes]
|
351
|
-
|
346
|
+
if attributes[:volumes] && attributes[:volumes].is_a?(Array)
|
347
|
+
attributes[:volumes].map! { |vol| vol.is_a?(Hash) ? service.volumes.new({ server: self }.merge(vol)) : vol }
|
352
348
|
end
|
353
349
|
end
|
354
350
|
|
355
351
|
def initialize_customvalues
|
356
|
-
if attributes[:customvalues]
|
357
|
-
|
352
|
+
if attributes[:customvalues] && attributes[:customvalues].is_a?(Array)
|
353
|
+
attributes[:customvalues].map { |cfield| cfield.is_a?(Hash) ? service.customvalue.new(cfield) : cfield }
|
358
354
|
end
|
359
355
|
end
|
360
356
|
|
361
357
|
def initialize_scsi_controllers
|
362
358
|
if attributes[:scsi_controllers] && attributes[:scsi_controllers].is_a?(Array)
|
363
|
-
|
359
|
+
attributes[:scsi_controllers].map! do |controller|
|
364
360
|
controller.is_a?(Hash) ? Fog::Compute::Vsphere::SCSIController.new(controller) : controller
|
365
361
|
end
|
366
362
|
elsif attributes[:scsi_controller] && attributes[:scsi_controller].is_a?(Hash)
|
367
|
-
|
368
|
-
Fog::Compute::Vsphere::SCSIController.new(
|
363
|
+
attributes[:scsi_controllers] = [
|
364
|
+
Fog::Compute::Vsphere::SCSIController.new(attributes[:scsi_controller])
|
369
365
|
]
|
370
366
|
elsif attributes[:volumes] && attributes[:volumes].is_a?(Array) && !attributes[:volumes].empty?
|
371
367
|
# Create a default scsi controller if there are any disks but no controller defined
|
372
|
-
|
368
|
+
attributes[:scsi_controllers] = [
|
373
369
|
Fog::Compute::Vsphere::SCSIController.new
|
374
370
|
]
|
375
371
|
end
|
376
372
|
end
|
377
|
-
|
378
|
-
def attribute_changed?(attr)
|
379
|
-
self.attributes.select { |k, v| old.attributes[k] != v }.key?(attr)
|
380
|
-
end
|
381
|
-
|
382
|
-
def old
|
383
|
-
@old ||= self.dup.reload
|
384
|
-
end
|
385
373
|
end
|
386
374
|
end
|
387
375
|
end
|