Moves image_info from cloud to proxy object
This makes image_info compatible with new sdk version - This patch changes get_image (which is a cloud object method) to image.get_image (proxy object method) - image.images accepts **query which is a dict object. So this patch changes the args passed to a dict. If properties is not specified it passes an empty dict. - updates the documentation to reflect the actual returned parameters - adds a ci test to list all images without specifying image name or property and assert no field is missing - changes openstack_image to image in ansible return value Change-Id: Ibf934568f069c305747fc24fbb22ce3fc095286c
This commit is contained in:
parent
1d22a94a90
commit
c1a9794207
@ -76,6 +76,7 @@
|
|||||||
identity_role
|
identity_role
|
||||||
identity_role_info
|
identity_role_info
|
||||||
image
|
image
|
||||||
|
image_info
|
||||||
keypair
|
keypair
|
||||||
keystone_domain
|
keystone_domain
|
||||||
keystone_federation_protocol
|
keystone_federation_protocol
|
||||||
|
@ -25,8 +25,8 @@
|
|||||||
- name: Verify image info
|
- name: Verify image info
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- "image_info_result.openstack_image.name == image_name"
|
- "image_info_result.images[0].name == image_name"
|
||||||
- "image_info_result.openstack_image.tags | sort == image_tags | sort"
|
- "image_info_result.images[0].tags | sort == image_tags | sort"
|
||||||
|
|
||||||
- name: Delete raw image (defaults)
|
- name: Delete raw image (defaults)
|
||||||
openstack.cloud.image:
|
openstack.cloud.image:
|
||||||
@ -71,4 +71,4 @@
|
|||||||
- name: Verify image is deleted
|
- name: Verify image is deleted
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- not deleted_image_info_result.openstack_image
|
- not deleted_image_info_result.images
|
65
ci/roles/image_info/defaults/main.yml
Normal file
65
ci/roles/image_info/defaults/main.yml
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
expected_fields:
|
||||||
|
- architecture
|
||||||
|
- checksum
|
||||||
|
- container_format
|
||||||
|
- created_at
|
||||||
|
- direct_url
|
||||||
|
- disk_format
|
||||||
|
- file
|
||||||
|
- has_auto_disk_config
|
||||||
|
- hash_algo
|
||||||
|
- hash_value
|
||||||
|
- hw_cpu_cores
|
||||||
|
- hw_cpu_policy
|
||||||
|
- hw_cpu_sockets
|
||||||
|
- hw_cpu_thread_policy
|
||||||
|
- hw_cpu_threads
|
||||||
|
- hw_disk_bus
|
||||||
|
- hw_machine_type
|
||||||
|
- hw_qemu_guest_agent
|
||||||
|
- hw_rng_model
|
||||||
|
- hw_scsi_model
|
||||||
|
- hw_serial_port_count
|
||||||
|
- hw_video_model
|
||||||
|
- hw_video_ram
|
||||||
|
- hw_vif_model
|
||||||
|
- hw_watchdog_action
|
||||||
|
- hypervisor_type
|
||||||
|
- id
|
||||||
|
- instance_type_rxtx_factor
|
||||||
|
- instance_uuid
|
||||||
|
- is_hidden
|
||||||
|
- is_hw_boot_menu_enabled
|
||||||
|
- is_hw_vif_multiqueue_enabled
|
||||||
|
- is_protected
|
||||||
|
- kernel_id
|
||||||
|
- locations
|
||||||
|
- metadata
|
||||||
|
- min_disk
|
||||||
|
- min_ram
|
||||||
|
- name
|
||||||
|
- needs_config_drive
|
||||||
|
- needs_secure_boot
|
||||||
|
- os_admin_user
|
||||||
|
- os_command_line
|
||||||
|
- os_distro
|
||||||
|
- os_require_quiesce
|
||||||
|
- os_shutdown_timeout
|
||||||
|
- os_type
|
||||||
|
- os_version
|
||||||
|
- owner
|
||||||
|
- owner_id
|
||||||
|
- properties
|
||||||
|
- ramdisk_id
|
||||||
|
- schema
|
||||||
|
- size
|
||||||
|
- status
|
||||||
|
- store
|
||||||
|
- tags
|
||||||
|
- updated_at
|
||||||
|
- url
|
||||||
|
- virtual_size
|
||||||
|
- visibility
|
||||||
|
- vm_mode
|
||||||
|
- vmware_adaptertype
|
||||||
|
- vmware_ostype
|
11
ci/roles/image_info/tasks/main.yml
Normal file
11
ci/roles/image_info/tasks/main.yml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
---
|
||||||
|
- name: List all images # This will list at least the default cirros image of devstack
|
||||||
|
openstack.cloud.image_info:
|
||||||
|
cloud: "{{ cloud }}"
|
||||||
|
register: image_list_result
|
||||||
|
|
||||||
|
- name: Assert fields
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- item in image_list_result.images.0.keys()
|
||||||
|
loop: "{{ expected_fields }}"
|
@ -22,6 +22,7 @@
|
|||||||
- { role: identity_role, tags: identity_role }
|
- { role: identity_role, tags: identity_role }
|
||||||
- { role: identity_role_info, tags: identity_role_info }
|
- { role: identity_role_info, tags: identity_role_info }
|
||||||
- { role: image, tags: image }
|
- { role: image, tags: image }
|
||||||
|
- { role: image_info, tags: image_info }
|
||||||
- { role: keypair, tags: keypair }
|
- { role: keypair, tags: keypair }
|
||||||
- { role: keystone_domain, tags: keystone_domain }
|
- { role: keystone_domain, tags: keystone_domain }
|
||||||
- role: keystone_mapping
|
- role: keystone_mapping
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
|
---
|
||||||
module: image_info
|
module: image_info
|
||||||
short_description: Retrieve information about an image within OpenStack.
|
short_description: Retrieve information about an image within OpenStack.
|
||||||
author: OpenStack Ansible SIG
|
author: OpenStack Ansible SIG
|
||||||
@ -17,11 +18,12 @@ options:
|
|||||||
- Name or ID of the image
|
- Name or ID of the image
|
||||||
required: false
|
required: false
|
||||||
type: str
|
type: str
|
||||||
properties:
|
filters:
|
||||||
description:
|
description:
|
||||||
- Dict of properties of the images used for query
|
- Dict of properties of the images used for query
|
||||||
type: dict
|
type: dict
|
||||||
required: false
|
required: false
|
||||||
|
aliases: ['properties']
|
||||||
requirements:
|
requirements:
|
||||||
- "python >= 3.6"
|
- "python >= 3.6"
|
||||||
- "openstacksdk"
|
- "openstacksdk"
|
||||||
@ -43,7 +45,7 @@ EXAMPLES = '''
|
|||||||
|
|
||||||
- name: Show openstack information
|
- name: Show openstack information
|
||||||
debug:
|
debug:
|
||||||
msg: "{{ result.openstack_image }}"
|
msg: "{{ result.image }}"
|
||||||
|
|
||||||
# Show all available Openstack images
|
# Show all available Openstack images
|
||||||
- name: Retrieve all available Openstack images
|
- name: Retrieve all available Openstack images
|
||||||
@ -52,22 +54,22 @@ EXAMPLES = '''
|
|||||||
|
|
||||||
- name: Show images
|
- name: Show images
|
||||||
debug:
|
debug:
|
||||||
msg: "{{ result.openstack_image }}"
|
msg: "{{ result.image }}"
|
||||||
|
|
||||||
# Show images matching requested properties
|
# Show images matching requested properties
|
||||||
- name: Retrieve images having properties with desired values
|
- name: Retrieve images having properties with desired values
|
||||||
openstack.cloud.image_facts:
|
openstack.cloud.image_facts:
|
||||||
properties:
|
filters:
|
||||||
some_property: some_value
|
some_property: some_value
|
||||||
OtherProp: OtherVal
|
OtherProp: OtherVal
|
||||||
|
|
||||||
- name: Show images
|
- name: Show images
|
||||||
debug:
|
debug:
|
||||||
msg: "{{ result.openstack_image }}"
|
msg: "{{ result.image }}"
|
||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = '''
|
RETURN = '''
|
||||||
openstack_image:
|
images:
|
||||||
description: has all the openstack information about the image
|
description: has all the openstack information about the image
|
||||||
returned: always, but can be null
|
returned: always, but can be null
|
||||||
type: complex
|
type: complex
|
||||||
@ -84,6 +86,12 @@ openstack_image:
|
|||||||
description: Image status.
|
description: Image status.
|
||||||
returned: success
|
returned: success
|
||||||
type: str
|
type: str
|
||||||
|
architecture:
|
||||||
|
description: >
|
||||||
|
The CPU architecture that must be supported by
|
||||||
|
the hypervisor.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
created_at:
|
created_at:
|
||||||
description: Image created at timestamp.
|
description: Image created at timestamp.
|
||||||
returned: success
|
returned: success
|
||||||
@ -92,6 +100,10 @@ openstack_image:
|
|||||||
description: Container format of the image.
|
description: Container format of the image.
|
||||||
returned: success
|
returned: success
|
||||||
type: str
|
type: str
|
||||||
|
direct_url:
|
||||||
|
description: URL to access the image file kept in external store.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
min_ram:
|
min_ram:
|
||||||
description: Min amount of RAM required for this image.
|
description: Min amount of RAM required for this image.
|
||||||
returned: success
|
returned: success
|
||||||
@ -100,11 +112,233 @@ openstack_image:
|
|||||||
description: Disk format of the image.
|
description: Disk format of the image.
|
||||||
returned: success
|
returned: success
|
||||||
type: str
|
type: str
|
||||||
|
file:
|
||||||
|
description: The URL for the virtual machine image file.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
has_auto_disk_config:
|
||||||
|
description: >
|
||||||
|
If root partition on disk is automatically resized
|
||||||
|
before the instance boots.
|
||||||
|
returned: success
|
||||||
|
type: bool
|
||||||
|
hash_algo:
|
||||||
|
description: >
|
||||||
|
The algorithm used to compute a secure hash of the
|
||||||
|
image data.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
hash_value:
|
||||||
|
description: >
|
||||||
|
The hexdigest of the secure hash of the image data
|
||||||
|
computed using the algorithm whose name is the value of the os_hash_algo property.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
hw_cpu_cores:
|
||||||
|
description: >
|
||||||
|
Used to pin the virtual CPUs (vCPUs) of instances to
|
||||||
|
the host's physical CPU cores (pCPUs).
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
hw_cpu_policy:
|
||||||
|
description: The hexdigest of the secure hash of the image data.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
hw_cpu_sockets:
|
||||||
|
description: Preferred number of sockets to expose to the guest.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
hw_cpu_thread_policy:
|
||||||
|
description: >
|
||||||
|
Defines how hardware CPU threads in a simultaneous
|
||||||
|
multithreading-based (SMT) architecture be used.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
hw_cpu_threads:
|
||||||
|
description: >
|
||||||
|
The preferred number of threads to expose to the guest.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
hw_disk_bus:
|
||||||
|
description: >
|
||||||
|
Specifies the type of disk controller to attach disk
|
||||||
|
devices to.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
hw_machine_type:
|
||||||
|
description: >
|
||||||
|
Enables booting an ARM system using the
|
||||||
|
specified machine type.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
hw_qemu_guest_agent:
|
||||||
|
description: >
|
||||||
|
A string boolean, which if "true", QEMU guest agent
|
||||||
|
will be exposed to the instance.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
hw_rng_model:
|
||||||
|
description: Adds a random-number generator device to the image's instances.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
hw_scsi_model:
|
||||||
|
description: >
|
||||||
|
Enables the use of VirtIO SCSI (virtio-scsi) to
|
||||||
|
provide block device access for compute instances.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
hw_video_model:
|
||||||
|
description: The video image driver used.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
hw_video_ram:
|
||||||
|
description: Maximum RAM for the video image.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
hw_vif_model:
|
||||||
|
description: Specifies the model of virtual network interface device to use.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
hw_watchdog_action:
|
||||||
|
description: >
|
||||||
|
Enables a virtual hardware watchdog device that
|
||||||
|
carries out the specified action if the server hangs.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
hypervisor_type:
|
||||||
|
description: The hypervisor type.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
instance_type_rxtx_factor:
|
||||||
|
description: >
|
||||||
|
Optional property allows created servers to have a
|
||||||
|
different bandwidth cap than that defined in the network they are attached to.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
instance_uuid:
|
||||||
|
description: >
|
||||||
|
For snapshot images, this is the UUID of the server
|
||||||
|
used to create this image.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
is_hidden:
|
||||||
|
description: Controls whether an image is displayed in the default image-list response
|
||||||
|
returned: success
|
||||||
|
type: bool
|
||||||
|
is_hw_boot_menu_enabled:
|
||||||
|
description: Enables the BIOS bootmenu.
|
||||||
|
returned: success
|
||||||
|
type: bool
|
||||||
|
is_hw_vif_multiqueue_enabled:
|
||||||
|
description: >
|
||||||
|
Enables the virtio-net multiqueue
|
||||||
|
feature.
|
||||||
|
returned: success
|
||||||
|
type: bool
|
||||||
|
kernel_id:
|
||||||
|
description: >
|
||||||
|
The ID of an image stored in the Image service that
|
||||||
|
should be used as the kernel when booting an AMI-style image.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
locations:
|
||||||
|
description: A list of URLs to access the image file in external store.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
metadata:
|
||||||
|
description: The location metadata.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
needs_config_drive:
|
||||||
|
description: Specifies whether the image needs a config drive.
|
||||||
|
returned: success
|
||||||
|
type: bool
|
||||||
|
needs_secure_boot:
|
||||||
|
description: Whether Secure Boot is needed.
|
||||||
|
returned: success
|
||||||
|
type: bool
|
||||||
|
os_admin_user:
|
||||||
|
description: The operating system admin username.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
os_command_line:
|
||||||
|
description: The kernel command line to be used by libvirt driver.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
os_distro:
|
||||||
|
description: >
|
||||||
|
The common name of the operating system distribution
|
||||||
|
in lowercase.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
os_require_quiesce:
|
||||||
|
description: >
|
||||||
|
If true, require quiesce on snapshot via
|
||||||
|
QEMU guest agent.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
os_shutdown_timeout:
|
||||||
|
description: Time for graceful shutdown.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
os_type:
|
||||||
|
description: The operating system installed on the image.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
os_version:
|
||||||
|
description: >
|
||||||
|
The operating system version as specified by
|
||||||
|
the distributor.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
owner_id:
|
||||||
|
description: The ID of the owner, or project, of the image.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
ramdisk_id:
|
||||||
|
description: >
|
||||||
|
The ID of image stored in the Image service that
|
||||||
|
should be used as the ramdisk when booting an AMI-style image.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
schema:
|
||||||
|
description: URL for the schema describing a virtual machine image.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
store:
|
||||||
|
description: >
|
||||||
|
Glance will attempt to store the disk
|
||||||
|
image data in the backing store indicated by the value of the
|
||||||
|
header.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
updated_at:
|
updated_at:
|
||||||
description: Image updated at timestamp.
|
description: Image updated at timestamp.
|
||||||
returned: success
|
returned: success
|
||||||
type: str
|
type: str
|
||||||
properties:
|
url:
|
||||||
|
description: URL to access the image file kept in external store.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
virtual_size:
|
||||||
|
description: The virtual size of the image.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
vm_mode:
|
||||||
|
description: The virtual machine mode.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
vmware_adaptertype:
|
||||||
|
description: >
|
||||||
|
The virtual SCSI or IDE controller used by the
|
||||||
|
hypervisor.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
vmware_ostype:
|
||||||
|
description: Operating system installed in the image.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
filters:
|
||||||
description: Additional properties associated with the image.
|
description: Additional properties associated with the image.
|
||||||
returned: success
|
returned: success
|
||||||
type: dict
|
type: dict
|
||||||
@ -112,7 +346,7 @@ openstack_image:
|
|||||||
description: Min amount of disk space required for this image.
|
description: Min amount of disk space required for this image.
|
||||||
returned: success
|
returned: success
|
||||||
type: int
|
type: int
|
||||||
protected:
|
is_protected:
|
||||||
description: Image protected flag.
|
description: Image protected flag.
|
||||||
returned: success
|
returned: success
|
||||||
type: bool
|
type: bool
|
||||||
@ -124,10 +358,10 @@ openstack_image:
|
|||||||
description: Owner for the image.
|
description: Owner for the image.
|
||||||
returned: success
|
returned: success
|
||||||
type: str
|
type: str
|
||||||
is_public:
|
visibility:
|
||||||
description: Is public flag of the image.
|
description: Indicates who has access to the image.
|
||||||
returned: success
|
returned: success
|
||||||
type: bool
|
type: str
|
||||||
size:
|
size:
|
||||||
description: Size of the image.
|
description: Size of the image.
|
||||||
returned: success
|
returned: success
|
||||||
@ -137,7 +371,6 @@ openstack_image:
|
|||||||
returned: success
|
returned: success
|
||||||
type: list
|
type: list
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import OpenStackModule
|
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import OpenStackModule
|
||||||
|
|
||||||
|
|
||||||
@ -147,20 +380,21 @@ class ImageInfoModule(OpenStackModule):
|
|||||||
|
|
||||||
argument_spec = dict(
|
argument_spec = dict(
|
||||||
image=dict(type='str', required=False),
|
image=dict(type='str', required=False),
|
||||||
properties=dict(type='dict', required=False),
|
filters=dict(type='dict', required=False, aliases=['properties']),
|
||||||
)
|
)
|
||||||
module_kwargs = dict(
|
module_kwargs = dict(
|
||||||
supports_check_mode=True
|
supports_check_mode=True
|
||||||
)
|
)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
args = {
|
||||||
if self.params['image']:
|
'name_or_id': self.params['image'],
|
||||||
image = self.conn.get_image(self.params['image'])
|
'filters': self.params['filters'],
|
||||||
self.exit(changed=False, openstack_image=image)
|
}
|
||||||
else:
|
args = {k: v for k, v in args.items() if v is not None}
|
||||||
images = self.conn.search_images(filters=self.params['properties'])
|
images = [image.to_dict(computed=False) for image in
|
||||||
self.exit(changed=False, openstack_image=images)
|
self.conn.search_images(**args)]
|
||||||
|
self.exit(changed=False, images=images)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user