snobear/ezmomi

Possible problem using distributed switches

rostchri opened this issue · 9 comments

ezmomi list --type Network returns the following Object in my setup:
dvportport-98 VLAN_1909

I want to use that, so i defined:
networks:
'192.168.0.0/24'
...
network: 'VLAN_1909'

After cloning a vm using ezmomi given a ip in network 192.168.0.0, the virtual-machine's
network-interface is disconnected and ezmomi list --type Network returns now
network-6626 VLAN_1909
dvportport-98 VLAN_1909

That is not the way it should work ...
How to specify the vlan-name at the distributed switch, without creating new bogus vlans
while cloning?

@rostchri Interesting. Speaking in vSphere API terms, it looks like there is a different "managed object type" for DistributedVirtualPortgroup.

ezmomi list --type DistributedVirtualPortgroup

It's an extension/subclass of network, so that explains why it shows up in the list for ezmomi list --type Network. Offhand, I think the solution would be to allow for a distributedvirtualportgroup: setting in the ezmomi networks config. It would place the NIC in the DVPG if it was set. If both distributedvirtualportgroup: and network: were set, it would choose distributedvirtualportgroup: first for the NIC as a priority. I think that makes sense since its more specific per vSphere docs. I'm not that familiar with DVPGs. Does that solution make sense to you?

Yes that makes sense.

+1

Same issue here!

Following modifications to ezmomi.py in ezmomi-0.3.1
are usable with distributed switches. I'm sure the author can write a
clean fix (usable for environments with and without distributed switches) based
on this modifications.

227 # 4000 seems to be the value to use for a vmxnet3 device
228 nic.device.key = 4000
229 nic.device.deviceInfo = vim.Description()
230 nic.device.deviceInfo.label = 'Network Adapter %s' % (key + 1)
231 nic.device.deviceInfo.summary = ip_settings[key]['network']
232 # find a DistributedVirtualPortgroup with that name
233 pg_obj = self.get_obj([vim.dvs.DistributedVirtualPortgroup],ip_settings[key]['network'])
234 dvs_port_connection = vim.dvs.PortConnection()
235 dvs_port_connection.portgroupKey = pg_obj.key
236 dvs_port_connection.switchUuid = pg_obj.config.distributedVirtualSwitch.uuid
237 #print dvs_port_connection
238 nic.device.backing = vim.vm.device.VirtualEthernetCard.DistributedVirtualPortBackingInfo()
239 nic.device.backing.port = dvs_port_connection
240 # else: use traditional network-setup without distributed switches
241 #nic.device.backing = (
242 # vim.vm.device.VirtualEthernetCard.NetworkBackingInfo()
243 #)
244 #nic.device.backing.network = (
245 # self.get_obj([vim.Network], ip_settings[key]['network'])
246 #)
247 #nic.device.backing.deviceName = ip_settings[key]['network']
248 #nic.device.backing.useAutoDetect = False
249 nic.device.connectable = vim.vm.device.VirtualDevice.ConnectInfo()
250 nic.device.connectable.startConnected = True
251 nic.device.connectable.allowGuestControl = True
252 devices.append(nic)

Thanks Christian, that code will be helpful. Will try to incorporate it
soon.

On Fri, Aug 14, 2015 at 4:38 AM, Christian Rost notifications@github.com
wrote:

Following modifications to ezmomi.py in ezmomi-0.3.1
are usable with distributed switches. I'm sure the author can write a
clean fix (usable for environments with and without distributed switches)
based
on this modifications.

227 # 4000 seems to be the value to use for a vmxnet3 device
228 nic.device.key = 4000
229 nic.device.deviceInfo = vim.Description()
230 nic.device.deviceInfo.label = 'Network Adapter %s' % (key + 1)
231 nic.device.deviceInfo.summary = ip_settings[key]['network']
232 # find a DistributedVirtualPortgroup with that name
233 pg_obj =
self.get_obj([vim.dvs.DistributedVirtualPortgroup],ip_settings[key]['network'])
234 dvs_port_connection = vim.dvs.PortConnection()
235 dvs_port_connection.portgroupKey = pg_obj.key
236 dvs_port_connection.switchUuid =
pg_obj.config.distributedVirtualSwitch.uuid
237 #print dvs_port_connection
238 nic.device.backing =
vim.vm.device.VirtualEthernetCard.DistributedVirtualPortBackingInfo()
239 nic.device.backing.port = dvs_port_connection
240 # else: use traditional network-setup without distributed switches
241 #nic.device.backing = (
242 # vim.vm.device.VirtualEthernetCard.NetworkBackingInfo()
243 #)
244 #nic.device.backing.network = (
245 # self.get_obj([vim.Network], ip_settings[key]['network'])
246 #)
247 #nic.device.backing.deviceName = ip_settings[key]['network']
248 #nic.device.backing.useAutoDetect = False
249 nic.device.connectable = vim.vm.device.VirtualDevice.ConnectInfo()
250 nic.device.connectable.startConnected = True
251 nic.device.connectable.allowGuestControl = True
252 devices.append(nic)


Reply to this email directly or view it on GitHub
#28 (comment).

Thanks Christian! @rostchri

Reopening as it needs to be added to ezmomi codebase.

@rostchri @daniloharuo Can you all pull down PR #72 and give it a test to see if the distributed virtual port group works as expected? Then I can merge it.

Distributed virtual port group support has been added. Its currently in the master branch...will release an updated py package soon.