-
Notifications
You must be signed in to change notification settings - Fork 14
DCS Modules #97
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
Open
SebastianGode
wants to merge
31
commits into
main
Choose a base branch
from
dcs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
DCS Modules #97
Changes from 23 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
7becf6e
Added dcs_instance_info
SebastianGode 2315f35
Added dcs_instance_info
SebastianGode 0d9c6e3
Added dcs_instance creation
SebastianGode bac1812
Functional dcs_instance
SebastianGode 42736be
Added doku
SebastianGode 1c1c6ee
rename
SebastianGode 4706eed
Fixed Sanity
SebastianGode ecfa51b
Some new modules
SebastianGode cf322b7
Some new modules
SebastianGode 49955f2
Fixed backup
SebastianGode 627c311
Fixed sanity
SebastianGode b984389
Sanity and Docu on backup modules
SebastianGode 3bc910b
Sanity and docu fixes
SebastianGode ecb0128
Fixed Sanity with ignore
SebastianGode 4b5375e
Integration Test (disabled) + new non-working module
SebastianGode 30b1a14
Fixed Sanity
SebastianGode f6040cc
Fixed Sanity
SebastianGode 1310a50
Fixed Sanity
SebastianGode 7c895f8
disabled integration test
SebastianGode 68e8565
Backup Modules check mode fix
SebastianGode fddded7
Make passwords hidden
SebastianGode 9802dee
changed password
SebastianGode 68c0116
Fixed Sanity
SebastianGode 99b8ed6
Merge branch 'master' into dcs
SebastianGode 7d428e6
Changed Backup
SebastianGode 085971d
Merge branch 'dcs' of github.com:opentelekomcloud/ansible-collection-…
SebastianGode d88a5d2
Changes
SebastianGode 013a2c0
Filter for instance id in statistics
SebastianGode a5c2b26
Added integration test
SebastianGode d1f0d9c
Better loop for filter
SebastianGode 711ad42
Merge branch 'master' into dcs
gtema File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
#!/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.0" | ||
author: "Sebastian Gode (@SebastianGode)" | ||
description: | ||
- Manage DCS Instance-Backups on Open Telekom Cloud | ||
options: | ||
instance_id: | ||
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_id: 12345678-20fb-441b-a0cd-46369a9f7db0 | ||
description: "This is a test" | ||
|
||
# Restore a backup | ||
- opentelekomcloud.cloud.dcs_instance_backup: | ||
instance_id: 12345678-20fb-441b-a0cd-46369a9f7db0 | ||
backup_id: 12345678-f021-417f-b019-dc02182926a9 | ||
|
||
# Delete a backup | ||
- opentelekomcloud.cloud.dcs_instance_backup: | ||
instance_id: 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_id=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 | ||
) | ||
|
||
def run(self): | ||
changed = False | ||
attrs = {} | ||
|
||
instance = self.conn.dcs.find_instance( | ||
name_or_id=self.params['instance_id'], | ||
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 self.params['backup_id']: | ||
if not self.ansible.check_mode: | ||
dcs_instance = self.conn.dcs.delete_instance_backup(self.params['backup_id'], instance.id) | ||
self.exit(changed=True, dcs_instance=dcs_instance) | ||
self.exit_json(True) | ||
else: | ||
self.exit( | ||
SebastianGode marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
changed=False, | ||
message=('No backup_id %s provided but required for deletion!'), | ||
failed=True | ||
) | ||
|
||
else: | ||
self.exit( | ||
changed=False, | ||
message=('No Instance with name or id %s found!', self.params['id']), | ||
failed=True | ||
) | ||
|
||
self.exit( | ||
changed=changed | ||
) | ||
|
||
|
||
def main(): | ||
module = DcsInstanceModule() | ||
module() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.3.0" | ||
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() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.