Merge "Migrating image_info module from AnsibleModule to OpenStackModule"
This commit is contained in:
commit
7e20a8fc97
@ -15,7 +15,16 @@
|
||||
disk_format: raw
|
||||
register: image
|
||||
|
||||
- debug: var=image
|
||||
- name: Get details of created image
|
||||
openstack.cloud.image_info:
|
||||
cloud: "{{ cloud }}"
|
||||
image: "{{ image_name }}"
|
||||
register: image_info_result
|
||||
|
||||
- name: Verify image info
|
||||
assert:
|
||||
that:
|
||||
- "image_info_result.openstack_image.name == image_name"
|
||||
|
||||
- name: Delete raw image (defaults)
|
||||
openstack.cloud.image:
|
||||
@ -40,8 +49,6 @@
|
||||
distro: ubuntu
|
||||
register: image
|
||||
|
||||
- debug: var=image
|
||||
|
||||
- name: Delete raw image (complex)
|
||||
openstack.cloud.image:
|
||||
cloud: "{{ cloud }}"
|
||||
@ -52,3 +59,14 @@
|
||||
file:
|
||||
name: "{{ tmp_file.stdout }}"
|
||||
state: absent
|
||||
|
||||
- name: Try to get details of deleted image
|
||||
openstack.cloud.image_info:
|
||||
cloud: "{{ cloud }}"
|
||||
image: "{{ image_name }}"
|
||||
register: deleted_image_info_result
|
||||
|
||||
- name: Verify image is deleted
|
||||
assert:
|
||||
that:
|
||||
- not deleted_image_info_result.openstack_image
|
@ -142,44 +142,31 @@ openstack_image:
|
||||
type: int
|
||||
'''
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import (openstack_full_argument_spec,
|
||||
openstack_module_kwargs,
|
||||
openstack_cloud_from_module)
|
||||
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import OpenStackModule
|
||||
|
||||
|
||||
class ImageInfoModule(OpenStackModule):
|
||||
|
||||
deprecated_names = ('openstack.cloud.os_image_facts', 'openstack.cloud.os_image_info')
|
||||
|
||||
argument_spec = dict(
|
||||
image=dict(type='str', required=False),
|
||||
properties=dict(type='dict', required=False),
|
||||
)
|
||||
|
||||
def run(self):
|
||||
|
||||
if self.params['image']:
|
||||
image = self.conn.get_image(self.params['image'])
|
||||
self.exit(changed=False, openstack_image=image)
|
||||
else:
|
||||
images = self.conn.search_images(filters=self.params['properties'])
|
||||
self.exit(changed=False, openstack_image=images)
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
argument_spec = openstack_full_argument_spec(
|
||||
image=dict(required=False),
|
||||
properties=dict(default=None, type='dict'),
|
||||
)
|
||||
module_kwargs = openstack_module_kwargs()
|
||||
module = AnsibleModule(argument_spec, **module_kwargs)
|
||||
is_old_facts = module._name == 'openstack.cloud.image_facts'
|
||||
if is_old_facts:
|
||||
module.deprecate("The 'openstack.cloud.image_facts' module has been renamed to 'openstack.cloud.image_info', "
|
||||
"and the renamed one no longer returns ansible_facts", version='2.13')
|
||||
|
||||
sdk, cloud = openstack_cloud_from_module(module)
|
||||
try:
|
||||
if module.params['image']:
|
||||
image = cloud.get_image(module.params['image'])
|
||||
if is_old_facts:
|
||||
module.exit_json(changed=False, ansible_facts=dict(
|
||||
openstack_image=image))
|
||||
else:
|
||||
module.exit_json(changed=False, openstack_image=image)
|
||||
else:
|
||||
images = cloud.search_images(filters=module.params['properties'])
|
||||
if is_old_facts:
|
||||
module.exit_json(changed=False, ansible_facts=dict(
|
||||
openstack_image=images))
|
||||
else:
|
||||
module.exit_json(changed=False, openstack_image=images)
|
||||
|
||||
except sdk.exceptions.OpenStackCloudException as e:
|
||||
module.fail_json(msg=str(e))
|
||||
module = ImageInfoModule()
|
||||
module()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -2,7 +2,6 @@ plugins/modules/baremetal_node.py pylint:ansible-deprecated-no-collection-name
|
||||
plugins/modules/compute_flavor_info.py pylint:ansible-deprecated-no-collection-name
|
||||
plugins/modules/identity_domain_info.py pylint:ansible-deprecated-no-collection-name
|
||||
plugins/modules/identity_user_info.py pylint:ansible-deprecated-no-collection-name
|
||||
plugins/modules/image_info.py pylint:ansible-deprecated-no-collection-name
|
||||
plugins/modules/port_info.py pylint:ansible-deprecated-no-collection-name
|
||||
plugins/modules/project_info.py pylint:ansible-deprecated-no-collection-name
|
||||
plugins/module_utils/openstack.py pylint:ansible-deprecated-no-collection-name
|
||||
|
@ -2,7 +2,6 @@ plugins/modules/baremetal_node.py pylint:ansible-deprecated-no-collection-name
|
||||
plugins/modules/compute_flavor_info.py pylint:ansible-deprecated-no-collection-name
|
||||
plugins/modules/identity_domain_info.py pylint:ansible-deprecated-no-collection-name
|
||||
plugins/modules/identity_user_info.py pylint:ansible-deprecated-no-collection-name
|
||||
plugins/modules/image_info.py pylint:ansible-deprecated-no-collection-name
|
||||
plugins/modules/port_info.py pylint:ansible-deprecated-no-collection-name
|
||||
plugins/modules/project_info.py pylint:ansible-deprecated-no-collection-name
|
||||
plugins/module_utils/openstack.py pylint:ansible-deprecated-no-collection-name
|
||||
|
Loading…
x
Reference in New Issue
Block a user