salt-cloud (non templated) VM deploy to an ESXi Host returns a profile error 'container_ref' referenced before assignment
Description of Issue/Question
I am trying to create a new blank Virtual Machine using this shiny new feature introduced in 2016.3.0 via salt-cloud with a target of a single ESXi host
(NOTE: Not using vCenter, thus no template in use nor specified)
This is related to issue #34880 after a workaround thus the same provider and profile configuration is being used to give this issue instead.
ERROR: [ERROR ] There was a profile error: local variable 'container_ref' referenced before assignment
I'm guessing this is something that will appear when issue #34880 is fixed by the team but I suppose it could also be something else?
Setup
- Single Salt-Master with Salt-Cloud installed, both at version 2016.3.1
- Followed guide: https://docs.saltstack.com/en/latest/topics/cloud/vmware.html#creating-a-vm
- Target is a single ESXI host using a very basic provider configuration
- Profile & Provider configured as per #34880
Steps to Reproduce Issue
- Create provider & profile as per above
- Update /usr/lib/python2.7/dist-packages/salt/config/init.py to include the below:
if driver == 'linode' and profile_key.get('clonefrom'): linode_cloning = True non_image_drivers.append('linode') non_size_drivers.append('linode')
if driver == 'vmware' and profile_key.get('clonefrom') is None: non_image_drivers.append('vmware')
if driver in non_image_drivers: required_keys.append('image')
- Rename
__init__.pyc - Restart the Salt-Master service
- Attempt to create a new Virtual Machine on a standalone host, this error is given:
[ERROR ] There was a profile error: local variable 'container_ref' referenced before assignment
Versions Report
Salt Version: Salt: 2016.3.1
Dependency Versions: cffi: Not Installed cherrypy: 3.5.0 dateutil: 2.4.2 gitdb: 0.6.4 gitpython: 1.0.1 ioflo: Not Installed Jinja2: 2.8 libgit2: Not Installed libnacl: Not Installed M2Crypto: Not Installed Mako: 1.0.3 msgpack-pure: Not Installed msgpack-python: 0.4.6 mysql-python: Not Installed pycparser: Not Installed pycrypto: 2.6.1 pygit2: Not Installed Python: 2.7.12 (default, Jul 1 2016, 15:12:24) python-gnupg: Not Installed PyYAML: 3.11 PyZMQ: 15.2.0 RAET: Not Installed smmap: 0.9.0 timelib: Not Installed Tornado: 4.2.1 ZMQ: 4.1.4
System Versions: dist: Ubuntu 16.04 xenial machine: x86_64 release: 4.4.0-28-generic system: Linux version: Ubuntu 16.04 xenial
think i've been able to fix this, salt packages on debian 8, fully updated.
dpkg -l | grep -i salt ii salt-cloud 2016.3.1+ds-1 all public cloud VM management system ii salt-common 2016.3.1+ds-1 all shared libraries that salt requires for all packages ii salt-master 2016.3.1+ds-1 all remote manager to administer servers via salt ii salt-minion 2016.3.1+ds-1 all client package for salt, the distributed remote execution system
dpkg -l | grep -i vmomi ii python-pyvmomi 6.0.0-1 all VMware vSphere Python SDK - Python 2.x
diff vmware.py vmware.py-2016080101
2196c2196
< resourcepool_ref = salt.utils.vmware.get_mor_by_property(_get_si(), vim.ResourcePool, resourcepool, container_ref=None)
---
> resourcepool_ref = salt.utils.vmware.get_mor_by_property(_get_si(), vim.ResourcePool, resourcepool, container_ref=container_ref)
2223c2223
< folder_ref = salt.utils.vmware.get_mor_by_property(_get_si(), vim.Folder, folder, container_ref=None)
---
> folder_ref = salt.utils.vmware.get_mor_by_property(_get_si(), vim.Folder, folder, container_ref=container_ref)
2423c2423
< new_vm_ref = salt.utils.vmware.get_mor_by_property(_get_si(), vim.VirtualMachine, vm_name, container_ref=None)
---
> new_vm_ref = salt.utils.vmware.get_mor_by_property(_get_si(), vim.VirtualMachine, vm_name, container_ref=container_ref)
also update the following line from /usr/lib/python2.7/dist-packages/salt/config/init.py :
elif driver == 'vmware' or linode_cloning:
required_keys.append('clonefrom')
to
elif driver == linode_cloning:
required_keys.append('clonefrom')
this allowed me to create a vm from scratch.
@abrinded would you mind giving the fix in #35099 a try and seeing if that resolves your issue?
Hi @Ch3LL I am currently using some of the code @otupman put forward and its working fine for what i need it to do (creation of new VMs against an ESXi6 host)