mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
38c3bb1ba4
* added methods to add, remove and update interfaces for vSphere * added missing method to retrieve the interface * added existing attribute key to interface (required for modifying, deleting interfaces) * alias interface's mac to id
58 lines
No EOL
2.2 KiB
Ruby
58 lines
No EOL
2.2 KiB
Ruby
module Fog
|
|
module Compute
|
|
class Vsphere
|
|
class Real
|
|
|
|
def add_vm_interface(vmid, options = {})
|
|
raise ArgumentError, "instance id is a required parameter" unless vmid
|
|
|
|
interface=get_interface_from_options(vmid, options)
|
|
vm_reconfig_hardware('instance_uuid' => vmid, 'hardware_spec' => {'deviceChange'=>[create_interface(interface)]})
|
|
end
|
|
|
|
def destroy_vm_interface(vmid, options = {})
|
|
raise ArgumentError, "instance id is a required parameter" unless vmid
|
|
|
|
interface=get_vm_interface(vmid, options)
|
|
vm_reconfig_hardware('instance_uuid' => vmid, 'hardware_spec' => {'deviceChange'=>[create_interface(interface, interface.key, :remove)]})
|
|
end
|
|
|
|
def update_vm_interface(vmid, options = {})
|
|
raise ArgumentError, "instance id is a required parameter" unless vmid
|
|
|
|
interface=get_vm_interface(vmid, options)
|
|
vm_reconfig_hardware('instance_uuid' => vmid, 'hardware_spec' => {'deviceChange'=>[create_interface(interface, interface.key, :edit)]})
|
|
end
|
|
|
|
private
|
|
def get_interface_from_options(vmid, options)
|
|
if options and options[:interface]
|
|
options[:interface]
|
|
elsif options[:key] and options[:key]>0
|
|
oldattributes=get_vm_interface(vmid, options)
|
|
Fog::Compute::Vsphere::Interface.new oldattributes.merge options
|
|
elsif options[:type] and options[:network]
|
|
Fog::Compute::Vsphere::Interface.new options
|
|
else
|
|
raise ArgumentError, "interface is a required parameter or pass options with type and network"
|
|
end
|
|
end
|
|
|
|
end
|
|
|
|
class Mock
|
|
def add_vm_interface(vmid, options = {})
|
|
raise ArgumentError, "instance id is a required parameter" unless vmid
|
|
raise ArgumentError, "interface is a required parameter" unless options and options[:interface]
|
|
true
|
|
end
|
|
|
|
def destroy_vm_interface(vmid, options = {})
|
|
raise ArgumentError, "instance id is a required parameter" unless vmid
|
|
raise ArgumentError, "interface is a required parameter" unless options and options[:interface]
|
|
true
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end |