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
@@ -5,14 +5,14 @@ module Fog
|
|
5
5
|
identity :key
|
6
6
|
|
7
7
|
attribute :filename
|
8
|
-
attribute :name, :
|
8
|
+
attribute :name, default: 'CD-/DVD-ROM Drive'
|
9
9
|
attribute :controller_key
|
10
10
|
attribute :unit_number
|
11
11
|
attribute :start_connected
|
12
12
|
attribute :allow_guest_control
|
13
13
|
attribute :connected
|
14
14
|
|
15
|
-
has_one_identity :server, :servers, :
|
15
|
+
has_one_identity :server, :servers, aliases: :instance_uuid
|
16
16
|
|
17
17
|
def to_s
|
18
18
|
name
|
@@ -29,17 +29,17 @@ module Fog
|
|
29
29
|
requires :instance_uuid
|
30
30
|
|
31
31
|
if unit_number.nil?
|
32
|
-
used_unit_numbers = server.cdroms.map
|
32
|
+
used_unit_numbers = server.cdroms.map(&:unit_number)
|
33
33
|
max_unit_number = used_unit_numbers.max
|
34
34
|
|
35
|
-
if max_unit_number > server.cdroms.size
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
35
|
+
self.unit_number = if max_unit_number > server.cdroms.size
|
36
|
+
# If the max ID exceeds the number of cdroms, there must be a hole in the range. Find a hole and use it.
|
37
|
+
max_unit_number.times.to_a.find { |i| used_unit_numbers.exclude?(i) }
|
38
|
+
else
|
39
|
+
max_unit_number + 1
|
40
|
+
end
|
41
41
|
else
|
42
|
-
if server.cdroms.any? { |cdrom| cdrom.unit_number ==
|
42
|
+
if server.cdroms.any? { |cdrom| cdrom.unit_number == unit_number && cdrom.id != id }
|
43
43
|
raise "A cdrom already exists with that unit_number, so we can't save the new cdrom"
|
44
44
|
end
|
45
45
|
end
|
@@ -2,10 +2,10 @@ module Fog
|
|
2
2
|
module Compute
|
3
3
|
class Vsphere
|
4
4
|
class Cdroms < Fog::Collection
|
5
|
-
attribute :instance_uuid, :
|
5
|
+
attribute :instance_uuid, alias: :server_id
|
6
6
|
model Fog::Compute::Vsphere::Cdrom
|
7
7
|
|
8
|
-
def all(
|
8
|
+
def all(_filters = {})
|
9
9
|
load service.list_vm_cdroms(instance_uuid)
|
10
10
|
end
|
11
11
|
|
@@ -11,36 +11,36 @@ module Fog
|
|
11
11
|
attribute :overall_status
|
12
12
|
attribute :full_path
|
13
13
|
|
14
|
-
def resource_pools(filters = {
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
def resource_pools(filters = {})
|
15
|
+
attributes[:resource_pools] ||= id.nil? ? [] : service.resource_pools({
|
16
|
+
service: service,
|
17
|
+
cluster: full_path,
|
18
|
+
datacenter: datacenter
|
19
|
+
}.merge(filters))
|
20
20
|
end
|
21
21
|
|
22
|
-
def datastores(filters = {
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
def datastores(filters = {})
|
23
|
+
attributes[:datastores] ||= id.nil? ? [] : service.datastores({
|
24
|
+
service: service,
|
25
|
+
cluster: full_path,
|
26
|
+
datacenter: datacenter
|
27
|
+
}.merge(filters))
|
28
28
|
end
|
29
29
|
|
30
|
-
def networks(filters = {
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
30
|
+
def networks(filters = {})
|
31
|
+
attributes[:networks] ||= id.nil? ? [] : service.networks({
|
32
|
+
service: service,
|
33
|
+
cluster: full_path,
|
34
|
+
datacenter: datacenter
|
35
|
+
}.merge(filters))
|
36
36
|
end
|
37
37
|
|
38
38
|
def rules
|
39
|
-
service.rules(:
|
39
|
+
service.rules(datacenter: datacenter, cluster: full_path)
|
40
40
|
end
|
41
41
|
|
42
42
|
def hosts
|
43
|
-
service.hosts(:
|
43
|
+
service.hosts(datacenter: datacenter, cluster: full_path)
|
44
44
|
end
|
45
45
|
|
46
46
|
def to_s
|
@@ -8,13 +8,13 @@ module Fog
|
|
8
8
|
|
9
9
|
attr_accessor :vm
|
10
10
|
|
11
|
-
def all(
|
12
|
-
load service.list_customfields
|
11
|
+
def all(_filters = {})
|
12
|
+
load service.list_customfields
|
13
13
|
end
|
14
14
|
|
15
15
|
def get(key)
|
16
|
-
load(service.list_customfields
|
17
|
-
cv.key == (
|
16
|
+
load(service.list_customfields).find do |cv|
|
17
|
+
cv.key == (key.is_a? String ? key.to_i : key)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -8,12 +8,12 @@ module Fog
|
|
8
8
|
|
9
9
|
attr_accessor :vm
|
10
10
|
|
11
|
-
def all(
|
11
|
+
def all(_filters = {})
|
12
12
|
requires :vm
|
13
13
|
case vm
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
when Fog::Compute::Vsphere::Server
|
15
|
+
load service.list_vm_customvalues(vm.id)
|
16
|
+
else
|
17
17
|
raise 'customvalues should have vm'
|
18
18
|
end
|
19
19
|
end
|
@@ -21,11 +21,11 @@ module Fog
|
|
21
21
|
def get(key)
|
22
22
|
requires :vm
|
23
23
|
case vm
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
when Fog::Compute::Vsphere::Server
|
25
|
+
load service.list_vm_customvalues(vm.id)
|
26
|
+
else
|
27
27
|
raise 'customvalues should have vm'
|
28
|
-
end.find { |
|
28
|
+
end.find { |cv| cv.key == key }
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -7,36 +7,36 @@ module Fog
|
|
7
7
|
attribute :path
|
8
8
|
attribute :status
|
9
9
|
|
10
|
-
def clusters
|
11
|
-
service.clusters({ :
|
10
|
+
def clusters(filters = {})
|
11
|
+
service.clusters({ datacenter: path.join('/') }.merge(filters))
|
12
12
|
end
|
13
13
|
|
14
|
-
def networks
|
15
|
-
service.networks({ :
|
14
|
+
def networks(filters = {})
|
15
|
+
service.networks({ datacenter: path.join('/') }.merge(filters))
|
16
16
|
end
|
17
17
|
|
18
|
-
def datastores
|
19
|
-
service.datastores({ :
|
18
|
+
def datastores(filters = {})
|
19
|
+
service.datastores({ datacenter: path.join('/') }.merge(filters))
|
20
20
|
end
|
21
21
|
|
22
|
-
def storage_pods
|
23
|
-
service.storage_pods({ :
|
22
|
+
def storage_pods(filters = {})
|
23
|
+
service.storage_pods({ datacenter: path.join('/') }.merge(filters))
|
24
24
|
end
|
25
25
|
|
26
|
-
def vm_folders
|
27
|
-
service.folders({ :
|
26
|
+
def vm_folders(filters = {})
|
27
|
+
service.folders({ datacenter: path.join('/'), type: :vm }.merge(filters))
|
28
28
|
end
|
29
29
|
|
30
|
-
def virtual_machines
|
31
|
-
service.servers({ :
|
30
|
+
def virtual_machines(filters = {})
|
31
|
+
service.servers({ datacenter: path.join('/') }.merge(filters))
|
32
32
|
end
|
33
33
|
|
34
|
-
def servertypes
|
35
|
-
service.servertypes({:
|
34
|
+
def servertypes(filters = {})
|
35
|
+
service.servertypes({ datacenter: name }.merge(filters))
|
36
36
|
end
|
37
37
|
|
38
|
-
def customfields
|
39
|
-
service.customfields({ :
|
38
|
+
def customfields(filters = {})
|
39
|
+
service.customfields({ datacenter: path.join('/') }.merge(filters))
|
40
40
|
end
|
41
41
|
|
42
42
|
def to_s
|
@@ -8,7 +8,7 @@ module Fog
|
|
8
8
|
attr_accessor :datacenter, :cluster
|
9
9
|
|
10
10
|
def all(filters = {})
|
11
|
-
load service.list_datastores(filters.merge(:
|
11
|
+
load service.list_datastores(filters.merge(datacenter: datacenter, cluster: cluster))
|
12
12
|
end
|
13
13
|
|
14
14
|
def get(id)
|
@@ -13,13 +13,13 @@ module Fog
|
|
13
13
|
# Pass :recursive => true to get a Servers object that searches for VM names recursively
|
14
14
|
def vms(options = {})
|
15
15
|
return [] if type.to_s != 'vm'
|
16
|
-
service.servers(:
|
16
|
+
service.servers(folder: path, datacenter: datacenter, recursive: options[:recursive])
|
17
17
|
end
|
18
18
|
|
19
19
|
def to_s
|
20
20
|
name
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def destroy
|
24
24
|
service.folder_destroy(path, datacenter)
|
25
25
|
end
|
@@ -7,10 +7,10 @@ module Fog
|
|
7
7
|
model Fog::Compute::Vsphere::Folder
|
8
8
|
attr_accessor :datacenter, :type, :path
|
9
9
|
|
10
|
-
def all(filters = {
|
10
|
+
def all(filters = {})
|
11
11
|
requires :datacenter
|
12
12
|
requires :type
|
13
|
-
load service.list_folders(filters.merge(:
|
13
|
+
load service.list_folders(filters.merge(datacenter: datacenter, type: type, path: path))
|
14
14
|
end
|
15
15
|
|
16
16
|
def get(id)
|
@@ -7,14 +7,14 @@ module Fog
|
|
7
7
|
|
8
8
|
model Fog::Compute::Vsphere::Host
|
9
9
|
|
10
|
-
def all(
|
10
|
+
def all(_filters = {})
|
11
11
|
requires :datacenter, :cluster
|
12
|
-
load service.list_hosts(:
|
12
|
+
load service.list_hosts(datacenter: datacenter, cluster: cluster)
|
13
13
|
end
|
14
14
|
|
15
15
|
def get(name)
|
16
|
-
all.find { |host| host.name == name }
|
17
|
-
raise
|
16
|
+
all.find { |host| host.name == name } ||
|
17
|
+
raise(Fog::Compute::Vsphere::NotFound, "no such host #{name}")
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -5,7 +5,7 @@ module Fog
|
|
5
5
|
SAVE_MUTEX = Mutex.new
|
6
6
|
|
7
7
|
identity :mac
|
8
|
-
|
8
|
+
alias id mac
|
9
9
|
|
10
10
|
attribute :network
|
11
11
|
attribute :name
|
@@ -21,12 +21,12 @@ module Fog
|
|
21
21
|
# Assign server first to prevent race condition with persisted?
|
22
22
|
self.server_id = attributes.delete(:server_id)
|
23
23
|
|
24
|
-
if attributes.key? :type
|
25
|
-
if attributes[:type].is_a? String
|
26
|
-
attributes[:type] = Fog::Vsphere.class_from_string(attributes[:type],
|
24
|
+
if attributes.key? :type
|
25
|
+
if attributes[:type].is_a? String
|
26
|
+
attributes[:type] = Fog::Vsphere.class_from_string(attributes[:type], 'RbVmomi::VIM')
|
27
27
|
end
|
28
28
|
else
|
29
|
-
attributes[:type] = Fog::Vsphere.class_from_string(
|
29
|
+
attributes[:type] = Fog::Vsphere.class_from_string('VirtualE1000', 'RbVmomi::VIM')
|
30
30
|
end
|
31
31
|
|
32
32
|
super defaults.merge(attributes)
|
@@ -44,11 +44,11 @@ module Fog
|
|
44
44
|
def destroy
|
45
45
|
requires :server_id, :key, :type
|
46
46
|
|
47
|
-
service.destroy_vm_interface(server_id, :
|
47
|
+
service.destroy_vm_interface(server_id, key: key, type: type)
|
48
48
|
end
|
49
49
|
|
50
50
|
def save
|
51
|
-
raise Fog::Errors::Error
|
51
|
+
raise Fog::Errors::Error, 'Resaving an existing object may create a duplicate' if persisted?
|
52
52
|
requires :server_id, :type, :network
|
53
53
|
|
54
54
|
# Our approach of finding the newly created interface is rough. We assume that the :key value always increments
|
@@ -78,12 +78,12 @@ module Fog
|
|
78
78
|
private
|
79
79
|
|
80
80
|
def defaults
|
81
|
-
default_type=Fog.credentials[:default_nic_type] || RbVmomi::VIM::VirtualE1000
|
81
|
+
default_type = Fog.credentials[:default_nic_type] || RbVmomi::VIM::VirtualE1000
|
82
82
|
{
|
83
|
-
:
|
84
|
-
:
|
85
|
-
:
|
86
|
-
:
|
83
|
+
name: 'Network adapter',
|
84
|
+
network: 'VM Network',
|
85
|
+
summary: 'VM Network',
|
86
|
+
type: Fog::Vsphere.class_from_string(default_type, 'RbVmomi::VIM')
|
87
87
|
}
|
88
88
|
end
|
89
89
|
end
|
@@ -8,19 +8,19 @@ module Fog
|
|
8
8
|
|
9
9
|
attribute :server_id
|
10
10
|
|
11
|
-
def all(
|
11
|
+
def all(_filters = {})
|
12
12
|
requires :server_id
|
13
13
|
|
14
14
|
case server
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
when Fog::Compute::Vsphere::Server
|
16
|
+
load service.list_vm_interfaces(server.id)
|
17
|
+
when Fog::Compute::Vsphere::Template
|
18
|
+
load service.list_template_interfaces(server.id)
|
19
|
+
else
|
20
20
|
raise 'interfaces should have vm or template'
|
21
21
|
end
|
22
22
|
|
23
|
-
|
23
|
+
each { |interface| interface.server_id = server.id }
|
24
24
|
self
|
25
25
|
end
|
26
26
|
|
@@ -28,25 +28,23 @@ module Fog
|
|
28
28
|
requires :server_id
|
29
29
|
|
30
30
|
case server
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
31
|
+
when Fog::Compute::Vsphere::Server
|
32
|
+
interface = service.get_vm_interface(server.id, key: id, mac: id, name: id)
|
33
|
+
when Fog::Compute::Vsphere::Template
|
34
|
+
interface = service.get_template_interfaces(server.id, key: id, mac: id, name: id)
|
35
|
+
else
|
36
36
|
|
37
37
|
raise 'interfaces should have vm or template'
|
38
38
|
end
|
39
39
|
|
40
40
|
if interface
|
41
|
-
Fog::Compute::Vsphere::Interface.new(interface.merge(:
|
42
|
-
else
|
43
|
-
nil
|
41
|
+
Fog::Compute::Vsphere::Interface.new(interface.merge(server_id: server.id, service: service))
|
44
42
|
end
|
45
43
|
end
|
46
44
|
|
47
45
|
def new(attributes = {})
|
48
46
|
if server_id
|
49
|
-
super({ :server_id
|
47
|
+
super({ server_id: server_id }.merge(attributes))
|
50
48
|
else
|
51
49
|
super
|
52
50
|
end
|
@@ -4,12 +4,12 @@ module Fog
|
|
4
4
|
class Interfacetype < Fog::Model
|
5
5
|
identity :id
|
6
6
|
|
7
|
-
# attribute :class
|
7
|
+
# attribute :class
|
8
8
|
attribute :name
|
9
9
|
attribute :datacenter
|
10
10
|
attribute :servertype
|
11
11
|
|
12
|
-
def initialize(attributes={}
|
12
|
+
def initialize(attributes = {})
|
13
13
|
super attributes
|
14
14
|
end
|
15
15
|
|
@@ -8,16 +8,14 @@ module Fog
|
|
8
8
|
attr_accessor :datacenter
|
9
9
|
attr_accessor :servertype
|
10
10
|
|
11
|
-
def all(filters = {
|
11
|
+
def all(filters = {})
|
12
12
|
requires :servertype
|
13
13
|
case servertype
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
else
|
20
|
-
raise 'interfacetypes should have a servertype'
|
14
|
+
when Fog::Compute::Vsphere::Servertype
|
15
|
+
load service.list_interface_types(filters.merge(datacenter: datacenter,
|
16
|
+
servertype: servertype.id))
|
17
|
+
else
|
18
|
+
raise 'interfacetypes should have a servertype'
|
21
19
|
end
|
22
20
|
end
|
23
21
|
|