mirror of
https://opendev.org/openstack/ansible-collections-openstack.git
synced 2026-05-13 13:02:21 +00:00
Merge "Add inactive state for the images"
This commit is contained in:
7
changelogs/fragments/image_deactivate_reactivate.yml
Normal file
7
changelogs/fragments/image_deactivate_reactivate.yml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
minor_changes:
|
||||||
|
- |
|
||||||
|
openstack.cloud.image - Added new `inactive` option for the image `state`
|
||||||
|
It will deactivate the image. Setting state `present` can re-activate it
|
||||||
|
again for deactivated previously images.
|
||||||
@@ -176,6 +176,34 @@
|
|||||||
- image is changed
|
- image is changed
|
||||||
- image.image.name == 'ansible_image-changed'
|
- image.image.name == 'ansible_image-changed'
|
||||||
|
|
||||||
|
- name: Deactivate raw image
|
||||||
|
openstack.cloud.image:
|
||||||
|
cloud: "{{ cloud }}"
|
||||||
|
state: inactive
|
||||||
|
id: "{{ image.image.id }}"
|
||||||
|
name: 'ansible_image-changed'
|
||||||
|
register: image
|
||||||
|
|
||||||
|
- name: Assert changed
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- image is changed
|
||||||
|
- image.image.status == 'deactivated'
|
||||||
|
|
||||||
|
- name: Reactivate raw image
|
||||||
|
openstack.cloud.image:
|
||||||
|
cloud: "{{ cloud }}"
|
||||||
|
state: present
|
||||||
|
id: "{{ image.image.id }}"
|
||||||
|
name: 'ansible_image-changed'
|
||||||
|
register: image
|
||||||
|
|
||||||
|
- name: Assert changed
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- image is changed
|
||||||
|
- image.image.status == 'active'
|
||||||
|
|
||||||
- name: Rename back raw image (defaults)
|
- name: Rename back raw image (defaults)
|
||||||
openstack.cloud.image:
|
openstack.cloud.image:
|
||||||
cloud: "{{ cloud }}"
|
cloud: "{{ cloud }}"
|
||||||
|
|||||||
@@ -100,8 +100,8 @@ options:
|
|||||||
type: str
|
type: str
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- Should the resource be present or absent.
|
- Should the resource be present, absent or inactive.
|
||||||
choices: [present, absent]
|
choices: [present, absent, inactive]
|
||||||
default: present
|
default: present
|
||||||
type: str
|
type: str
|
||||||
tags:
|
tags:
|
||||||
@@ -153,7 +153,7 @@ EXAMPLES = r'''
|
|||||||
RETURN = r'''
|
RETURN = r'''
|
||||||
image:
|
image:
|
||||||
description: Dictionary describing the Glance image.
|
description: Dictionary describing the Glance image.
|
||||||
returned: On success when I(state) is C(present).
|
returned: On success when I(state) is C(present) or C(inactive).
|
||||||
type: dict
|
type: dict
|
||||||
contains:
|
contains:
|
||||||
id:
|
id:
|
||||||
@@ -394,7 +394,7 @@ class ImageModule(OpenStackModule):
|
|||||||
owner_domain=dict(aliases=['project_domain']),
|
owner_domain=dict(aliases=['project_domain']),
|
||||||
properties=dict(type='dict', default={}),
|
properties=dict(type='dict', default={}),
|
||||||
ramdisk=dict(),
|
ramdisk=dict(),
|
||||||
state=dict(default='present', choices=['absent', 'present']),
|
state=dict(default='present', choices=['absent', 'present', 'inactive']),
|
||||||
tags=dict(type='list', default=[], elements='str'),
|
tags=dict(type='list', default=[], elements='str'),
|
||||||
visibility=dict(choices=['public', 'private', 'shared', 'community']),
|
visibility=dict(choices=['public', 'private', 'shared', 'community']),
|
||||||
volume=dict(),
|
volume=dict(),
|
||||||
@@ -510,6 +510,10 @@ class ImageModule(OpenStackModule):
|
|||||||
self.exit_json(changed=changed,
|
self.exit_json(changed=changed,
|
||||||
image=self._return_value(image.id))
|
image=self._return_value(image.id))
|
||||||
|
|
||||||
|
if image['status'] == 'deactivated':
|
||||||
|
self.conn.image.reactivate_image(image)
|
||||||
|
changed = True
|
||||||
|
|
||||||
update_payload = self._build_update(image)
|
update_payload = self._build_update(image)
|
||||||
|
|
||||||
if update_payload:
|
if update_payload:
|
||||||
@@ -525,6 +529,20 @@ class ImageModule(OpenStackModule):
|
|||||||
wait=self.params['wait'],
|
wait=self.params['wait'],
|
||||||
timeout=self.params['timeout'])
|
timeout=self.params['timeout'])
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
|
elif self.params['state'] == 'inactive' and image is not None:
|
||||||
|
if image['status'] == 'active':
|
||||||
|
self.conn.image.deactivate_image(image)
|
||||||
|
changed = True
|
||||||
|
|
||||||
|
update_payload = self._build_update(image)
|
||||||
|
|
||||||
|
if update_payload:
|
||||||
|
self.conn.image.update_image(image.id, **update_payload)
|
||||||
|
changed = True
|
||||||
|
|
||||||
|
self.exit_json(changed=changed, image=self._return_value(image.id))
|
||||||
|
|
||||||
self.exit_json(changed=changed)
|
self.exit_json(changed=changed)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user