mirror of
https://opendev.org/openstack/ansible-collections-openstack.git
synced 2026-05-07 05:43:15 +00:00
Merge "Add bootable volume support"
This commit is contained in:
@@ -12,14 +12,35 @@
|
|||||||
that: item in vol.volume
|
that: item in vol.volume
|
||||||
loop: "{{ expected_fields }}"
|
loop: "{{ expected_fields }}"
|
||||||
|
|
||||||
- name: Create volume from existing volume
|
- assert:
|
||||||
|
that: not vol.volume.is_bootable
|
||||||
|
|
||||||
|
- name: Create bootable volume from existing volume
|
||||||
openstack.cloud.volume:
|
openstack.cloud.volume:
|
||||||
cloud: "{{ cloud }}"
|
cloud: "{{ cloud }}"
|
||||||
state: present
|
state: present
|
||||||
size: 1
|
size: 1
|
||||||
volume: "{{ vol.volume.id }}"
|
volume: "{{ vol.volume.id }}"
|
||||||
name: ansible_volume1
|
name: ansible_volume1
|
||||||
|
is_bootable: true
|
||||||
description: Test volume
|
description: Test volume
|
||||||
|
register: vol
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that: vol.volume.is_bootable
|
||||||
|
|
||||||
|
- name: Make the first volume bootable
|
||||||
|
openstack.cloud.volume:
|
||||||
|
cloud: "{{ cloud }}"
|
||||||
|
state: present
|
||||||
|
size: 1
|
||||||
|
name: ansible_volume
|
||||||
|
is_bootable: true
|
||||||
|
description: Test volume
|
||||||
|
register: vol
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that: vol.volume.is_bootable
|
||||||
|
|
||||||
- name: Delete volume
|
- name: Delete volume
|
||||||
openstack.cloud.volume:
|
openstack.cloud.volume:
|
||||||
|
|||||||
@@ -15,16 +15,19 @@ options:
|
|||||||
availability_zone:
|
availability_zone:
|
||||||
description:
|
description:
|
||||||
- The availability zone.
|
- The availability zone.
|
||||||
|
- This attribute cannot be updated.
|
||||||
type: str
|
type: str
|
||||||
description:
|
description:
|
||||||
description:
|
description:
|
||||||
- String describing the volume
|
- String describing the volume
|
||||||
|
- This attribute cannot be updated.
|
||||||
type: str
|
type: str
|
||||||
aliases: [display_description]
|
aliases: [display_description]
|
||||||
image:
|
image:
|
||||||
description:
|
description:
|
||||||
- Image name or id for boot from volume
|
- Image name or id for boot from volume
|
||||||
- Mutually exclusive with I(snapshot) and I(volume)
|
- Mutually exclusive with I(snapshot) and I(volume)
|
||||||
|
- This attribute cannot be updated.
|
||||||
type: str
|
type: str
|
||||||
is_bootable:
|
is_bootable:
|
||||||
description:
|
description:
|
||||||
@@ -40,30 +43,36 @@ options:
|
|||||||
- Note that support for multiattach volumes depends on the volume
|
- Note that support for multiattach volumes depends on the volume
|
||||||
type being used.
|
type being used.
|
||||||
- "Cinder's default for I(is_multiattach) is C(false)."
|
- "Cinder's default for I(is_multiattach) is C(false)."
|
||||||
|
- This attribute cannot be updated.
|
||||||
type: bool
|
type: bool
|
||||||
metadata:
|
metadata:
|
||||||
description:
|
description:
|
||||||
- Metadata for the volume
|
- Metadata for the volume
|
||||||
|
- This attribute cannot be updated.
|
||||||
type: dict
|
type: dict
|
||||||
name:
|
name:
|
||||||
description:
|
description:
|
||||||
- Name of volume
|
- Name of volume
|
||||||
|
- This attribute cannot be updated.
|
||||||
required: true
|
required: true
|
||||||
type: str
|
type: str
|
||||||
aliases: [display_name]
|
aliases: [display_name]
|
||||||
scheduler_hints:
|
scheduler_hints:
|
||||||
description:
|
description:
|
||||||
- Scheduler hints passed to volume API in form of dict
|
- Scheduler hints passed to volume API in form of dict
|
||||||
|
- This attribute cannot be updated.
|
||||||
type: dict
|
type: dict
|
||||||
size:
|
size:
|
||||||
description:
|
description:
|
||||||
- Size of volume in GB. This parameter is required when the
|
- Size of volume in GB. This parameter is required when the
|
||||||
I(state) parameter is 'present'.
|
I(state) parameter is 'present'.
|
||||||
|
- This attribute can only be updated to a larger size.
|
||||||
type: int
|
type: int
|
||||||
snapshot:
|
snapshot:
|
||||||
description:
|
description:
|
||||||
- Volume snapshot name or id to create from
|
- Volume snapshot name or id to create from
|
||||||
- Mutually exclusive with I(image) and I(volume)
|
- Mutually exclusive with I(image) and I(volume)
|
||||||
|
- This attribute cannot be updated.
|
||||||
type: str
|
type: str
|
||||||
aliases: [snapshot_id]
|
aliases: [snapshot_id]
|
||||||
state:
|
state:
|
||||||
@@ -76,10 +85,12 @@ options:
|
|||||||
description:
|
description:
|
||||||
- Volume name or id to create from
|
- Volume name or id to create from
|
||||||
- Mutually exclusive with I(image) and I(snapshot)
|
- Mutually exclusive with I(image) and I(snapshot)
|
||||||
|
- This attribute cannot be updated.
|
||||||
type: str
|
type: str
|
||||||
volume_type:
|
volume_type:
|
||||||
description:
|
description:
|
||||||
- Volume type for volume
|
- Volume type for volume
|
||||||
|
- This attribute cannot be updated.
|
||||||
type: str
|
type: str
|
||||||
extends_documentation_fragment:
|
extends_documentation_fragment:
|
||||||
- openstack.cloud.openstack
|
- openstack.cloud.openstack
|
||||||
@@ -238,16 +249,13 @@ class VolumeModule(OpenStackModule):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def _build_update(self, volume):
|
def _build_update(self, volume):
|
||||||
keys = ('size',)
|
keys = ('size', 'is_bootable')
|
||||||
return {k: self.params[k] for k in keys if self.params[k] is not None
|
return {k: self.params[k] for k in keys if self.params[k] is not None
|
||||||
and self.params[k] != volume[k]}
|
and self.params[k] != volume[k]}
|
||||||
|
|
||||||
def _update(self, volume):
|
def _update(self, volume):
|
||||||
'''
|
'''
|
||||||
modify volume, the only modification to an existing volume
|
modify volume. If the size has changed, it can only be extended.
|
||||||
available at the moment is extending the size, this is
|
|
||||||
limited by the openstacksdk and may change whenever the
|
|
||||||
functionality is extended.
|
|
||||||
'''
|
'''
|
||||||
diff = {'before': volume.to_dict(computed=False), 'after': ''}
|
diff = {'before': volume.to_dict(computed=False), 'after': ''}
|
||||||
diff['after'] = diff['before']
|
diff['after'] = diff['before']
|
||||||
@@ -259,15 +267,19 @@ class VolumeModule(OpenStackModule):
|
|||||||
volume=volume.to_dict(computed=False), diff=diff)
|
volume=volume.to_dict(computed=False), diff=diff)
|
||||||
|
|
||||||
if self.ansible.check_mode:
|
if self.ansible.check_mode:
|
||||||
volume.size = update['size']
|
for k, v in update:
|
||||||
|
volume[k] = v
|
||||||
self.exit_json(changed=False,
|
self.exit_json(changed=False,
|
||||||
volume=volume.to_dict(computed=False), diff=diff)
|
volume=volume.to_dict(computed=False), diff=diff)
|
||||||
|
|
||||||
if 'size' in update and update['size'] != volume.size:
|
if 'size' in update and update['size'] != volume.size:
|
||||||
size = update['size']
|
size = update['size']
|
||||||
self.conn.volume.extend_volume(volume.id, size)
|
self.conn.volume.extend_volume(volume.id, size)
|
||||||
volume = self.conn.block_storage.get_volume(volume)
|
|
||||||
|
|
||||||
|
if 'is_bootable' in update and update['is_bootable'] != volume.is_bootable:
|
||||||
|
self.conn.volume.set_volume_bootable_status(volume, update['is_bootable'])
|
||||||
|
|
||||||
|
volume = self.conn.block_storage.get_volume(volume)
|
||||||
volume = volume.to_dict(computed=False)
|
volume = volume.to_dict(computed=False)
|
||||||
diff['after'] = volume
|
diff['after'] = volume
|
||||||
self.exit_json(changed=True, volume=volume, diff=diff)
|
self.exit_json(changed=True, volume=volume, diff=diff)
|
||||||
@@ -310,6 +322,10 @@ class VolumeModule(OpenStackModule):
|
|||||||
self.conn.block_storage.wait_for_status(
|
self.conn.block_storage.wait_for_status(
|
||||||
volume, wait=self.params['timeout'])
|
volume, wait=self.params['timeout'])
|
||||||
|
|
||||||
|
if self.params['is_bootable']:
|
||||||
|
self.conn.volume.set_volume_bootable_status(volume, True)
|
||||||
|
volume.is_bootable = True
|
||||||
|
|
||||||
volume = volume.to_dict(computed=False)
|
volume = volume.to_dict(computed=False)
|
||||||
diff['after'] = volume
|
diff['after'] = volume
|
||||||
self.exit_json(changed=True, volume=volume, diff=diff)
|
self.exit_json(changed=True, volume=volume, diff=diff)
|
||||||
|
|||||||
Reference in New Issue
Block a user