Add ability to clone from a snapshot to salt-cloud vmware driver

This commit is contained in:
Aditya Kulkarni 2016-09-12 14:14:29 -04:00
parent 6ebe655e17
commit d96981639b
4 changed files with 49 additions and 6 deletions

BIN
doc/_static/snapshot_manager.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 297 KiB

View file

@ -530,6 +530,32 @@ Example of a minimal profile:
cluster: 'Prod'
Cloning from a Snapshot
=======================
.. versionadded:: Carbon
Cloning a template works similar to cloning a VM except for the fact that
a snapshot number must be provided.
Example of a minimal profile:
.. code-block:: yaml
my-template-clone:
provider: vcenter01
clonefrom: 'salt_vm'
snapshot: 3
.. image:: /_static/snapshot_manager.png
:align: center
:scale: 70%
.. note::
The previous diagram shows how to identify the snapshot number. Selected
(third snapshot) is number 3.
Creating a VM
=============

View file

@ -7,3 +7,4 @@ Version 2016.3.4 is a bugfix release for :doc:`2016.3.0
- The `disk.wipe` execution module function has been modified
so that it correctly wipes a disk.
- Add ability to clone from a snapshot to the VMWare salt-cloud driver.

View file

@ -2187,6 +2187,14 @@ def create(vm_):
raise SaltCloudSystemExit(
'The VM/template that you have specified under clonefrom does not exist.'
)
snapshot = None
if clone_type == 'vm' and 'snapshot' in vm_:
num = int(vm_['snapshot']) - 1
snapshot = object_ref.rootSnapshot[0]
# Drill down to the correct snapshot number
for i in range(num):
snapshot = snapshot.childSnapshot[0]
else:
clone_type = None
object_ref = None
@ -2325,12 +2333,20 @@ def create(vm_):
config_spec.extraConfig.append(option)
if 'clonefrom' in vm_:
# Create the clone specs
clone_spec = vim.vm.CloneSpec(
template=template,
location=reloc_spec,
config=config_spec
)
if not snapshot:
# Create the clone specs
clone_spec = vim.vm.CloneSpec(
template=template,
location=reloc_spec,
config=config_spec
)
else:
clone_spec = vim.vm.CloneSpec(
template=template,
location=reloc_spec,
config=config_spec,
snapshot=snapshot
)
if customization and (devices and 'network' in list(devices.keys())) and 'Windows' not in object_ref.config.guestFullName:
global_ip = vim.vm.customization.GlobalIPSettings()