From a0b05ec572dc53d5ce4b8cff7cbbb22a644aabd0 Mon Sep 17 00:00:00 2001 From: "aurelien.legrand01@gmail.com" Date: Mon, 30 Oct 2023 11:22:53 +0100 Subject: [PATCH 1/4] Handling SQL IP address issue --- .../network-dashboard/src/plugins/discover-cai.py | 13 ++++++++----- .../network-dashboard/src/plugins/series-psa.py | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/blueprints/cloud-operations/network-dashboard/src/plugins/discover-cai.py b/blueprints/cloud-operations/network-dashboard/src/plugins/discover-cai.py index 246ebfe0d6..794cc4d1bc 100644 --- a/blueprints/cloud-operations/network-dashboard/src/plugins/discover-cai.py +++ b/blueprints/cloud-operations/network-dashboard/src/plugins/discover-cai.py @@ -212,14 +212,17 @@ def _handle_routes(resource, data): def _handle_sql_instances(resource, data): 'Handles cloud sql instance type resource data.' + ip_addressses = [] + if data.get('ipAddresses'): + ip_addressses = [ + i['ipAddress'] + for i in data.get('ipAddresses') + if i['type'] == 'PRIVATE' + ] return { 'name': data['name'], 'self_link': _self_link(data['selfLink']), - 'ipAddresses': [ - i['ipAddress'] - for i in data.get('ipAddresses') - if i['type'] == 'PRIVATE' - ], + 'ipAddresses': ip_addressses, 'region': data['region'], 'availabilityType': data['settings']['availabilityType'], 'network': data['settings']['ipConfiguration'].get('privateNetwork') diff --git a/blueprints/cloud-operations/network-dashboard/src/plugins/series-psa.py b/blueprints/cloud-operations/network-dashboard/src/plugins/series-psa.py index f2e676d76b..442cf2c29c 100644 --- a/blueprints/cloud-operations/network-dashboard/src/plugins/series-psa.py +++ b/blueprints/cloud-operations/network-dashboard/src/plugins/series-psa.py @@ -31,7 +31,7 @@ def _sql_addresses(sql_instances): 'Returns counts of Cloud SQL instances per PSA range.' for v in sql_instances.values(): - if not v['ipAddresses']: + if not v.get('ipAddresses'): continue # 1 IP for the instance + 1 IP for the ILB + 1 IP if HA yield v['ipAddresses'][ From e46519765436a4c7da75cb8e3c5d2f184451b6f4 Mon Sep 17 00:00:00 2001 From: "aurelien.legrand01@gmail.com" Date: Mon, 30 Oct 2023 12:35:11 +0100 Subject: [PATCH 2/4] reverting one change --- .../network-dashboard/src/plugins/series-psa.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blueprints/cloud-operations/network-dashboard/src/plugins/series-psa.py b/blueprints/cloud-operations/network-dashboard/src/plugins/series-psa.py index 442cf2c29c..f2e676d76b 100644 --- a/blueprints/cloud-operations/network-dashboard/src/plugins/series-psa.py +++ b/blueprints/cloud-operations/network-dashboard/src/plugins/series-psa.py @@ -31,7 +31,7 @@ def _sql_addresses(sql_instances): 'Returns counts of Cloud SQL instances per PSA range.' for v in sql_instances.values(): - if not v.get('ipAddresses'): + if not v['ipAddresses']: continue # 1 IP for the instance + 1 IP for the ILB + 1 IP if HA yield v['ipAddresses'][ From 73ded02e811209e9b1b7f1f36dad27aa49a8c3e0 Mon Sep 17 00:00:00 2001 From: "aurelien.legrand01@gmail.com" Date: Mon, 30 Oct 2023 16:33:52 +0100 Subject: [PATCH 3/4] Improving this fix based on wiktor's feedback --- .../network-dashboard/src/plugins/discover-cai.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/blueprints/cloud-operations/network-dashboard/src/plugins/discover-cai.py b/blueprints/cloud-operations/network-dashboard/src/plugins/discover-cai.py index 794cc4d1bc..35585e59e4 100644 --- a/blueprints/cloud-operations/network-dashboard/src/plugins/discover-cai.py +++ b/blueprints/cloud-operations/network-dashboard/src/plugins/discover-cai.py @@ -212,17 +212,14 @@ def _handle_routes(resource, data): def _handle_sql_instances(resource, data): 'Handles cloud sql instance type resource data.' - ip_addressses = [] - if data.get('ipAddresses'): - ip_addressses = [ - i['ipAddress'] - for i in data.get('ipAddresses') - if i['type'] == 'PRIVATE' - ] return { 'name': data['name'], 'self_link': _self_link(data['selfLink']), - 'ipAddresses': ip_addressses, + 'ipAddresses': [ + i['ipAddress'] + for i in data.get('ipAddresses', []) + if i['type'] == 'PRIVATE' + ], 'region': data['region'], 'availabilityType': data['settings']['availabilityType'], 'network': data['settings']['ipConfiguration'].get('privateNetwork') From 46c17ff8dceb752f22aa18c260cb72a05a907b9a Mon Sep 17 00:00:00 2001 From: "aurelien.legrand01@gmail.com" Date: Mon, 30 Oct 2023 17:00:11 +0100 Subject: [PATCH 4/4] formatting --- .../network-dashboard/src/plugins/discover-cai.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/blueprints/cloud-operations/network-dashboard/src/plugins/discover-cai.py b/blueprints/cloud-operations/network-dashboard/src/plugins/discover-cai.py index 35585e59e4..5a87d93b4f 100644 --- a/blueprints/cloud-operations/network-dashboard/src/plugins/discover-cai.py +++ b/blueprints/cloud-operations/network-dashboard/src/plugins/discover-cai.py @@ -216,10 +216,10 @@ def _handle_sql_instances(resource, data): 'name': data['name'], 'self_link': _self_link(data['selfLink']), 'ipAddresses': [ - i['ipAddress'] - for i in data.get('ipAddresses', []) - if i['type'] == 'PRIVATE' - ], + i['ipAddress'] + for i in data.get('ipAddresses', []) + if i['type'] == 'PRIVATE' + ], 'region': data['region'], 'availabilityType': data['settings']['availabilityType'], 'network': data['settings']['ipConfiguration'].get('privateNetwork')