From d1f0d9c325e8f976cad7150357bc83ac602eb427 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Thu, 1 Jul 2021 07:42:06 +0000 Subject: [PATCH] Better loop for filter --- plugins/modules/dcs_instance_statistics_info.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/plugins/modules/dcs_instance_statistics_info.py b/plugins/modules/dcs_instance_statistics_info.py index bfc26f8f..da40c9e3 100644 --- a/plugins/modules/dcs_instance_statistics_info.py +++ b/plugins/modules/dcs_instance_statistics_info.py @@ -66,31 +66,24 @@ class DcsInstanceStatisticsInfoModule(OTCModule): argument_spec = dict( - instance_id=dict(required=False) + 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] + if raw.instance_id == self.params['instance_id']: + final_data = dt break else: - final_data = data - break - i = i + 1 + final_data.append(dt) self.exit( changed=False,