mirror of
https://opendev.org/openstack/ansible-collections-openstack.git
synced 2026-05-08 14:23:03 +00:00
Set owner in image module
Previously the owner field was not set by module
`cloud.openstack.image`, although it is specified as a module parameter.
The usual approach in `ansible-collections-openstack` is to accept both
names and IDs when referencing openstack resources.
Therefore this commit follows the approach taken by
`python-openstackclient` in [1] and introduces a `project` and a
`project_domain` parameter to identify projects by name or ID and
assign the ID to the `owner` attribute of the image.
The `owner` parameter is left as an alias to `project` in the module.
Story: 2009983
Task: 45012
[1]
cf2de9af79
Change-Id: I3654587df8e40d554aac5126df307961f335332c
This commit is contained in:
committed by
Jakob Meng
parent
a4894337d4
commit
acf64a1f72
@@ -57,11 +57,6 @@
|
|||||||
state: absent
|
state: absent
|
||||||
name: "{{ image_name }}"
|
name: "{{ image_name }}"
|
||||||
|
|
||||||
- name: Delete test image file
|
|
||||||
file:
|
|
||||||
name: "{{ tmp_file.stdout }}"
|
|
||||||
state: absent
|
|
||||||
|
|
||||||
- name: Try to get details of deleted image
|
- name: Try to get details of deleted image
|
||||||
openstack.cloud.image_info:
|
openstack.cloud.image_info:
|
||||||
cloud: "{{ cloud }}"
|
cloud: "{{ cloud }}"
|
||||||
@@ -72,3 +67,82 @@
|
|||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- not deleted_image_info_result.openstack_images
|
- not deleted_image_info_result.openstack_images
|
||||||
|
|
||||||
|
- name: Create owner project
|
||||||
|
openstack.cloud.project:
|
||||||
|
cloud: "{{ cloud }}"
|
||||||
|
state: present
|
||||||
|
name: image_owner_project
|
||||||
|
description: Project owning test image
|
||||||
|
domain_id: default
|
||||||
|
enabled: True
|
||||||
|
register: owner_project
|
||||||
|
|
||||||
|
- name: Create raw image (owner by project name)
|
||||||
|
openstack.cloud.image:
|
||||||
|
cloud: "{{ cloud }}"
|
||||||
|
state: present
|
||||||
|
name: "{{ image_name }}"
|
||||||
|
filename: "{{ tmp_file.stdout }}"
|
||||||
|
disk_format: raw
|
||||||
|
tags: "{{ image_tags }}"
|
||||||
|
project: image_owner_project
|
||||||
|
register: image
|
||||||
|
|
||||||
|
- name: Get details of created image (owner by project name)
|
||||||
|
openstack.cloud.image_info:
|
||||||
|
cloud: "{{ cloud }}"
|
||||||
|
image: "{{ image_name }}"
|
||||||
|
register: image_info_result
|
||||||
|
|
||||||
|
- name: Verify image owner (owner by project name)
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- image_info_result.openstack_images[0].owner == owner_project.project.id
|
||||||
|
|
||||||
|
- name: Delete raw image (owner by project name)
|
||||||
|
openstack.cloud.image:
|
||||||
|
cloud: "{{ cloud }}"
|
||||||
|
state: absent
|
||||||
|
name: "{{ image_name }}"
|
||||||
|
|
||||||
|
- name: Create raw image (owner by project name and domain name)
|
||||||
|
openstack.cloud.image:
|
||||||
|
cloud: "{{ cloud }}"
|
||||||
|
state: present
|
||||||
|
name: "{{ image_name }}"
|
||||||
|
filename: "{{ tmp_file.stdout }}"
|
||||||
|
disk_format: raw
|
||||||
|
tags: "{{ image_tags }}"
|
||||||
|
project: image_owner_project
|
||||||
|
project_domain: default
|
||||||
|
register: image
|
||||||
|
|
||||||
|
- name: Get details of created image (owner by project name and domain name)
|
||||||
|
openstack.cloud.image_info:
|
||||||
|
cloud: "{{ cloud }}"
|
||||||
|
image: "{{ image_name }}"
|
||||||
|
register: image_info_result
|
||||||
|
|
||||||
|
- name: Verify image owner (owner by project name and domain name)
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- image_info_result.openstack_images[0].owner == owner_project.project.id
|
||||||
|
|
||||||
|
- name: Delete raw image (owner by project name and domain name)
|
||||||
|
openstack.cloud.image:
|
||||||
|
cloud: "{{ cloud }}"
|
||||||
|
state: absent
|
||||||
|
name: "{{ image_name }}"
|
||||||
|
|
||||||
|
- name: Delete owner project
|
||||||
|
openstack.cloud.project:
|
||||||
|
cloud: "{{ cloud }}"
|
||||||
|
state: absent
|
||||||
|
name: image_owner_project
|
||||||
|
domain_id: default
|
||||||
|
|
||||||
|
- name: Delete test image file
|
||||||
|
file:
|
||||||
|
name: "{{ tmp_file.stdout }}"
|
||||||
|
state: absent
|
||||||
|
|||||||
@@ -40,9 +40,15 @@ options:
|
|||||||
default: bare
|
default: bare
|
||||||
choices: ['ami', 'aki', 'ari', 'bare', 'ovf', 'ova', 'docker']
|
choices: ['ami', 'aki', 'ari', 'bare', 'ovf', 'ova', 'docker']
|
||||||
type: str
|
type: str
|
||||||
owner:
|
project:
|
||||||
description:
|
description:
|
||||||
- The owner of the image
|
- The name or ID of the project owning the image
|
||||||
|
type: str
|
||||||
|
aliases: ['owner']
|
||||||
|
project_domain:
|
||||||
|
description:
|
||||||
|
- The domain the project owning the image belongs to
|
||||||
|
- May be used to identify a unique project when providing a name to the project argument and multiple projects with such name exist
|
||||||
type: str
|
type: str
|
||||||
min_disk:
|
min_disk:
|
||||||
description:
|
description:
|
||||||
@@ -169,7 +175,8 @@ class ImageModule(OpenStackModule):
|
|||||||
disk_format=dict(default='qcow2',
|
disk_format=dict(default='qcow2',
|
||||||
choices=['ami', 'ari', 'aki', 'vhd', 'vmdk', 'raw', 'qcow2', 'vdi', 'iso', 'vhdx', 'ploop']),
|
choices=['ami', 'ari', 'aki', 'vhd', 'vmdk', 'raw', 'qcow2', 'vdi', 'iso', 'vhdx', 'ploop']),
|
||||||
container_format=dict(default='bare', choices=['ami', 'aki', 'ari', 'bare', 'ovf', 'ova', 'docker']),
|
container_format=dict(default='bare', choices=['ami', 'aki', 'ari', 'bare', 'ovf', 'ova', 'docker']),
|
||||||
owner=dict(type='str'),
|
project=dict(type='str', aliases=['owner']),
|
||||||
|
project_domain=dict(type='str'),
|
||||||
min_disk=dict(type='int', default=0),
|
min_disk=dict(type='int', default=0),
|
||||||
min_ram=dict(type='int', default=0),
|
min_ram=dict(type='int', default=0),
|
||||||
is_public=dict(type='bool', default=False),
|
is_public=dict(type='bool', default=False),
|
||||||
@@ -202,6 +209,16 @@ class ImageModule(OpenStackModule):
|
|||||||
kwargs = {}
|
kwargs = {}
|
||||||
if self.params['id'] is not None:
|
if self.params['id'] is not None:
|
||||||
kwargs['id'] = self.params['id']
|
kwargs['id'] = self.params['id']
|
||||||
|
if self.params['project']:
|
||||||
|
project_domain = {'id': None}
|
||||||
|
if self.params['project_domain']:
|
||||||
|
project_domain = self.conn.get_domain(name_or_id=self.params['project_domain'])
|
||||||
|
if not project_domain or project_domain['id'] is None:
|
||||||
|
self.fail(msg='Project domain %s could not be found' % self.params['project_domain'])
|
||||||
|
project = self.conn.get_project(name_or_id=self.params['project'], domain_id=project_domain['id'])
|
||||||
|
if not project:
|
||||||
|
self.fail(msg='Project %s could not be found' % self.params['project'])
|
||||||
|
kwargs['owner'] = project['id']
|
||||||
image = self.conn.create_image(
|
image = self.conn.create_image(
|
||||||
name=self.params['name'],
|
name=self.params['name'],
|
||||||
filename=self.params['filename'],
|
filename=self.params['filename'],
|
||||||
|
|||||||
Reference in New Issue
Block a user