1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/vsphere/requests/compute/modify_vm_interface.rb
Marc Grimme 38c3bb1ba4 [vSphere] Refactor and extend network interface methods (similar to the ovirt implementation)
* 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
2013-04-23 10:52:52 +02:00

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