Skip to content

Commit

Permalink
Add ability to clone from a snapshot to salt-cloud vmware driver
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya Kulkarni committed Sep 12, 2016
1 parent 6ebe655 commit d969816
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 6 deletions.
Binary file added doc/_static/snapshot_manager.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions doc/topics/cloud/vmware.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=============

Expand Down
1 change: 1 addition & 0 deletions doc/topics/releases/2016.3.4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
28 changes: 22 additions & 6 deletions salt/cloud/clouds/vmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit d969816

Please sign in to comment.