mirror of
https://opendev.org/openstack/ansible-collections-openstack.git
synced 2026-03-27 05:53:02 +00:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1c6663999d | ||
|
|
38e61994c7 | ||
|
|
d416a27112 | ||
|
|
631e1412a0 | ||
|
|
4c31ea152e | ||
|
|
a39470ac2b | ||
|
|
39a8362d7a | ||
|
|
05da83520e | ||
|
|
a6b52612de | ||
|
|
a67272d1f5 |
@@ -197,6 +197,7 @@
|
||||
- job:
|
||||
name: openstack-tox-linters-ansible-devel
|
||||
parent: openstack-tox-linters
|
||||
nodeset: ubuntu-bionic
|
||||
description: |
|
||||
Run openstack collections linter tests using the devel branch of ansible
|
||||
# non-voting because we can't prevent ansible devel from breaking us
|
||||
@@ -208,6 +209,7 @@
|
||||
- job:
|
||||
name: openstack-tox-linters-ansible-2.10
|
||||
parent: openstack-tox-linters
|
||||
nodeset: ubuntu-bionic
|
||||
description: |
|
||||
Run openstack collections linter tests using the 2.10 branch of ansible
|
||||
voting: true
|
||||
@@ -218,6 +220,7 @@
|
||||
- job:
|
||||
name: openstack-tox-linters-ansible-2.9
|
||||
parent: openstack-tox-linters
|
||||
nodeset: ubuntu-bionic
|
||||
description: |
|
||||
Run openstack collections linter tests using the 2.9 branch of ansible
|
||||
voting: true
|
||||
@@ -297,8 +300,12 @@
|
||||
|
||||
- bifrost-collections-src:
|
||||
voting: false
|
||||
dependencies: *deps_unit_lint
|
||||
irrelevant-files: *ignore_files
|
||||
- bifrost-keystone-collections-src:
|
||||
voting: false
|
||||
dependencies: *deps_unit_lint
|
||||
irrelevant-files: *ignore_files
|
||||
|
||||
gate:
|
||||
jobs:
|
||||
|
||||
@@ -5,6 +5,26 @@ Openstack Cloud Ansilbe modules Release Notes
|
||||
.. contents:: Topics
|
||||
|
||||
|
||||
v1.2.0
|
||||
======
|
||||
|
||||
Release Summary
|
||||
---------------
|
||||
|
||||
New volume backup modules.
|
||||
|
||||
Minor Changes
|
||||
-------------
|
||||
|
||||
- lb_health_monitor - Make it possible to create a health monitor to a pool
|
||||
|
||||
New Modules
|
||||
-----------
|
||||
|
||||
- openstack.cloud.volume_backup module - Add/Delete Openstack volumes backup.
|
||||
- openstack.cloud.volume_backup_info module - Retrieve information about Openstack volume backups.
|
||||
- openstack.cloud.volume_snapshot_info module - Retrieve information about Openstack volume snapshots.
|
||||
|
||||
v1.1.0
|
||||
======
|
||||
|
||||
@@ -24,12 +44,6 @@ Minor Changes
|
||||
- inventory_openstack - Add openstack logger and Ansible display utility
|
||||
- loadbalancer - Add support for setting the Flavor when creating a load balancer
|
||||
|
||||
Deprecated Features
|
||||
-------------------
|
||||
|
||||
- foo - The bar option has been deprecated. Use the username option instead.
|
||||
- send_request - The quic option has been deprecated. Use the protocol option instead.
|
||||
|
||||
Bugfixes
|
||||
--------
|
||||
|
||||
|
||||
@@ -1,20 +1,32 @@
|
||||
releases:
|
||||
1.2.0:
|
||||
release_date: '2020-10-13'
|
||||
changes:
|
||||
release_summary: New volume backup modules.
|
||||
minor_changes:
|
||||
- lb_health_monitor - Make it possible to create a health monitor to a pool
|
||||
modules:
|
||||
- name: volume_snapshot_info module
|
||||
description: Retrieve information about Openstack volume snapshots.
|
||||
namespace: ''
|
||||
- name: volume_backup_info module
|
||||
description: Retrieve information about Openstack volume backups.
|
||||
namespace: ''
|
||||
- name: volume_backup module
|
||||
description: Add/Delete Openstack volumes backup.
|
||||
namespace: ''
|
||||
1.1.0:
|
||||
release_date: '2020-08-17'
|
||||
changes:
|
||||
release_summary: Starting redesign modules and bugfixes.
|
||||
minor_changes:
|
||||
- Added changelog.
|
||||
- A basic module subclass was introduced and a few modules moved to inherit from it.
|
||||
- Added pip installation option for collection.
|
||||
- Added template for generation of artibtrary module.
|
||||
- Added more useful information from exception
|
||||
- Add more useful information from exception
|
||||
- inventory_openstack - Add openstack logger and Ansible display utility
|
||||
- loadbalancer - Add support for setting the Flavor when creating a load balancer
|
||||
- baremetal modules - Do not require ironic_url if cloud or auth.endpoint is provided
|
||||
deprecated_features:
|
||||
- foo - The bar option has been deprecated. Use the username option instead.
|
||||
- send_request - The quic option has been deprecated. Use the protocol option instead.
|
||||
bugfixes:
|
||||
- security_group_rule - Don't pass tenant_id for remote group
|
||||
- Fix non existing attribuites in SDK exception
|
||||
|
||||
@@ -8,8 +8,55 @@
|
||||
display_description: Test volume
|
||||
register: vol
|
||||
|
||||
- name: Create volume snapshot
|
||||
openstack.cloud.volume_snapshot:
|
||||
cloud: "{{ cloud }}"
|
||||
state: present
|
||||
display_name: ansible_volume_snapshot
|
||||
volume: ansible_volume
|
||||
register: vol_snap
|
||||
|
||||
- name: Get snapshot info
|
||||
openstack.cloud.volume_snapshot_info:
|
||||
cloud: "{{ cloud }}"
|
||||
name: ansible_volume_snapshot
|
||||
register: snap_info
|
||||
|
||||
- name: Create volume backup
|
||||
openstack.cloud.volume_backup:
|
||||
cloud: "{{ cloud }}"
|
||||
state: present
|
||||
display_name: ansible_volume_backup
|
||||
volume: ansible_volume
|
||||
register: vol_backup
|
||||
|
||||
- name: Get backup info
|
||||
openstack.cloud.volume_backup_info:
|
||||
cloud: "{{ cloud }}"
|
||||
name: ansible_volume_backup
|
||||
register: backup_info
|
||||
|
||||
- debug: var=vol
|
||||
|
||||
- debug: var=vol_backup
|
||||
|
||||
- debug: var=backup_info
|
||||
|
||||
- debug: var=snap_info
|
||||
|
||||
- name: Delete volume backup
|
||||
openstack.cloud.volume_backup:
|
||||
cloud: "{{ cloud }}"
|
||||
display_name: ansible_volume_backup
|
||||
state: absent
|
||||
|
||||
- name: Delete volume snapshot
|
||||
openstack.cloud.volume_snapshot:
|
||||
cloud: "{{ cloud }}"
|
||||
display_name: ansible_volume_snapshot
|
||||
volume: ansible_volume
|
||||
state: absent
|
||||
|
||||
- name: Delete volume
|
||||
openstack.cloud.volume:
|
||||
cloud: "{{ cloud }}"
|
||||
|
||||
@@ -88,8 +88,11 @@ action_groups:
|
||||
- subnet
|
||||
- subnets_info
|
||||
- volume
|
||||
- volume_backup
|
||||
- volume_backup_info
|
||||
- volume_info
|
||||
- volume_snapshot
|
||||
- volume_snapshot_info
|
||||
os:
|
||||
- auth
|
||||
- baremetal_inspect
|
||||
@@ -179,8 +182,11 @@ action_groups:
|
||||
- subnet
|
||||
- subnets_info
|
||||
- volume
|
||||
- volume_backup
|
||||
- volume_backup_info
|
||||
- volume_info
|
||||
- volume_snapshot
|
||||
- volume_snapshot_info
|
||||
- os_auth
|
||||
- os_client_config
|
||||
- os_client_config
|
||||
|
||||
291
plugins/modules/lb_health_monitor.py
Normal file
291
plugins/modules/lb_health_monitor.py
Normal file
@@ -0,0 +1,291 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
# Copyright (c) 2020 Jesper Schmitz Mouridsen.
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
module: lb_health_monitor
|
||||
author: OpenStack Ansible SIG
|
||||
short_description: Add/Delete a health m nonitor to a pool in the load balancing service from OpenStack Cloud
|
||||
description:
|
||||
- Add or Remove a health monitor to/from a pool in the OpenStack load-balancer service.
|
||||
options:
|
||||
name:
|
||||
type: 'str'
|
||||
description:
|
||||
- Name that has to be given to the health monitor
|
||||
required: true
|
||||
state:
|
||||
type: 'str'
|
||||
description:
|
||||
- Should the resource be present or absent.
|
||||
choices: [present, absent]
|
||||
default: present
|
||||
pool:
|
||||
required: true
|
||||
type: 'str'
|
||||
description:
|
||||
- The pool name or id to monitor by the health monitor.
|
||||
type:
|
||||
type: 'str'
|
||||
default: HTTP
|
||||
description:
|
||||
- One of HTTP, HTTPS, PING, SCTP, TCP, TLS-HELLO, or UDP-CONNECT.
|
||||
choices: [HTTP, HTTPS, PING, SCTP, TCP, TLS-HELLO, UDP-CONNECT]
|
||||
delay:
|
||||
type: 'str'
|
||||
required: true
|
||||
description:
|
||||
- the interval, in seconds, between health checks.
|
||||
max_retries:
|
||||
required: true
|
||||
type: 'str'
|
||||
description:
|
||||
- The number of successful checks before changing the operating status of the member to ONLINE.
|
||||
max_retries_down:
|
||||
type: 'str'
|
||||
default: 3
|
||||
description:
|
||||
- The number of allowed check failures before changing the operating status of the member to ERROR. A valid value is from 1 to 10. The default is 3.
|
||||
resp_timeout:
|
||||
required: true
|
||||
description:
|
||||
- The time, in seconds, after which a health check times out. Must be less than delay
|
||||
type: int
|
||||
admin_state_up:
|
||||
default: True
|
||||
description:
|
||||
- The admin state of the helath monitor true for up or false for down
|
||||
type: bool
|
||||
expected_codes:
|
||||
type: 'str'
|
||||
default: 200
|
||||
description:
|
||||
- The list of HTTP status codes expected in response from the member to declare it healthy. Specify one of the following values
|
||||
A single value, such as 200
|
||||
A list, such as 200, 202
|
||||
A range, such as 200-204
|
||||
http_method:
|
||||
type: 'str'
|
||||
default: GET
|
||||
choices: ['GET', 'CONNECT', 'DELETE', 'HEAD', 'OPTIONS', 'PATCH', 'POST', 'PUT', 'TRACE']
|
||||
description:
|
||||
- The HTTP method that the health monitor uses for requests. One of CONNECT, DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT, or TRACE. The default is GET.
|
||||
url_path:
|
||||
type: 'str'
|
||||
default: '/'
|
||||
description:
|
||||
- The HTTP URL path of the request sent by the monitor to test the health of a backend member.
|
||||
Must be a string that begins with a forward slash (/). The default URL path is /.
|
||||
requirements: ["openstacksdk"]
|
||||
extends_documentation_fragment:
|
||||
- openstack.cloud.openstack
|
||||
'''
|
||||
EXAMPLES = '''
|
||||
#Create a healtmonitor named healthmonitor01 with method HEAD url_path /status and expect code 200
|
||||
- openstack.cloud.lb_health_monitor:
|
||||
auth:
|
||||
auth_url: "{{keystone_url}}"
|
||||
username: "{{username}}"
|
||||
password: "{{password}}"
|
||||
project_domain_name: "{{domain_name}}"
|
||||
user_domain_name: "{{domain_name}}"
|
||||
project_name: "{{project_name}}"
|
||||
wait: true
|
||||
admin_state_up: True
|
||||
expected_codes: '200'
|
||||
max_retries_down: '4'
|
||||
http_method: GET
|
||||
url_path: "/status"
|
||||
pool: '{{pool_id}}'
|
||||
name: 'healthmonitor01'
|
||||
delay: '10'
|
||||
max_retries: '3'
|
||||
resp_timeout: '5'
|
||||
state: present
|
||||
'''
|
||||
RETURN = '''
|
||||
health_monitor:
|
||||
description: Dictionary describing the health monitor.
|
||||
returned: On success when C(state=present)
|
||||
type: complex
|
||||
contains:
|
||||
id:
|
||||
description: The health monitor UUID.
|
||||
returned: On success when C(state=present)
|
||||
type: str
|
||||
admin_state_up:
|
||||
returned: On success when C(state=present)
|
||||
description: The administrative state of the resource.
|
||||
type: bool
|
||||
created_at:
|
||||
returned: On success when C(state=present)
|
||||
description: The UTC date and timestamp when the resource was created.
|
||||
type: str
|
||||
delay:
|
||||
returned: On success when C(state=present)
|
||||
description: The time, in seconds, between sending probes to members.
|
||||
type: int
|
||||
expected_codes:
|
||||
returned: On success when C(state=present)
|
||||
description: The list of HTTP status codes expected in response from the member to declare it healthy.
|
||||
type: str
|
||||
http_method:
|
||||
returned: On success when C(state=present)
|
||||
description: The HTTP method that the health monitor uses for requests.
|
||||
type: str
|
||||
max_retries:
|
||||
returned: On success when C(state=present)
|
||||
description: The number of successful checks before changing the operating status of the member to ONLINE.
|
||||
type: str
|
||||
max_retries_down:
|
||||
returned: On success when C(state=present)
|
||||
description: The number of allowed check failures before changing the operating status of the member to ERROR.
|
||||
type: str
|
||||
name:
|
||||
returned: On success when C(state=present)
|
||||
description: Human-readable name of the resource.
|
||||
type: str
|
||||
operating_status:
|
||||
returned: On success when C(state=present)
|
||||
description: The operating status of the resource.
|
||||
type: str
|
||||
pool_id:
|
||||
returned: On success when C(state=present)
|
||||
description: The id of the pool.
|
||||
type: str
|
||||
project_id:
|
||||
returned: On success when C(state=present)
|
||||
description: The ID of the project owning this resource.
|
||||
type: str
|
||||
provisioning_status:
|
||||
returned: On success when C(state=present)
|
||||
description: The provisioning status of the resource.
|
||||
type: str
|
||||
timeout:
|
||||
returned: On success when C(state=present)
|
||||
description: The maximum time, in seconds, that a monitor waits to connect before it times out.
|
||||
type: int
|
||||
type:
|
||||
returned: On success when C(state=present)
|
||||
description: The type of health monitor.
|
||||
type: str
|
||||
updated_at:
|
||||
returned: On success when C(state=present)
|
||||
description: The UTC date and timestamp when the resource was last updated.
|
||||
type: str
|
||||
url_path:
|
||||
returned: On success when C(state=present)
|
||||
description: The HTTP URL path of the request sent by the monitor to test the health of a backend member.
|
||||
type: str
|
||||
'''
|
||||
import time
|
||||
|
||||
|
||||
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import OpenStackModule
|
||||
|
||||
|
||||
class HealthMonitorModule(OpenStackModule):
|
||||
|
||||
def _wait_for_health_monitor_status(self, health_monitor_id, status, failures, interval=5):
|
||||
timeout = self.params['timeout']
|
||||
|
||||
total_sleep = 0
|
||||
if failures is None:
|
||||
failures = []
|
||||
|
||||
while total_sleep < timeout:
|
||||
health_monitor = self.conn.load_balancer.get_health_monitor(health_monitor_id)
|
||||
provisioning_status = health_monitor.provisioning_status
|
||||
if provisioning_status == status:
|
||||
return health_monitor
|
||||
if provisioning_status in failures:
|
||||
self._fail_json(
|
||||
msg="health monitor %s transitioned to failure state %s" %
|
||||
(health_monitor, provisioning_status)
|
||||
)
|
||||
|
||||
time.sleep(interval)
|
||||
total_sleep += interval
|
||||
|
||||
self._fail_json(msg="timeout waiting for health monitor %s to transition to %s" %
|
||||
(health_monitor_id, status)
|
||||
)
|
||||
|
||||
argument_spec = dict(
|
||||
name=dict(required=True),
|
||||
delay=dict(required=True),
|
||||
max_retries=dict(required=True),
|
||||
max_retries_down=dict(required=False, default="3"),
|
||||
resp_timeout=dict(required=True, type='int'),
|
||||
pool=dict(required=True),
|
||||
expected_codes=dict(required=False, default="200"),
|
||||
admin_state_up=dict(required=False, default=True, type='bool'),
|
||||
state=dict(default='present', choices=['absent', 'present']),
|
||||
http_method=dict(default="GET", requried=False, choices=["GET", "CONNECT", "DELETE",
|
||||
"HEAD", "OPTIONS", "PATCH",
|
||||
"POST", "PUT", "TRACE"]),
|
||||
url_path=dict(default="/", requires=False),
|
||||
type=dict(default='HTTP',
|
||||
choices=['HTTP', 'HTTPS', 'PING', 'SCTP', 'TCP', 'TLS-HELLO', 'UDP-CONNECT']))
|
||||
|
||||
module_kwargs = dict(supports_check_mode=True)
|
||||
|
||||
def run(self):
|
||||
|
||||
try:
|
||||
changed = False
|
||||
health_monitor = self.conn.load_balancer.find_health_monitor(name_or_id=self.params['name'])
|
||||
pool = self.conn.load_balancer.find_pool(name_or_id=self.params['pool'])
|
||||
if self.params['state'] == 'present':
|
||||
if not health_monitor:
|
||||
changed = True
|
||||
health_attrs = {"pool_id": pool.id,
|
||||
"type": self.params["type"],
|
||||
"delay": self.params['delay'],
|
||||
"max_retries": self.params['max_retries'],
|
||||
"max_retries_down": self.params['max_retries_down'],
|
||||
"timeout": self.params['resp_timeout'],
|
||||
"name": self.params['name'],
|
||||
"admin_state_up": self.params["admin_state_up"],
|
||||
}
|
||||
if self.params["type"] in ["HTTP", "HTTPS"]:
|
||||
health_attrs["expected_codes"] = self.params["expected_codes"]
|
||||
health_attrs["http_method"] = self.params["http_method"]
|
||||
health_attrs["url_path"] = self.params["url_path"]
|
||||
|
||||
if self.ansible.check_mode:
|
||||
self.exit_json(changed=True)
|
||||
|
||||
health_monitor = self.conn.load_balancer.create_health_monitor(**health_attrs)
|
||||
if not self.params['wait']:
|
||||
self.exit_json(changed=changed, id=health_monitor.id,
|
||||
health_monitor=health_monitor.to_dict())
|
||||
else:
|
||||
health_monitor = self._wait_for_health_monitor_status(health_monitor.id, "ACTIVE", ["ERROR"])
|
||||
self.exit_json(changed=changed, id=health_monitor.id,
|
||||
health_monitor=health_monitor.to_dict())
|
||||
else:
|
||||
self.exit_json(changed=changed, id=health_monitor.id,
|
||||
health_monitor=health_monitor.to_dict()
|
||||
)
|
||||
elif self.params['state'] == 'absent':
|
||||
if health_monitor:
|
||||
if self.ansible.check_mode:
|
||||
self.exit_json(changed=True)
|
||||
self.conn.load_balancer.delete_health_monitor(health_monitor)
|
||||
changed = True
|
||||
|
||||
self.exit_json(changed=changed)
|
||||
except Exception as e:
|
||||
self.fail(msg=str(e))
|
||||
|
||||
|
||||
def main():
|
||||
module = HealthMonitorModule()
|
||||
module()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
219
plugins/modules/volume_backup.py
Normal file
219
plugins/modules/volume_backup.py
Normal file
@@ -0,0 +1,219 @@
|
||||
#!/usr/bin/python
|
||||
# coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (c) 2020 by Open Telekom Cloud, operated by T-Systems International GmbH
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
module: volume_backup
|
||||
short_description: Add/Delete Volume backup
|
||||
extends_documentation_fragment: openstack.cloud.openstack
|
||||
author: OpenStack Ansible SIG
|
||||
description:
|
||||
- Add or Remove Volume Backup in OTC.
|
||||
options:
|
||||
display_name:
|
||||
description:
|
||||
- Name that has to be given to the backup
|
||||
required: true
|
||||
type: str
|
||||
aliases: ['name']
|
||||
display_description:
|
||||
description:
|
||||
- String describing the backup
|
||||
required: false
|
||||
type: str
|
||||
aliases: ['description']
|
||||
state:
|
||||
description:
|
||||
- Should the resource be present or absent.
|
||||
choices: [present, absent]
|
||||
default: present
|
||||
type: str
|
||||
volume:
|
||||
description:
|
||||
- Name or ID of the volume. Required when state is True.
|
||||
type: str
|
||||
required: False
|
||||
snapshot:
|
||||
description: Name or ID of the Snapshot to take backup of
|
||||
type: str
|
||||
force:
|
||||
description:
|
||||
- Indicates whether to backup, even if the volume is attached.
|
||||
type: bool
|
||||
default: False
|
||||
metadata:
|
||||
description: Metadata for the backup
|
||||
type: dict
|
||||
incremental:
|
||||
description: The backup mode
|
||||
type: bool
|
||||
default: False
|
||||
requirements: ["openstacksdk"]
|
||||
'''
|
||||
|
||||
RETURN = '''
|
||||
id:
|
||||
description: The Volume backup ID.
|
||||
returned: On success when C(state=present)
|
||||
type: str
|
||||
sample: "39007a7e-ee4f-4d13-8283-b4da2e037c69"
|
||||
backup:
|
||||
description: Dictionary describing the Cluster.
|
||||
returned: On success when C(state=present)
|
||||
type: complex
|
||||
contains:
|
||||
id:
|
||||
description: Unique UUID.
|
||||
type: str
|
||||
sample: "39007a7e-ee4f-4d13-8283-b4da2e037c69"
|
||||
name:
|
||||
description: Name given to the load balancer.
|
||||
type: str
|
||||
sample: "elb_test"
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
- name: Create backup
|
||||
openstack.cloud.volume_backup:
|
||||
display_name: test_volume_backup
|
||||
volume: "test_volume"
|
||||
|
||||
- name: Create backup from snapshot
|
||||
openstack.cloud.volume_backup:
|
||||
display_name: test_volume_backup
|
||||
volume: "test_volume"
|
||||
snapshot: "test_snapshot"
|
||||
|
||||
- name: Delete volume backup
|
||||
openstack.cloud.volume_backup:
|
||||
display_name: test_volume_backup
|
||||
state: absent
|
||||
'''
|
||||
|
||||
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import OpenStackModule
|
||||
|
||||
|
||||
class VolumeBackupModule(OpenStackModule):
|
||||
argument_spec = dict(
|
||||
display_name=dict(required=True, aliases=['name'], type='str'),
|
||||
display_description=dict(required=False, aliases=['description'],
|
||||
type='str'),
|
||||
volume=dict(required=False, type='str'),
|
||||
snapshot=dict(required=False, type='str'),
|
||||
state=dict(default='present', type='str', choices=['absent', 'present']),
|
||||
force=dict(default=False, type='bool'),
|
||||
metadata=dict(required=False, type='dict'),
|
||||
incremental=dict(required=False, default=False, type='bool')
|
||||
)
|
||||
module_kwargs = dict(
|
||||
required_if=[
|
||||
('state', 'present', ['volume'])
|
||||
],
|
||||
supports_check_mode=True
|
||||
)
|
||||
|
||||
def _create_backup(self):
|
||||
if self.ansible.check_mode:
|
||||
self.exit_json(changed=True)
|
||||
|
||||
name = self.params['display_name']
|
||||
description = self.params['display_description']
|
||||
volume = self.params['volume']
|
||||
snapshot = self.params['snapshot']
|
||||
force = self.params['force']
|
||||
is_incremental = self.params['incremental']
|
||||
metadata = self.params['metadata']
|
||||
|
||||
changed = False
|
||||
|
||||
cloud_volume = self.conn.block_storage.find_volume(volume)
|
||||
cloud_snapshot_id = None
|
||||
|
||||
attrs = {
|
||||
'name': name,
|
||||
'volume_id': cloud_volume.id,
|
||||
'force': force,
|
||||
'is_incremental': is_incremental
|
||||
}
|
||||
|
||||
if snapshot:
|
||||
cloud_snapshot_id = self.conn.block_storage.find_snapshot(
|
||||
snapshot, ignore_missing=False).id
|
||||
attrs['snapshot_id'] = cloud_snapshot_id
|
||||
|
||||
if metadata:
|
||||
attrs['metadata'] = metadata
|
||||
|
||||
if description:
|
||||
attrs['description'] = description
|
||||
|
||||
backup = self.conn.block_storage.create_backup(**attrs)
|
||||
changed = True
|
||||
|
||||
if self.params['wait']:
|
||||
try:
|
||||
backup = self.conn.block_storage.wait_for_status(
|
||||
backup,
|
||||
status='available',
|
||||
wait=self.params['timeout'])
|
||||
self.exit_json(
|
||||
changed=True, volume_backup=backup.to_dict(), id=backup.id
|
||||
)
|
||||
except self.sdk.exceptions.ResourceTimeout:
|
||||
self.fail_json(
|
||||
msg='Timeout failure waiting for backup '
|
||||
'to complete'
|
||||
)
|
||||
|
||||
self.exit_json(
|
||||
changed=changed, volume_backup=backup.to_dict(), id=backup.id
|
||||
)
|
||||
|
||||
def _delete_backup(self, backup):
|
||||
if self.ansible.check_mode:
|
||||
self.exit_json(changed=True)
|
||||
|
||||
if backup:
|
||||
self.conn.block_storage.delete_backup(backup)
|
||||
if self.params['wait']:
|
||||
try:
|
||||
self.conn.block_storage.wait_for_delete(
|
||||
backup,
|
||||
interval=2,
|
||||
wait=self.params['timeout'])
|
||||
except self.sdk.exceptions.ResourceTimeout:
|
||||
self.fail_json(
|
||||
msg='Timeout failure waiting for backup '
|
||||
'to be deleted'
|
||||
)
|
||||
|
||||
self.exit_json(changed=True)
|
||||
|
||||
def run(self):
|
||||
name = self.params['display_name']
|
||||
|
||||
backup = self.conn.block_storage.find_backup(name)
|
||||
|
||||
if self.params['state'] == 'present':
|
||||
if not backup:
|
||||
self._create_backup()
|
||||
else:
|
||||
# For the moment we do not support backup update, since SDK
|
||||
# doesn't support it either => do nothing
|
||||
self.exit_json(changed=False)
|
||||
|
||||
elif self.params['state'] == 'absent':
|
||||
self._delete_backup(backup)
|
||||
|
||||
|
||||
def main():
|
||||
module = VolumeBackupModule()
|
||||
module()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
121
plugins/modules/volume_backup_info.py
Normal file
121
plugins/modules/volume_backup_info.py
Normal file
@@ -0,0 +1,121 @@
|
||||
#!/usr/bin/python
|
||||
# coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (c) 2020 by Open Telekom Cloud, operated by T-Systems International GmbH
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
module: volume_backup_info
|
||||
short_description: Get Backups
|
||||
author: OpenStack Ansible SIG
|
||||
description:
|
||||
- Get Backup info from the Openstack cloud.
|
||||
options:
|
||||
name:
|
||||
description:
|
||||
- Name of the Backup.
|
||||
type: str
|
||||
volume:
|
||||
description:
|
||||
- Name of the volume.
|
||||
type: str
|
||||
requirements: ["openstacksdk"]
|
||||
extends_documentation_fragment:
|
||||
- openstack.cloud.openstack
|
||||
'''
|
||||
|
||||
RETURN = '''
|
||||
volume_backups:
|
||||
description: List of dictionaries describing volume backups.
|
||||
type: list
|
||||
elements: dict
|
||||
returned: always.
|
||||
contains:
|
||||
availability_zone:
|
||||
description: Backup availability zone.
|
||||
type: str
|
||||
created_at:
|
||||
description: Backup creation time.
|
||||
type: str
|
||||
description:
|
||||
description: Backup desciption.
|
||||
type: str
|
||||
id:
|
||||
description: Unique UUID.
|
||||
type: str
|
||||
sample: "39007a7e-ee4f-4d13-8283-b4da2e037c69"
|
||||
is_incremental:
|
||||
description: Backup incremental property.
|
||||
type: bool
|
||||
metadata:
|
||||
description: Backup metadata.
|
||||
type: dict
|
||||
name:
|
||||
description: Backup Name.
|
||||
type: str
|
||||
snapshot_id:
|
||||
description: Snapshot ID.
|
||||
type: str
|
||||
status:
|
||||
description: Backup status.
|
||||
type: str
|
||||
updated_at:
|
||||
description: Backup update time.
|
||||
type: str
|
||||
volume_id:
|
||||
description: Volume ID.
|
||||
type: str
|
||||
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
# Get backups.
|
||||
- openstack.cloud.volume_backup_info:
|
||||
register: backup
|
||||
|
||||
- openstack.cloud.volume_backup_info:
|
||||
name: my_fake_backup
|
||||
register: backup
|
||||
'''
|
||||
|
||||
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import OpenStackModule
|
||||
|
||||
|
||||
class VolumeBackupInfoModule(OpenStackModule):
|
||||
argument_spec = dict(
|
||||
name=dict(required=False, type='str'),
|
||||
volume=dict(required=False, type='str')
|
||||
)
|
||||
|
||||
def run(self):
|
||||
name_filter = self.params['name']
|
||||
volume = self.params['volume']
|
||||
|
||||
data = []
|
||||
attrs = {}
|
||||
|
||||
if name_filter:
|
||||
attrs['name'] = name_filter
|
||||
if volume:
|
||||
attrs['volume_id'] = self.conn.block_storage.find_volume(volume)
|
||||
|
||||
for raw in self.conn.block_storage.backups(**attrs):
|
||||
dt = raw.to_dict()
|
||||
dt.pop('location')
|
||||
data.append(dt)
|
||||
|
||||
self.exit_json(
|
||||
changed=False,
|
||||
volume_backups=data
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
module = VolumeBackupInfoModule()
|
||||
module()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
131
plugins/modules/volume_snapshot_info.py
Normal file
131
plugins/modules/volume_snapshot_info.py
Normal file
@@ -0,0 +1,131 @@
|
||||
#!/usr/bin/python
|
||||
# coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (c) 2020 by Open Telekom Cloud, operated by T-Systems International GmbH
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
module: volume_snapshot_info
|
||||
short_description: Get volume snapshots
|
||||
author: OpenStack Ansible SIG
|
||||
description:
|
||||
- Get Volume Snapshot info from the Openstack cloud.
|
||||
options:
|
||||
details:
|
||||
description: More detailed output
|
||||
type: bool
|
||||
default: True
|
||||
name:
|
||||
description:
|
||||
- Name of the Snapshot.
|
||||
type: str
|
||||
volume:
|
||||
description:
|
||||
- Name of the volume.
|
||||
type: str
|
||||
status:
|
||||
description:
|
||||
- Specifies the snapshot status.
|
||||
choices: [creating, available, error, deleting,
|
||||
error_deleting, rollbacking, backing-up]
|
||||
type: str
|
||||
requirements: ["openstacksdk"]
|
||||
extends_documentation_fragment:
|
||||
- openstack.cloud.openstack
|
||||
'''
|
||||
|
||||
RETURN = '''
|
||||
volume_snapshots:
|
||||
description: List of dictionaries describing volume snapshots.
|
||||
type: list
|
||||
elements: dict
|
||||
returned: always.
|
||||
contains:
|
||||
created_at:
|
||||
description: Snapshot creation time.
|
||||
type: str
|
||||
description:
|
||||
description: Snapshot desciption.
|
||||
type: str
|
||||
id:
|
||||
description: Unique UUID.
|
||||
type: str
|
||||
sample: "39007a7e-ee4f-4d13-8283-b4da2e037c69"
|
||||
metadata:
|
||||
description: Snapshot metadata.
|
||||
type: dict
|
||||
name:
|
||||
description: Snapshot Name.
|
||||
type: str
|
||||
status:
|
||||
description: Snapshot status.
|
||||
type: str
|
||||
updated_at:
|
||||
description: Snapshot update time.
|
||||
type: str
|
||||
volume_id:
|
||||
description: Volume ID.
|
||||
type: str
|
||||
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
# Get snapshots.
|
||||
- openstack.cloud.volume_snapshot_info:
|
||||
register: snapshots
|
||||
|
||||
- openstack.cloud.volume_snapshotbackup_info:
|
||||
name: my_fake_snapshot
|
||||
register: snapshot
|
||||
'''
|
||||
|
||||
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import OpenStackModule
|
||||
|
||||
|
||||
class VolumeSnapshotInfoModule(OpenStackModule):
|
||||
argument_spec = dict(
|
||||
details=dict(default=True, type='bool'),
|
||||
name=dict(required=False, type='str'),
|
||||
volume=dict(required=False, type='str'),
|
||||
status=dict(required=False, type='str',
|
||||
choices=['creating', 'available', 'error',
|
||||
'deleting', 'error_deleting', 'rollbacking',
|
||||
'backing-up']),
|
||||
)
|
||||
|
||||
def run(self):
|
||||
|
||||
details_filter = self.params['details']
|
||||
name_filter = self.params['name']
|
||||
volume_filter = self.params['volume']
|
||||
status_filter = self.params['status']
|
||||
|
||||
data = []
|
||||
query = {}
|
||||
if name_filter:
|
||||
query['name'] = name_filter
|
||||
if volume_filter:
|
||||
query['volume_id'] = self.conn.block_storage.find_volume(volume_filter)
|
||||
if status_filter:
|
||||
query['status'] = status_filter.lower()
|
||||
|
||||
for raw in self.conn.block_storage.snapshots(details_filter, **query):
|
||||
dt = raw.to_dict()
|
||||
dt.pop('location')
|
||||
data.append(dt)
|
||||
|
||||
self.exit_json(
|
||||
changed=False,
|
||||
volume_snapshots=data
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
module = VolumeSnapshotInfoModule()
|
||||
module()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -1,5 +1,5 @@
|
||||
openstacksdk
|
||||
ansible
|
||||
ansible<2.10
|
||||
pycodestyle
|
||||
flake8
|
||||
pylint
|
||||
|
||||
Reference in New Issue
Block a user