Skip to content

Commit

Permalink
Filter for instance id in statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianGode committed Jun 28, 2021
1 parent d88a5d2 commit 013a2c0
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions plugins/modules/dcs_instance_statistics_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
author: "Sebastian Gode (@SebastianGode)"
description:
- Get Instance Statistics
options:
instance_id:
description:
- Instance ID to filter results for that instance
type: str
required: false
requirements: ["openstacksdk", "otcextensions"]
'''

Expand Down Expand Up @@ -47,31 +53,48 @@
'''

EXAMPLES = '''
# Query statistics
# Query statistics about all instances
- opentelekomcloud.cloud.dcs_instance_statistics_info:
# Query statistics about a specific instance
- opentelekomcloud.cloud.dcs_instance_statistics_info:
instance_id: "12345678-b17b-434d-b6a1-4cc5abb1f2ca"
'''

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


class DcsInstanceStatisticsInfoModule(OTCModule):
argument_spec = dict(
instance_id=dict(required=False)
)
module_kwargs = dict(
supports_check_mode=True
)

def run(self):
data = []
final_data = []

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

i = 0
while i < len(data):
if self.params['instance_id']:
if data[i]['instance_id'] == self.params['instance_id']:
final_data = data[i]
break
else:
final_data = data
break
i = i + 1

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


Expand Down

0 comments on commit 013a2c0

Please sign in to comment.