From 1e8fa143bcb6bb2fb1f470a97f6a794dfcd3ae5c Mon Sep 17 00:00:00 2001 From: Michael Weber Date: Sat, 16 Jul 2016 12:31:21 -0700 Subject: [PATCH] Add distributedvirtualportgroup support 'distributedvirtualportgroup' configuration takes precedence over 'network'. Closes: #28, #55 --- ezmomi/config/config.yml.example | 7 +++++++ ezmomi/ezmomi.py | 30 +++++++++++++++++++++--------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/ezmomi/config/config.yml.example b/ezmomi/config/config.yml.example index 62e6864..39a34fd 100644 --- a/ezmomi/config/config.yml.example +++ b/ezmomi/config/config.yml.example @@ -37,6 +37,13 @@ networks: network: 'Internal 2' gateway: '192.168.24.50' + '192.168.24.60/24': + datacenter: 'Foocenter' + cluster: 'FooCluster' + datastore: 'Foomount' + distributedvirtualportgroup: 'DVInternal' + gateway: '192.168.24.61' + # storage network # Note: any networks that not used for primary IPs only need to have the network name defined, like this example. '172.20.200.1/24': diff --git a/ezmomi/ezmomi.py b/ezmomi/ezmomi.py index b65f8db..77fc140 100644 --- a/ezmomi/ezmomi.py +++ b/ezmomi/ezmomi.py @@ -290,15 +290,27 @@ def clone(self): nic.device.key = 4000 nic.device.deviceInfo = vim.Description() nic.device.deviceInfo.label = 'Network Adapter %s' % (key + 1) - nic.device.deviceInfo.summary = ip_settings[key]['network'] - nic.device.backing = ( - vim.vm.device.VirtualEthernetCard.NetworkBackingInfo() - ) - nic.device.backing.network = ( - self.get_obj([vim.Network], ip_settings[key]['network']) - ) - nic.device.backing.deviceName = ip_settings[key]['network'] - nic.device.backing.useAutoDetect = False + + if ip_settings[key].has_key('distributedvirtualportgroup'): + dvpg = ip_settings[key]['distributedvirtualportgroup'] + nic.device.deviceInfo.summary = dvpg + pg_obj = self.get_obj([vim.dvs.DistributedVirtualPortgroup], dvpg) # noqa + dvs_port_connection = vim.dvs.PortConnection() + dvs_port_connection.portgroupKey = pg_obj.key + dvs_port_connection.switchUuid = pg_obj.config.distributedVirtualSwitch.uuid # noqa + nic.device.backing = vim.vm.device.VirtualEthernetCard.DistributedVirtualPortBackingInfo() # noqa + nic.device.backing.port = dvs_port_connection + else: + # use traditional network-setup without distributed switches + nic.device.deviceInfo.summary = ip_settings[key]['network'] + nic.device.backing = ( + vim.vm.device.VirtualEthernetCard.NetworkBackingInfo() + ) + nic.device.backing.network = ( + self.get_obj([vim.Network], ip_settings[key]['network']) + ) + nic.device.backing.deviceName = ip_settings[key]['network'] + nic.device.backing.useAutoDetect = False nic.device.connectable = vim.vm.device.VirtualDevice.ConnectInfo() nic.device.connectable.startConnected = True nic.device.connectable.allowGuestControl = True