Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request fog#1431 from ekohl/vmware-dvs
[vsphere] Vmware Distributed Virtual Switches
  • Loading branch information
ohadlevy committed Feb 2, 2013
2 parents ef66eef + 3ac6847 commit ba105fa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
21 changes: 18 additions & 3 deletions lib/fog/vsphere/requests/compute/create_vm.rb
Expand Up @@ -39,7 +39,7 @@ def vm_path_name attributes
def device_change attributes
devices = []
if (nics = attributes[:interfaces])
devices << nics.map { |nic| create_interface(nic, nics.index(nic)) }
devices << nics.map { |nic| create_interface(nic, nics.index(nic), :add, attributes) }
end

if (disks = attributes[:volumes])
Expand All @@ -49,7 +49,22 @@ def device_change attributes
devices.flatten
end

def create_interface nic, index = 0, operation = :add
def create_nic_backing nic, attributes
raw_network = get_raw_network(nic.network, attributes[:datacenter])

if raw_network.kind_of? RbVmomi::VIM::DistributedVirtualPortgroup
RbVmomi::VIM.VirtualEthernetCardDistributedVirtualPortBackingInfo(
:port => RbVmomi::VIM.DistributedVirtualSwitchPortConnection(
:portgroupKey => raw_network.key,
:switchUuid => raw_network.config.distributedVirtualSwitch.uuid
)
)
else
RbVmomi::VIM.VirtualEthernetCardNetworkBackingInfo(:deviceName => nic.network)
end
end

def create_interface nic, index = 0, operation = :add, attributes = {}
{
:operation => operation,
:device => nic.type.new(
Expand All @@ -59,7 +74,7 @@ def create_interface nic, index = 0, operation = :add
:label => nic.name,
:summary => nic.summary,
},
:backing => RbVmomi::VIM.VirtualEthernetCardNetworkBackingInfo(:deviceName => nic.network),
:backing => create_nic_backing(nic, attributes),
:addressType => 'generated')
}
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/vsphere/requests/compute/list_vm_interfaces.rb
Expand Up @@ -33,7 +33,7 @@ def list_vm_interfaces(vm_id)
{
:name => nic.deviceInfo.label,
:mac => nic.macAddress,
:network => nic.backing.network.name,
:network => nic.backing.respond_to?("network") ? nic.backing.network.name : nic.backing.port.portgroupKey,
:status => nic.connectable.status,
:summary => nic.deviceInfo.summary,
:type => nic.class,
Expand Down

0 comments on commit ba105fa

Please sign in to comment.