mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
Merge pull request #37245 from rallytime/bp-36334
Back-port #36334 to 2016.3
This commit is contained in:
commit
bb7caf8c42
@ -612,6 +612,7 @@ Example of a complete profile:
|
||||
Hard disk 0:
|
||||
controller: 'SCSI controller 0'
|
||||
size: 20
|
||||
mode: 'independent_nonpersistent'
|
||||
cd:
|
||||
CD/DVD drive 0:
|
||||
controller: 'IDE 0'
|
||||
@ -628,3 +629,30 @@ Example of a complete profile:
|
||||
be available. In such cases, the closest match to another ``image`` should
|
||||
be used. In the example above, a Debian 8 VM is created using the image
|
||||
``debian7_64Guest`` which is for a Debian 7 guest.
|
||||
|
||||
|
||||
Specifying disk backing mode
|
||||
============================
|
||||
|
||||
.. versionadded:: Nitrogen
|
||||
|
||||
Disk backing mode can now be specified when cloning a VM. This option
|
||||
can be set in the cloud profile as shown in example below:
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
my-vm:
|
||||
provider: esx01
|
||||
datastore: esx01-datastore
|
||||
resourcepool: Resources
|
||||
folder: vm
|
||||
|
||||
|
||||
devices:
|
||||
disk:
|
||||
Hard disk 1:
|
||||
mode: 'independent_nonpersistent'
|
||||
|
||||
Hard disk 2:
|
||||
size: 15
|
||||
mode: 'independent_nonpersistent'
|
||||
|
@ -24,6 +24,7 @@ Changes
|
||||
- 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.
|
||||
- Add ability to specify disk backing mode in the VMWare salt cloud profile.
|
||||
|
||||
Changes for v2016.3.3..v2016.3.4
|
||||
--------------------------------
|
||||
|
@ -270,6 +270,15 @@ def _edit_existing_hard_disk_helper(disk, size_kb):
|
||||
return disk_spec
|
||||
|
||||
|
||||
def _edit_existing_hard_disk_mode_helper(disk, mode):
|
||||
disk_spec = vim.vm.device.VirtualDeviceSpec()
|
||||
disk_spec.operation = vim.vm.device.VirtualDeviceSpec.Operation.edit
|
||||
disk.backing.diskMode = mode
|
||||
disk_spec.device = disk
|
||||
|
||||
return disk_spec
|
||||
|
||||
|
||||
def _add_new_hard_disk_helper(disk_label, size_gb, unit_number, controller_key=1000, thin_provision=False):
|
||||
random_key = randint(-2099, -2000)
|
||||
|
||||
@ -601,15 +610,30 @@ def _manage_devices(devices, vm=None, container_ref=None):
|
||||
if isinstance(device, vim.vm.device.VirtualDisk):
|
||||
# this is a hard disk
|
||||
if 'disk' in list(devices.keys()):
|
||||
# there is atleast one disk specified to be created/configured
|
||||
# there is at least one disk specified to be created/configured
|
||||
unit_number += 1
|
||||
existing_disks_label.append(device.deviceInfo.label)
|
||||
if device.deviceInfo.label in list(devices['disk'].keys()):
|
||||
size_gb = float(devices['disk'][device.deviceInfo.label]['size'])
|
||||
size_kb = int(size_gb * 1024.0 * 1024.0)
|
||||
if device.capacityInKB < size_kb:
|
||||
# expand the disk
|
||||
disk_spec = _edit_existing_hard_disk_helper(device, size_kb)
|
||||
disk_spec = None
|
||||
if 'size' in devices['disk'][device.deviceInfo.label]:
|
||||
disk_spec = _get_size_spec(device, devices)
|
||||
|
||||
if 'mode' in devices['disk'][device.deviceInfo.label]:
|
||||
if devices['disk'][device.deviceInfo.label]['mode'] \
|
||||
in [
|
||||
'independent_persistent',
|
||||
'persistent',
|
||||
'independent_nonpersistent',
|
||||
'nonpersistent',
|
||||
'undoable',
|
||||
'append'
|
||||
]:
|
||||
disk_spec = _get_mode_spec(device, devices, disk_spec)
|
||||
else:
|
||||
raise SaltCloudSystemExit('Invalid disk'
|
||||
' backing mode'
|
||||
' specified!')
|
||||
if disk_spec:
|
||||
device_specs.append(disk_spec)
|
||||
|
||||
elif isinstance(device.backing, vim.vm.device.VirtualEthernetCard.NetworkBackingInfo) or isinstance(device.backing, vim.vm.device.VirtualEthernetCard.DistributedVirtualPortBackingInfo):
|
||||
@ -755,6 +779,31 @@ def _manage_devices(devices, vm=None, container_ref=None):
|
||||
return ret
|
||||
|
||||
|
||||
def _get_mode_spec(device, devices, disk_spec):
|
||||
if device.backing.diskMode != \
|
||||
devices['disk'][device.deviceInfo.label]['mode']:
|
||||
if not disk_spec:
|
||||
disk_spec = \
|
||||
_edit_existing_hard_disk_mode_helper(
|
||||
device,
|
||||
devices['disk'][device.deviceInfo.label]['mode']
|
||||
)
|
||||
else:
|
||||
disk_spec.device.backing.diskMode = \
|
||||
devices['disk'][device.deviceInfo.label]['mode']
|
||||
return disk_spec
|
||||
|
||||
|
||||
def _get_size_spec(device, devices):
|
||||
size_gb = float(devices['disk'][device.deviceInfo.label]['size'])
|
||||
size_kb = int(size_gb * 1024.0 * 1024.0)
|
||||
disk_spec = None
|
||||
if device.capacityInKB < size_kb:
|
||||
# expand the disk
|
||||
disk_spec = _edit_existing_hard_disk_helper(device, size_kb)
|
||||
return disk_spec
|
||||
|
||||
|
||||
def _wait_for_vmware_tools(vm_ref, max_wait):
|
||||
time_counter = 0
|
||||
starttime = time.time()
|
||||
|
Loading…
Reference in New Issue
Block a user