Skip to content

Commit

Permalink
Add distributedvirtualportgroup support
Browse files Browse the repository at this point in the history
'distributedvirtualportgroup' configuration takes precedence over
'network'.

Closes: snobear#28, snobear#55
  • Loading branch information
Michael Weber committed Jul 22, 2016
1 parent 3dcadbf commit 1e8fa14
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
7 changes: 7 additions & 0 deletions ezmomi/config/config.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
30 changes: 21 additions & 9 deletions ezmomi/ezmomi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1e8fa14

Please sign in to comment.