salt-cloud with VMware and distributed switches support?
Description of Issue/Question
When I clone from template a VM and try to associate a Network that is defined in a distributed switch salt-cloud crash with the exception:
[ERROR ] There was a profile error: 'NoneType' object has no attribute 'key' Traceback (most recent call last): File "/usr/lib/python2.6/site-packages/salt/cloud/cli.py", line 284, in run self.config.get('names') File "/usr/lib/python2.6/site-packages/salt/cloud/init.py", line 1458, in run_profile ret[name] = self.create(vm_) File "/usr/lib/python2.6/site-packages/salt/cloud/init.py", line 1288, in create output = self.cloudsfunc File "/usr/lib64/python2.6/contextlib.py", line 34, in exit self.gen.throw(type, value, traceback) File "/usr/lib/python2.6/site-packages/salt/utils/context.py", line 48, in func_globals_inject yield File "/usr/lib/python2.6/site-packages/salt/cloud/init.py", line 1288, in create output = self.cloudsfunc File "/usr/lib/python2.6/site-packages/salt/cloud/clouds/vmware.py", line 2511, in create specs = _manage_devices(devices, object_ref) File "/usr/lib/python2.6/site-packages/salt/cloud/clouds/vmware.py", line 680, in _manage_devices network_spec = _edit_existing_network_adapter(device, network_name, adapter_type, switch_type) File "/usr/lib/python2.6/site-packages/salt/cloud/clouds/vmware.py", line 346, in _edit_existing_network_adapter portgroupKey=network_ref.key, AttributeError: 'NoneType' object has no attribute 'key'`
Setup
The VM definition is:
vmtest.localhost:
## Parametros para clonar una maquina virtual
provider: vmware
clonefrom: vmtemplate
## Parametros Opcionales de la maquina virtual
annotations: "vmtest a partir de plantilla: vmtemplate"
## Definicion de dispositivos: discos, tarjetas de red, etc.
## vCPUS & Memoria
num_cpus: 3
memory: 14GB
## Dispositivos
devices:
## Interfaces de red
network:
Network adapter 1:
name: 10_PROD-SERV-APLIC
adapter_type: vmxnet3
switch_type: distributed
ip: 192.168.120.5
gateway: [192.168.120.1]
subnet_mask: 255.255.255.0
## Configuracion global de red
domain: localhost
dns_servers:
- 192.168.120.2
- 192.168.120.3
## Recursos de la maquina virtual
cluster: CL1_ORO
datastore: dsc_pro_lin_03
folder: Produccion
datacenter: VMs
hardware_version: 10
template: False
power_on: True
## Despliegue de agente salt-minion
deploy: False
If I set the switch_typeasstandard` salt-cloud create the VM but the NIC is disconnected. The 10_PROD-SERV-APLIC are defined in standard and distributed switches but only CL1_ORO clusters has associated distributed switches.
Can I specify the distributed switch that I want to associate to the VM? something as:
switch_type: distributed dvs_switch: dvSwitch2
Steps to Reproduce Issue
[ERROR ] There was a profile error: 'NoneType' object has no attribute 'key' Traceback (most recent call last): File "/usr/lib/python2.6/site-packages/salt/cloud/cli.py", line 284, in run self.config.get('names') File "/usr/lib/python2.6/site-packages/salt/cloud/init.py", line 1458, in run_profile ret[name] = self.create(vm_) File "/usr/lib/python2.6/site-packages/salt/cloud/init.py", line 1288, in create output = self.cloudsfunc File "/usr/lib64/python2.6/contextlib.py", line 34, in exit self.gen.throw(type, value, traceback) File "/usr/lib/python2.6/site-packages/salt/utils/context.py", line 48, in func_globals_inject yield File "/usr/lib/python2.6/site-packages/salt/cloud/init.py", line 1288, in create output = self.cloudsfunc File "/usr/lib/python2.6/site-packages/salt/cloud/clouds/vmware.py", line 2511, in create specs = _manage_devices(devices, object_ref) File "/usr/lib/python2.6/site-packages/salt/cloud/clouds/vmware.py", line 680, in _manage_devices network_spec = _edit_existing_network_adapter(device, network_name, adapter_type, switch_type) File "/usr/lib/python2.6/site-packages/salt/cloud/clouds/vmware.py", line 346, in _edit_existing_network_adapter portgroupKey=network_ref.key, AttributeError: 'NoneType' object has no attribute 'key' `
Versions Report
Salt Version: Salt: 2016.11.3
Dependency Versions: cffi: Not Installed cherrypy: 3.2.2 dateutil: 1.4.1 gitdb: 0.5.4 gitpython: 0.3.2 RC1 ioflo: Not Installed Jinja2: 2.8.1 libgit2: Not Installed libnacl: Not Installed M2Crypto: 0.20.2 Mako: Not Installed msgpack-pure: Not Installed msgpack-python: 0.4.6 mysql-python: 1.2.5 pycparser: Not Installed pycrypto: 2.6.1 pygit2: Not Installed Python: 2.6.6 (r266:84292, Aug 19 2016, 02:44:53) python-gnupg: Not Installed PyYAML: 3.11 PyZMQ: 14.5.0 RAET: Not Installed smmap: 0.8.1 timelib: Not Installed Tornado: 4.3 ZMQ: 4.0.5
System Versions: dist: centos 6.8 Santiago machine: x86_64 release: 2.6.32-642.15.1.el6.x86_64 system: Linux version: Red Hat Enterprise Linux Server 6.8 Santiago `
This appears to be the same issue that was here.
https://github.com/saltstack/salt/issues/37274
It sounds like the switch is either A) not named that, or B) a standard switch and not distributed.
Thanks for the reply @gtmanfred, i know that issues and the problem is the same but in that issue just change the switch_type to standard. In my case the network has the same name in distributed switch and standard switch:
sudo salt-cloud -f list_dvs vmware vmware: ---------- vmware: ---------- Distributed Virtual Switches: - dvSwitch6 - dvSwitch7 - dvSwitch8
sudo salt-cloud -f list_portgroups vmware | grep PROD-SERV-APLIC - 10_PROD-SERV-APLIC
sudo salt-cloud -f list_networks vmware | grep PROD-SERV-APLIC - 10_PROD-SERV-APLIC - 10_PROD-SERV-APLIC
If i select stantard switch the NIC appears disconnect because CL1_ORO only have distributed switches and if i select distributed switch salt-cloud raise the exception.
@nmadhok could you take a look at this, it looks like it is a new issue where we can't have standard and distributed networks being named the same.
Thanks, Daniel
@gtmanfred I'm aware about this issue. @PabloLemos In general, one should have Standard Networks named differently that the Distributed Port Groups. If there are two networks with the same name, it's confusing for anyone to figure out which one to use. Since we have a second factor (switch_type) here, we could probably look up combination of the network name and the switch type. I'll work on a fix for this soon!
Thanks @nmadhok ! much appreciated as always!
Daniel
@nmadhok thanks for the reply, you are right. We use the same name in both kind of switches because the System staff is not the same as the Virtualization staff. System Staff only knows about VLANs.
I have code currently in the develop branch that would permit a user to select the switch by id instead of name, if that were to be desirable. Specifically, the get_mor_by_property function called allows for object ids.
VMWare is interesting in that they let you name all kinds of things by the exact same name, like folders, VMs, resource pools, and so on...
Basically you need to use a point of reference to determine if you have the right object when searching by name. For folders, you might check the parent, and maybe some child folders if they're available or known. For a virtual switch? I'm not too familiar with what containers it would be in.
I think get_mor_by_property supports a container ref, but I'm not sure how it would be used and would probably require a bunch of code and config changes to work in a way that makes sense. Unless someone has a better vision for it.
Maybe try testing with the develop version of get_mor_by_property. It's in salt/utils/vmware.py
With the salt/utils/vmware.py version from DEV branch it works.
https://raw.githubusercontent.com/saltstack/salt/develop/salt/utils/vmware.py
Hi!
I can't get it to work with the latest dev version. Which settings did you use?
Out VMWare settings:
root@salt:/etc/salt/cloud.profiles.d# salt-cloud -f list_networks vmware zim-vcenter: ---------- vmware: ---------- Networks: - Management - VM Network - dPG ad0 (299) - dPG alcatraz (91) - dPG azubinet (972) - dPG backup (218) - dPG bibsearch (119)
root@salt:/etc/salt/cloud.profiles.d# salt-cloud -f list_portgroups vmware zim-vcenter: ---------- vmware: ---------- Portgroups: - dPG ad0 (299) - dPG alcatraz (91) - dPG azubinet (972) - dPG backup (218) - dPG bibsearch (119)
root@salt:/etc/salt/cloud.profiles.d# salt-cloud -f list_dvs vmware zim-vcenter: ---------- vmware: ---------- Distributed Virtual Switches: - DSwitch ZIM zentral
There is also an issue where salt-cloud will build the VM, but because of a duplicate network / portgroup names in vcenter (for example, two dvportgroups named "DEV" that are on different switches) there will be no network connectivity.
@PabloLemos earlier suggestion would fix this: switch_type: distributed dvs_switch: dvSwitch2
Or maybe a way to just insert the MoRef directly into the profile/map would be even better.
Thanks for clearing this up, @legnej ! I've added "dvs_switch: ourSwitchName" and it will clone the vm and add a nic, but then it will throw a new error and the vm doesn't get started (note, there really are no strange characters in the profile...):
[ERROR ] There was a profile error: 'ascii' codec can't encode character u'\xfc' in position 98: ordinal not in range(128) Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/salt/cloud/cli.py", line 284, in run self.config.get('names') File "/usr/lib/python2.7/dist-packages/salt/cloud/init.py", line 1457, in run_profile ret[name] = self.create(vm_) File "/usr/lib/python2.7/dist-packages/salt/cloud/init.py", line 1287, in create output = self.cloudsfunc File "/usr/lib/python2.7/dist-packages/salt/cloud/clouds/vmware.py", line 2691, in create err_msg = 'Error creating {0}: {1}'.format(vm_['name'], exc) UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in position 98: ordinal not in range(128)
Here's the profile I use:
vmware-debian9-neueIP: provider: zim-vcenter deploy: True resourcepool: Test datacenter: "ZIM Zentral" datastore: ZR_3par_bronze.0 clonefrom: salt-debian9-template private_key: /srv/salt/ssh/id_rsa ssh_username: root memory: 8GB devices: network: Network adapter 1: name: "dvPG zim (220)" dvs_switch: "DSwitch ZIM zentral" switch_type: distributed ip: 132.195.221.12 gateway: [132.195.223.254] subnet_mask: 255.255.252.0 domain: zim.uni-wuppertal.de dns_servers: - 132.195.249.13
Ok it works after applying the proposed fix from here: https://github.com/saltstack/salt/issues/38402
(I now get the error, that customising Debian hosts is not supported... but that is a different story... ;) )
The patch works fine!!!!
Thanks for the work!!!
ok, can we close this issue?
It is unfortunate that we can't come up with a really overarching fix right now, but I think this issue is solved for now.
Thanks, Daniel
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.