Skip to content

Commit 013a2c0

Browse files
committed
Filter for instance id in statistics
1 parent d88a5d2 commit 013a2c0

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

plugins/modules/dcs_instance_statistics_info.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
author: "Sebastian Gode (@SebastianGode)"
2020
description:
2121
- Get Instance Statistics
22+
options:
23+
instance_id:
24+
description:
25+
- Instance ID to filter results for that instance
26+
type: str
27+
required: false
2228
requirements: ["openstacksdk", "otcextensions"]
2329
'''
2430

@@ -47,31 +53,48 @@
4753
'''
4854

4955
EXAMPLES = '''
50-
# Query statistics
56+
# Query statistics about all instances
5157
- opentelekomcloud.cloud.dcs_instance_statistics_info:
58+
59+
# Query statistics about a specific instance
60+
- opentelekomcloud.cloud.dcs_instance_statistics_info:
61+
instance_id: "12345678-b17b-434d-b6a1-4cc5abb1f2ca"
5262
'''
5363

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

5666

5767
class DcsInstanceStatisticsInfoModule(OTCModule):
5868
argument_spec = dict(
69+
instance_id=dict(required=False)
5970
)
6071
module_kwargs = dict(
6172
supports_check_mode=True
6273
)
6374

6475
def run(self):
6576
data = []
77+
final_data = []
6678

6779
for raw in self.conn.dcs.statistics():
6880
dt = raw.to_dict()
6981
dt.pop('location')
7082
data.append(dt)
7183

84+
i = 0
85+
while i < len(data):
86+
if self.params['instance_id']:
87+
if data[i]['instance_id'] == self.params['instance_id']:
88+
final_data = data[i]
89+
break
90+
else:
91+
final_data = data
92+
break
93+
i = i + 1
94+
7295
self.exit(
7396
changed=False,
74-
instances=data
97+
instances=final_data
7598
)
7699

77100

0 commit comments

Comments
 (0)