Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support creating an image from a volume #59574

Merged
merged 5 commits into from
Sep 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/fragments/59574-os_image_from_volume.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- os_image - add ``volume`` option to support creating an image from a volume
39 changes: 38 additions & 1 deletion lib/ansible/modules/cloud/openstack/os_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@
availability_zone:
description:
- Ignored. Present for backwards compatibility
volume:
version_added: "2.10"
description:
- ID of a volume to create an image from.
- The volume must be in AVAILABLE state.
requirements: ["openstacksdk"]
'''

Expand All @@ -109,6 +114,33 @@
properties:
cpu_arch: x86_64
distro: ubuntu

# Create image from volume attached to an instance
- name: create volume snapshot
os_volume_snapshot:
auth:
"{{ auth }}"
display_name: myvol_snapshot
volume: myvol
force: yes
register: myvol_snapshot

- name: create volume from snapshot
os_volume:
auth:
"{{ auth }}"
size: "{{ myvol_snapshot.snapshot.size }}"
snapshot_id: "{{ myvol_snapshot.snapshot.id }}"
display_name: myvol_snapshot_volume
wait: yes
register: myvol_snapshot_volume

- name: create image from volume snapshot
os_image:
auth:
"{{ auth }}"
volume: "{{ myvol_snapshot_volume.volume.id }}"
name: myvol_image
'''

from ansible.module_utils.basic import AnsibleModule
Expand All @@ -132,9 +164,13 @@ def main():
ramdisk=dict(default=None),
kernel=dict(default=None),
properties=dict(type='dict', default={}),
volume=dict(default=None),
state=dict(default='present', choices=['absent', 'present']),
)
module_kwargs = openstack_module_kwargs()

module_kwargs = openstack_module_kwargs(
mutually_exclusive=[['filename', 'volume']],
)
module = AnsibleModule(argument_spec, **module_kwargs)

sdk, cloud = openstack_cloud_from_module(module)
Expand Down Expand Up @@ -162,6 +198,7 @@ def main():
protected=module.params['protected'],
min_disk=module.params['min_disk'],
min_ram=module.params['min_ram'],
volume=module.params['volume'],
**kwargs
)
changed = True
Expand Down