ovirt_disk add state imported (#62859)

* ovirt_disk add state imported

* change search_by_name to get_id_by_name

* add disk_module.create as ret
pull/63460/head
Martin Nečas 5 years ago committed by ansibot
parent aa0d4ef4ab
commit 2fe2a12440

@ -37,8 +37,8 @@ options:
- "ID of the Virtual Machine to manage. Either C(vm_id) or C(vm_name) is required if C(state) is I(attached) or I(detached)." - "ID of the Virtual Machine to manage. Either C(vm_id) or C(vm_name) is required if C(state) is I(attached) or I(detached)."
state: state:
description: description:
- "Should the Virtual Machine disk be present/absent/attached/detached/exported." - "Should the Virtual Machine disk be present/absent/attached/detached/exported/imported."
choices: ['present', 'absent', 'attached', 'detached', 'exported'] choices: ['present', 'absent', 'attached', 'detached', 'exported', 'imported']
default: 'present' default: 'present'
download_image_path: download_image_path:
description: description:
@ -168,6 +168,7 @@ options:
image_provider: image_provider:
description: description:
- "When C(state) is I(exported) disk is exported to given Glance image provider." - "When C(state) is I(exported) disk is exported to given Glance image provider."
- "When C(state) is I(imported) disk is imported from given Glance image provider."
- "C(**IMPORTANT**)" - "C(**IMPORTANT**)"
- "There is no reliable way to achieve idempotency, so every time - "There is no reliable way to achieve idempotency, so every time
you specify this parameter the disk is exported, so please handle you specify this parameter the disk is exported, so please handle
@ -328,6 +329,7 @@ from ansible.module_utils.ovirt import (
follow_link, follow_link,
get_id_by_name, get_id_by_name,
ovirt_full_argument_spec, ovirt_full_argument_spec,
get_dict_of_struct,
search_by_name, search_by_name,
wait, wait,
) )
@ -634,7 +636,7 @@ def get_vm_service(connection, module):
def main(): def main():
argument_spec = ovirt_full_argument_spec( argument_spec = ovirt_full_argument_spec(
state=dict( state=dict(
choices=['present', 'absent', 'attached', 'detached', 'exported'], choices=['present', 'absent', 'attached', 'detached', 'exported', 'imported'],
default='present' default='present'
), ),
id=dict(default=None), id=dict(default=None),
@ -762,6 +764,25 @@ def main():
wait_condition=lambda d: d.status == otypes.DiskStatus.OK, wait_condition=lambda d: d.status == otypes.DiskStatus.OK,
storage_domain=otypes.StorageDomain(name=module.params['image_provider']), storage_domain=otypes.StorageDomain(name=module.params['image_provider']),
) )
elif state == 'imported':
glance_service = connection.system_service().openstack_image_providers_service()
image_provider = search_by_name(glance_service, module.params['image_provider'])
images_service = glance_service.service(image_provider.id).images_service()
entity_id = get_id_by_name(images_service, module.params['name'])
images_service.service(entity_id).import_(
storage_domain=otypes.StorageDomain(
name=module.params['storage_domain']
) if module.params['storage_domain'] else None,
disk=otypes.Disk(
name=module.params['name']
),
import_as_template=False,
)
# Wait for disk to appear in system:
disk = disks_module.wait_for_import(
condition=lambda t: t.status == otypes.DiskStatus.OK
)
ret = disks_module.create(result_state=otypes.DiskStatus.OK)
elif state == 'absent': elif state == 'absent':
ret = disks_module.remove() ret = disks_module.remove()

Loading…
Cancel
Save