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

DCS Modules #97

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
7becf6e
Added dcs_instance_info
SebastianGode Feb 26, 2021
2315f35
Added dcs_instance_info
SebastianGode Feb 26, 2021
0d9c6e3
Added dcs_instance creation
SebastianGode Feb 26, 2021
bac1812
Functional dcs_instance
SebastianGode Mar 2, 2021
42736be
Added doku
SebastianGode Mar 2, 2021
1c1c6ee
rename
SebastianGode Mar 2, 2021
4706eed
Fixed Sanity
SebastianGode Mar 2, 2021
ecfa51b
Some new modules
SebastianGode Mar 2, 2021
cf322b7
Some new modules
SebastianGode Mar 3, 2021
49955f2
Fixed backup
SebastianGode Mar 8, 2021
627c311
Fixed sanity
SebastianGode Mar 8, 2021
b984389
Sanity and Docu on backup modules
SebastianGode Mar 9, 2021
3bc910b
Sanity and docu fixes
SebastianGode Mar 9, 2021
ecb0128
Fixed Sanity with ignore
SebastianGode Mar 9, 2021
4b5375e
Integration Test (disabled) + new non-working module
SebastianGode Mar 10, 2021
30b1a14
Fixed Sanity
SebastianGode Mar 10, 2021
f6040cc
Fixed Sanity
SebastianGode Mar 10, 2021
1310a50
Fixed Sanity
SebastianGode Mar 10, 2021
7c895f8
disabled integration test
SebastianGode Mar 10, 2021
68e8565
Backup Modules check mode fix
SebastianGode May 3, 2021
fddded7
Make passwords hidden
SebastianGode May 3, 2021
9802dee
changed password
SebastianGode May 3, 2021
68c0116
Fixed Sanity
SebastianGode Jun 11, 2021
99b8ed6
Merge branch 'master' into dcs
SebastianGode Jun 24, 2021
7d428e6
Changed Backup
SebastianGode Jun 28, 2021
085971d
Merge branch 'dcs' of github.com:opentelekomcloud/ansible-collection-…
SebastianGode Jun 28, 2021
d88a5d2
Changes
SebastianGode Jun 28, 2021
013a2c0
Filter for instance id in statistics
SebastianGode Jun 28, 2021
a5c2b26
Added integration test
SebastianGode Jun 28, 2021
d1f0d9c
Better loop for filter
SebastianGode Jul 1, 2021
711ad42
Merge branch 'master' into dcs
gtema Nov 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
538 changes: 538 additions & 0 deletions plugins/modules/dcs_instance.py

Large diffs are not rendered by default.

165 changes: 165 additions & 0 deletions plugins/modules/dcs_instance_backup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
#!/usr/bin/python
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

DOCUMENTATION = '''
module: dcs_instance_backup
short_description: Manage DCS Instance-Backups on Open Telekom Cloud
extends_documentation_fragment: opentelekomcloud.cloud.otc
version_added: "0.8.2"
author: "Sebastian Gode (@SebastianGode)"
description:
- Manage DCS Instance-Backups on Open Telekom Cloud
options:
instance:
description:
- Specifies the name or ID of the instance
type: str
required: true
description:
description:
- Specifies the description of the backup
type: str
backup_id:
description:
- Specifies the backup ID which is required for restoring or deletion
type: str
state:
choices: [present, absent]
default: present
description: Instance state
type: str
requirements: ["openstacksdk", "otcextensions"]
'''

RETURN = '''
dcs_instance:
description: Dictionary of DCS instance
returned: changed
type: dict
sample: {
"dcs_instance": {
"created_at": null,
"description": null,
"error_code": null,
"id": "12345678-4b3a-4dfa-9f13-33c732a8f497",
"is_restorable": null,
"location": {
"cloud": "otc",
"project": {
"domain_id": null,
"domain_name": null,
"id": "123456768a13b49529d2e2c3646691288",
"name": "eu-de"
},
"region_name": "eu-de",
"zone": null
},
"name": null,
"period": null,
"progress": null,
"size": null,
"status": null,
"type": null,
"updated_at": null
}
}
'''

EXAMPLES = '''
# Create a Backup
- opentelekomcloud.cloud.dcs_instance_backup:
instance: 12345678-20fb-441b-a0cd-46369a9f7db0
description: "This is a test"

# Restore a backup
- opentelekomcloud.cloud.dcs_instance_backup:
instance: 12345678-20fb-441b-a0cd-46369a9f7db0
backup_id: 12345678-f021-417f-b019-dc02182926a9

# Delete a backup
- opentelekomcloud.cloud.dcs_instance_backup:
instance: 12345678-20fb-441b-a0cd-46369a9f7db0
backup_id: 12345678-f021-417f-b019-dc02182926a9
state: absent
'''

from ansible_collections.opentelekomcloud.cloud.plugins.module_utils.otc import OTCModule


class DcsInstanceModule(OTCModule):
argument_spec = dict(
instance=dict(required=True),
description=dict(required=False),
backup_id=dict(required=False),
state=dict(type='str', choices=['present', 'absent'], default='present')
)
module_kwargs = dict(
supports_check_mode=True,
required_if=[
('state', 'absent',
['backup_id'])
]
)

def run(self):
changed = False
attrs = {}

instance = self.conn.dcs.find_instance(
name_or_id=self.params['instance'],
ignore_missing=True
)
if instance:
if self.params['state'] == 'present':
if self.params['description']:
attrs['description'] = self.params['description']
# Restore Backup
if self.params['backup_id']:
attrs['backup_id'] = self.params['backup_id']
if not self.ansible.check_mode:
dcs_instance = self.conn.dcs.restore_instance(instance.id, **attrs)
self.exit(changed=True, dcs_instance=dcs_instance.to_dict())
self.exit_json(True)

# Create Backup
else:
if not self.ansible.check_mode:
dcs_instance = self.conn.dcs.backup_instance(instance.id, **attrs)
self.exit(changed=True, dcs_instance=dcs_instance.to_dict())
self.exit_json(True)

elif self.params['state'] == 'absent':
if not self.ansible.check_mode:
dcs_instance = self.conn.dcs.delete_instance_backup(self.params['backup_id'], instance.id)
SebastianGode marked this conversation as resolved.
Show resolved Hide resolved
self.exit(changed=True, dcs_instance=dcs_instance)
self.exit_json(True)

else:
self.exit(
changed=False,
message=('No Instance with name or id %s found!', self.params['instance']),
failed=True
)

self.exit(
changed=changed
)


def main():
module = DcsInstanceModule()
module()


if __name__ == "__main__":
main()
91 changes: 91 additions & 0 deletions plugins/modules/dcs_instance_backup_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/usr/bin/python
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

DOCUMENTATION = '''
module: dcs_instance_backup_info
short_description: Get Instance backup informations
extends_documentation_fragment: opentelekomcloud.cloud.otc
version_added: "0.8.2"
author: "Sebastian Gode (@SebastianGode)"
description:
- Get Instance backup informations
requirements: ["openstacksdk", "otcextensions"]
options:
id:
description:
- Instance ID or name of the chosen DCS Instance
type: str
required: true
'''

RETURN = '''
instances:
description: Dictionary of Metrics
returned: changed
type: list
sample: [
{
"created_at": "2021-03-02T13:23:42.968Z",
"description": null,
"error_code": null,
"id": "c417bd7d-f021-417f-b019-dc02182926a9",
"name": "backup_20210302142342",
"period": null,
"progress": "100.00",
"size": 124,
"status": "succeed",
"type": "manual",
"updated_at": "2021-03-02T13:25:30.723Z"
}
]
'''

EXAMPLES = '''
# Query Params
- opentelekomcloud.cloud.dcs_instance_backup_info:
id: 12345678-20fb-441b-a0cd-46369a9f7db0
'''

from ansible_collections.opentelekomcloud.cloud.plugins.module_utils.otc import OTCModule


class DcsInstanceBackupInfoModule(OTCModule):
argument_spec = dict(
id=dict(required=True),
)
module_kwargs = dict(
supports_check_mode=True
)

def run(self):
data = []

for raw in self.conn.dcs.backups(self.params['id']):
dt = raw.to_dict()
dt.pop('location')
dt.pop('is_restorable')
data = dt

self.exit(
changed=False,
instances=data
)


def main():
module = DcsInstanceBackupInfoModule()
module()


if __name__ == '__main__':
main()
115 changes: 115 additions & 0 deletions plugins/modules/dcs_instance_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#!/usr/bin/python
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

DOCUMENTATION = '''
module: dcs_instance_info
short_description: Get Instance Informations
extends_documentation_fragment: opentelekomcloud.cloud.otc
version_added: "0.8.2"
author: "Sebastian Gode (@SebastianGode)"
description:
- Get Instance Informations
requirements: ["openstacksdk", "otcextensions"]
'''

RETURN = '''
instances:
description: Dictionary of Metrics
returned: changed
type: list
sample: [
{
"available_zones": null,
"backup_policy": null,
"capacity": 2,
"charging_mode": 0,
"created_at": "2021-02-26T08:21:49.137Z",
"description": null,
"domain_name": null,
"engine": "Redis",
"engine_version": "3.0",
"error_code": null,
"id": "6543212f-6bd4-45df-9c4e-fadb35d6e0d0",
"internal_version": null,
"ip": "192.168.10.12",
"lock_time": null,
"lock_time_left": null,
"maintain_begin": "02:00:00",
"maintain_end": "06:00:00",
"max_memory": 1536,
"message": null,
"name": "dcs-qrt6",
"order_id": null,
"password": null,
"port": 6379,
"product_id": null,
"resource_spec_code": "dcs.master_standby",
"result": null,
"retry_times_left": null,
"security_group_id": "6543212f-b782-4aff-8311-19896597fd4e",
"security_group_name": null,
"status": "RUNNING",
"subnet_cidr": null,
"subnet_id": null,
"subnet_name": null,
"used_memory": 4,
"user_id": "1234567890bb4c6f81bc358d54693962",
"user_name": "user",
"vpc_id": "12345678-dc40-4e3a-95b1-5a0756441e12",
"vpc_name": null
}
]
'''

EXAMPLES = '''
# Query Instance Informations from DCS Instance with ID
- opentelekomcloud.cloud.dcs_instance_info:
instance_id: 6543212f-6bd4-45df-9c4e-fadb35d6e0d0

# Query all existing Instances
- opentelekomcloud.cloud.dcs_instance_info:
'''

from ansible_collections.opentelekomcloud.cloud.plugins.module_utils.otc import OTCModule


class DcsInstanceInfoModule(OTCModule):
argument_spec = dict(
)
module_kwargs = dict(
supports_check_mode=True
)

def run(self):

data = []
query = {}

for raw in self.conn.dcs.instances(**query):
dt = raw.to_dict()
dt.pop('location')
data.append(dt)

self.exit(
changed=False,
instances=data
)


def main():
module = DcsInstanceInfoModule()
module()


if __name__ == '__main__':
main()
Loading