salt icon indicating copy to clipboard operation
salt copied to clipboard

salt-cloud (non templated) VM deploy to an ESXi Host appears to require a "clonefrom" parameter

Open abrinded opened this issue 10 years ago • 9 comments

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)

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
esx01:
  driver: vmware
  user: 'root'
  password: 'password'
  url: '192.168.1.13'
  • Using a very basic profile configuration
base-gold:
  provider: esx01
  datastore: Datastore1
  resourcepool: Resources
  folder: vm

  ## Optional arguments
  num_cpus: 1
  memory: 4GB
  devices:
    cd:
      CD/DVD drive 1:
        controller: 'IDE 0'
        device_type: datastore_iso_file
        iso_path: "[Datastore1] ISOs/Microsoft/WindowsServer2012R2.iso"
    disk:
      Hard disk 1:
        size: 40
        controller: 'SCSI controller 1'
    network:
      Network adapter 1:
        name: 'VM Network'
        adapter_type: e1000
        switch_type: standard
    scsi:
      SCSI controller 1:
        type: lsilogic
    ide:
      IDE 0
      IDE 1

  deploy: True
  customization: False
  power_on: True
  hardware_version: 10
  image: windows8Server64Guest
  • Using the following command salt-cloud -f test_vcenter_connection esx01 returns success
  • I couldn't find a test_esxi_connection thus assumed because it returned success, this would be fine
esx01:
    ----------
    vmware:
        connection successful
  • Using command salt-cloud -p base-gold TESTVM -l debug fails to deploy

[ERROR ] The required 'clonefrom' configuration setting is missing from the 'base-gold' profile, which is configured under the 'esx01' alias. Error: There was a profile error: Failed to deploy VM

  • Other commands work fine, for example listing datastores
esx01:
    ----------
    vmware:
        ----------
        Datastores:
            - Datastore1
            - Datastore2
  • Weirdly enough if I specify a template name with the name of an existing VM on my ESXI host, which is obviously not a template, I get a different error, as for whether its relevant, no idea.
[ERROR   ] There was a profile error: 'str' object has no attribute 'keys'
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 1446, in run_profile
    ret[name] = self.create(vm_)
  File "/usr/lib/python2.7/dist-packages/salt/cloud/__init__.py", line 1281, in create
    output = self.clouds[func](vm_)
  File "/usr/lib/python2.7/dist-packages/salt/cloud/clouds/vmware.py", line 2319, in create
    specs = _manage_devices(devices, object_ref)
  File "/usr/lib/python2.7/dist-packages/salt/cloud/clouds/vmware.py", line 687, in _manage_devices
    ide_controllers_to_create = list(set(devices['ide'].keys()) - set(existing_ide_controllers_label))
AttributeError: 'str' object has no attribute 'keys'

Steps to Reproduce Issue

  • Create provider as per above
  • Create profile as per above
  • Attempt to create a new Virtual Machine on a standalone host

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

abrinded avatar Jul 22 '16 14:07 abrinded

Digging through this I believe I've identified the line that causes this:

elif driver == 'vmware' or linode_cloning:
    required_keys.append('clonefrom')

So it looks like whenever the driver is vmware it always requires the clonefrom parameter in the profile, which then causes vm creation to follow a whole different path.

I've checked this against the devel branch and it's still present; not sure whether this is intentional (i.e. one should not deploy without using cloning) or not.

Perhaps the best approach would be to have one driver for ESX and one for vCenter?

otupman avatar Jul 25 '16 16:07 otupman

@nmadhok can I get your opinions here? Do you think the clonefrom parameter should be required? any opinions on the approach of multiple drivers? thanks

Ch3LL avatar Jul 26 '16 17:07 Ch3LL

develop branch contains the fix. The fix needs to be backported to 2016.3 branch. Specifying image is required when creating the VM and specifying clonefrom is required when cloning a VM. Either image or clonefrom must be specified in the profile.

https://github.com/saltstack/salt/blob/develop/salt/config/init.py#L2854

nmadhok avatar Jul 26 '16 18:07 nmadhok

Actually from looking at the code and writing some tests I validated that the fix is not working. Specifically because of:

if driver == 'vmware' and profile_key.get('image', True):
    non_image_drivers.append('vmware')

So it's calling profile_key.get('image', True') which will always return true, even if the image key is present and so would append vmware to non_image_drivers and then require clonefrom later on.

I've submitted a fix - including 3 tests for the issue - on PR https://github.com/saltstack/salt/pull/35017

otupman avatar Jul 28 '16 12:07 otupman

Today I ran into this issue but managed to get around it by extending the IDE-entries in the profile like this:

    ide:
      IDE 0:
        key: 200
        type: VirtualIDEController
      IDE 1:
        key: 201
        type: VirtualIDEController

Since the error complains about existing_ide_controllers_label and (devices['ide'].keys()), I checked with salt-cloud -f list_nodes_full esxi01 what was expected, which turns out to be something like this:

devices:
  ---------

[ ... ]

IDE 0:
    ----------
    busNumber:
        0
    deviceKeys:
        - 3000
    key:
        200
    label:
        IDE 0
    summary:
        IDE 0
    type:
        VirtualIDEController

HTH! If the above is right, then it should be included in Salt-docs too IMHO.

Update - just found #39146 ...

hbokh avatar Feb 11 '17 11:02 hbokh

@otupman looks like you resolved this with #35099 @abrinded can you confirm this is fixed for you?

Ch3LL avatar Feb 14 '17 19:02 Ch3LL

salt-cloud -f is the cloning command and therefore you need to use the "clonefrom" parameter , for creating a new machine you should use the salt-cloud -p command.

felixuma avatar Jun 12 '17 12:06 felixuma

@Ch3LL This issue can be closed as this doesn't seem to be an issue anymore and has been fixed

nmadhok avatar Jun 12 '17 22:06 nmadhok

Thanks everyone for following up here. I agree that this can be closed now. Please let us know if this problem pops up again and we will be happy to open this issue once more.

rallytime avatar Jun 12 '17 22:06 rallytime