ovirt: Backport of bug fixes for 2.6 (#41092)

* ovirt_vms: Fix change cd (#40939)

* ovirt_vms: Fix attaching of CD

* ovirt_vms: Fix idemptency

* ovirt_templates: Add searching by cluster (#40934)

* ovirt_templates: Add searching by cluster

* ovirt_disks: Add searching by sd and vm_name

* Fix python syntax
pull/41109/head
Ondra Machacek 7 years ago committed by Matt Clay
parent e8d8fa4e1a
commit 773fdeb6f0

@ -555,6 +555,18 @@ class DiskAttachmentsModule(DisksModule):
)
def searchable_attributes(module):
"""
Return all searchable disk attributes passed to module.
"""
attributes = {
'name': module.params.get('name'),
'Storage.name': module.params.get('storage_domain'),
'vm_names': module.params.get('vm_name'),
}
return dict((k, v) for k, v in attributes.items() if v is not None)
def main():
argument_spec = ovirt_full_argument_spec(
state=dict(
@ -616,6 +628,7 @@ def main():
if state in ('present', 'detached', 'attached'):
ret = disks_module.create(
entity=disk,
search_params=searchable_attributes(module),
result_state=otypes.DiskStatus.OK if lun is None else None,
fail_condition=lambda d: d.status == otypes.DiskStatus.ILLEGAL if lun is None else False,
)

@ -422,6 +422,17 @@ def _get_vnic_profile_mappings(module):
return vnicProfileMappings
def searchable_attributes(module):
"""
Return all searchable template attributes passed to module.
"""
attributes = {
'name': module.params.get('name'),
'cluster': module.params.get('cluster'),
}
return dict((k, v) for k, v in attributes.items() if v is not None)
def main():
argument_spec = ovirt_full_argument_spec(
state=dict(
@ -474,6 +485,7 @@ def main():
if state == 'present':
ret = templates_module.create(
result_state=otypes.TemplateStatus.OK,
search_params=searchable_attributes(module),
clone_permissions=module.params['clone_permissions'],
seal=module.params['seal'],
)

@ -1186,8 +1186,9 @@ class VmsModule(BaseModule):
def post_present(self, entity_id):
# After creation of the VM, attach disks and NICs:
entity = self._service.service(entity_id).get()
self.changed = self.__attach_disks(entity)
self.changed = self.__attach_nics(entity)
self.__attach_disks(entity)
self.__attach_nics(entity)
self._attach_cd(entity)
self.changed = self.__attach_numa_nodes(entity)
self.changed = self.__attach_watchdog(entity)
self.changed = self.__attach_graphical_console(entity)
@ -1239,7 +1240,7 @@ class VmsModule(BaseModule):
cd_iso = self.param('cd_iso')
if cd_iso is not None:
vm_service = self._service.service(entity.id)
current = vm_service.get().status == otypes.VmStatus.UP
current = vm_service.get().status == otypes.VmStatus.UP and self.param('state') == 'running'
cdroms_service = vm_service.cdroms_service()
cdrom_device = cdroms_service.list()[0]
cdrom_service = cdroms_service.cdrom_service(cdrom_device.id)
@ -1339,7 +1340,7 @@ class VmsModule(BaseModule):
def __attach_graphical_console(self, entity):
graphical_console = self.param('graphical_console')
if not graphical_console:
return
return False
vm_service = self._service.service(entity.id)
gcs_service = vm_service.graphics_consoles_service()
@ -1450,6 +1451,7 @@ class VmsModule(BaseModule):
)
def __attach_numa_nodes(self, entity):
updated = False
numa_nodes_service = self._service.service(entity.id).numa_nodes_service()
if len(self.param('numa_nodes')) > 0:
@ -1458,10 +1460,11 @@ class VmsModule(BaseModule):
existed_numa_nodes.sort(reverse=len(existed_numa_nodes) > 1 and existed_numa_nodes[1].index > existed_numa_nodes[0].index)
for current_numa_node in existed_numa_nodes:
numa_nodes_service.node_service(current_numa_node.id).remove()
updated = True
for numa_node in self.param('numa_nodes'):
if numa_node is None or numa_node.get('index') is None or numa_node.get('cores') is None or numa_node.get('memory') is None:
return False
continue
numa_nodes_service.add(
otypes.VirtualNumaNode(
@ -1481,8 +1484,9 @@ class VmsModule(BaseModule):
] if numa_node.get('numa_node_pins') is not None else None,
)
)
updated = True
return True
return updated
def __attach_watchdog(self, entity):
watchdogs_service = self._service.service(entity.id).watchdogs_service()
@ -2002,11 +2006,9 @@ def main():
clone=module.params['clone'],
clone_permissions=module.params['clone_permissions'],
)
vms_module.post_present(ret['id'])
if module.params['force']:
ret = vms_module.action(
action='stop',
post_action=vms_module._attach_cd,
action_condition=lambda vm: vm.status != otypes.VmStatus.DOWN,
wait_condition=vms_module.wait_for_down,
)
@ -2014,10 +2016,10 @@ def main():
ret = vms_module.action(
action='shutdown',
pre_action=vms_module._pre_shutdown_action,
post_action=vms_module._attach_cd,
action_condition=lambda vm: vm.status != otypes.VmStatus.DOWN,
wait_condition=vms_module.wait_for_down,
)
vms_module.post_present(ret['id'])
elif state == 'suspended':
vms_module.create(
entity=vm,

Loading…
Cancel
Save