|
|
|
@ -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)."
|
|
|
|
|
state:
|
|
|
|
|
description:
|
|
|
|
|
- "Should the Virtual Machine disk be present/absent/attached/detached/exported."
|
|
|
|
|
choices: ['present', 'absent', 'attached', 'detached', 'exported']
|
|
|
|
|
- "Should the Virtual Machine disk be present/absent/attached/detached/exported/imported."
|
|
|
|
|
choices: ['present', 'absent', 'attached', 'detached', 'exported', 'imported']
|
|
|
|
|
default: 'present'
|
|
|
|
|
download_image_path:
|
|
|
|
|
description:
|
|
|
|
@ -168,6 +168,7 @@ options:
|
|
|
|
|
image_provider:
|
|
|
|
|
description:
|
|
|
|
|
- "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**)"
|
|
|
|
|
- "There is no reliable way to achieve idempotency, so every time
|
|
|
|
|
you specify this parameter the disk is exported, so please handle
|
|
|
|
@ -328,6 +329,7 @@ from ansible.module_utils.ovirt import (
|
|
|
|
|
follow_link,
|
|
|
|
|
get_id_by_name,
|
|
|
|
|
ovirt_full_argument_spec,
|
|
|
|
|
get_dict_of_struct,
|
|
|
|
|
search_by_name,
|
|
|
|
|
wait,
|
|
|
|
|
)
|
|
|
|
@ -634,7 +636,7 @@ def get_vm_service(connection, module):
|
|
|
|
|
def main():
|
|
|
|
|
argument_spec = ovirt_full_argument_spec(
|
|
|
|
|
state=dict(
|
|
|
|
|
choices=['present', 'absent', 'attached', 'detached', 'exported'],
|
|
|
|
|
choices=['present', 'absent', 'attached', 'detached', 'exported', 'imported'],
|
|
|
|
|
default='present'
|
|
|
|
|
),
|
|
|
|
|
id=dict(default=None),
|
|
|
|
@ -762,6 +764,25 @@ def main():
|
|
|
|
|
wait_condition=lambda d: d.status == otypes.DiskStatus.OK,
|
|
|
|
|
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':
|
|
|
|
|
ret = disks_module.remove()
|
|
|
|
|
|
|
|
|
|