mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
vsphere: Support multiple NIC backings
A bit of background: currently fog supports Network[1], but there's also DistributedVirtualPortgroup[2] which extends Network. With this commit create_vm tries to detect if the network is a DistributedVirtualPortgroup. If it is it will create the appropriate backing (VirtualEthernetCardDistributedVirtualPortBackingInfo[3]). If it's not it will fall back to the regular backing (VirtualEthernetCardNetworkBackingInfo[4]). Known issues: * It is possible for an administrator to assign network permissions to a DistributedVirtualPortgroup[2], but not to the DistributedVirtualSwitch[5]. In that case you can't read its UUID and it fails with an exception. [1]: http://pubs.vmware.com/vsphere-51/index.jsp?topic=%2Fcom.vmware.wssdk.apiref.doc%2Fvim.Network.html [2]: http://pubs.vmware.com/vsphere-51/index.jsp?topic=%2Fcom.vmware.wssdk.apiref.doc%2Fvim.dvs.DistributedVirtualPortgroup.html [3]: https://pubs.vmware.com/vsphere-51/index.jsp?topic=%2Fcom.vmware.wssdk.apiref.doc%2Fvim.vm.device.VirtualEthernetCard.DistributedVirtualPortBackingInfo.html [4]: https://pubs.vmware.com/vsphere-51/index.jsp?topic=%2Fcom.vmware.wssdk.apiref.doc%2Fvim.vm.device.VirtualEthernetCard.NetworkBackingInfo.html [5]: https://pubs.vmware.com/vsphere-51/index.jsp?topic=%2Fcom.vmware.wssdk.apiref.doc%2Fvim.DistributedVirtualSwitch.html
This commit is contained in:
parent
9bce631156
commit
26b5805852
1 changed files with 18 additions and 3 deletions
|
@ -39,7 +39,7 @@ module Fog
|
|||
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])
|
||||
|
@ -49,7 +49,22 @@ module Fog
|
|||
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(
|
||||
|
@ -59,7 +74,7 @@ module Fog
|
|||
:label => nic.name,
|
||||
:summary => nic.summary,
|
||||
},
|
||||
:backing => RbVmomi::VIM.VirtualEthernetCardNetworkBackingInfo(:deviceName => nic.network),
|
||||
:backing => create_nic_backing(nic, attributes),
|
||||
:addressType => 'generated')
|
||||
}
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue