Skip to content

Commit 30bd585

Browse files
committed
Update rhevm template kwargs, handle disk attachments
draft state add_disk kwargs for name/format/sparse updated disk_attachments handling for template deploy. needs some consideration of the tradeoffs, and whether the kwarg should contain the attachments that should exist - or just modifications to attachments on the template that match by name.
1 parent 3fb310d commit 30bd585

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

wrapanapi/systems/rhevm.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -596,11 +596,15 @@ def deploy(self, vm_name, cluster, timeout=900, power_on=True, **kwargs):
596596
sockets (optional) -- numbner of cpu sockets
597597
ram (optional) -- memory in GB
598598
storage_domain (optional) -- storage domain name to which VM should be deployed
599+
disk_attachments (optional) -- list of dicts defining (name (partial), format, sparse)
600+
name of template disks will be partial matched
601+
format defaults to COW
602+
sparse defaults to True (thin provisioning)
599603
600604
Returns:
601605
wrapanapi.systems.rhevm.RHEVMVirtualMachine
602606
"""
603-
self.logger.debug(' Deploying RHEV template %s to VM %s', self.name, vm_name)
607+
self.logger.debug('Deploying RHEV template %s to VM %s', self.name, vm_name)
604608
vm_kwargs = {
605609
'name': vm_name,
606610
'cluster': self.system.get_cluster(cluster),
@@ -609,22 +613,32 @@ def deploy(self, vm_name, cluster, timeout=900, power_on=True, **kwargs):
609613
clone = None
610614
domain_name = kwargs.get('storage_domain')
611615
if domain_name:
616+
target_attachments = kwargs.get('disk_attachments', [])
612617
# need to specify storage domain, if its different than the template's disks location
613618
# then additional options required. disk allocation mode in UI required to be clone
614619
clone = True
615620
target_storage_domain = self.system.get_storage_domain(domain_name)
616621
disk_attachments = []
617-
for template_attachment in self.api.disk_attachments_service().list():
618-
new_attachment = types.DiskAttachment(
619-
disk=types.Disk(
620-
id=template_attachment.id,
621-
format=types.DiskFormat.COW,
622-
storage_domains=[target_storage_domain]
623-
)
624-
)
625-
disk_attachments.append(new_attachment)
622+
for template_attachment in self.api.disk_attachments_service().list(follow='disk'):
623+
disk_kwargs = dict(id=template_attachment.id,
624+
storage_domains=[target_storage_domain])
625+
for target_disk in target_attachments:
626+
target_name = target_disk.get('name')
627+
if target_name in template_attachment.disk.name:
628+
self.logger.debug('Matched partial disk from template: %s', target_name)
629+
disk_kwargs.update(
630+
dict(
631+
format=types.DiskFormat(target_disk.get('format', 'raw').lower()),
632+
sparse=bool(target_disk.get('sparse', True))
633+
)
634+
)
635+
else:
636+
self.logger.info('Template disk name not matching any disk_attachment names')
637+
638+
disk_attachments.append(disk_kwargs)
626639

627-
vm_kwargs['disk_attachments'] = disk_attachments
640+
vm_kwargs['disk_attachments'] = [types.DiskAttachment(disk=types.Disk(**dkwargs))
641+
for dkwargs in disk_attachments]
628642

629643
# Placement requires two args
630644
if 'placement_policy_host' in kwargs and 'placement_policy_affinity' in kwargs:

0 commit comments

Comments
 (0)