From 57680362f72714302fe8fc9cb51d2c091cbb8666 Mon Sep 17 00:00:00 2001 From: mischa Date: Wed, 15 Jun 2022 10:43:29 +0200 Subject: [PATCH] extra debug scripts --- awsvpcconnectors.txt | 25 +++++++++++++++++--- get.py | 5 ++-- push-debug.py | 55 ++++++++++++++++++++++++++++++++++++++++++++ push.py | 20 +++------------- validate-json.py | 7 ++++++ 5 files changed, 90 insertions(+), 22 deletions(-) create mode 100755 push-debug.py create mode 100755 validate-json.py diff --git a/awsvpcconnectors.txt b/awsvpcconnectors.txt index 4429594..af7652d 100644 --- a/awsvpcconnectors.txt +++ b/awsvpcconnectors.txt @@ -1,4 +1,22 @@ -{ +[ + { + "customerName": "AlkiraEMEA_US-East2-1-vpc", + "customerRegion": "us-east-2", + "vpcId": "vpc-052769d7efd0e75eb", + "vpcOwnerId": "138319602003", + "credentialId": "b269e6d7-2b7d-45dc-9fb5-5ac1f49db139", + "segments": [ + "Corporate" + ], + "size": "MEDIUM", + "name": "AlkiraEMEA_US-East2-2-vpc", + "cxp": "US-EAST-2", + "group": "Users", + "billingTags": [ + "333" + ], + }, + { "customerName": "AlkiraEMEA_US-East2-2-vpc", "customerRegion": "us-east-2", "vpcId": "vpc-007815b7e755ac4b3", @@ -12,6 +30,7 @@ "cxp": "US-EAST-2", "group": "Users", "billingTags": [ - 333 + "333" ], -} + } +] diff --git a/get.py b/get.py index 03182dc..1f0708f 100755 --- a/get.py +++ b/get.py @@ -95,18 +95,19 @@ r = alkira_get(s, f'/tenantnetworks/{tenantNetworkId}/connectors') data = r.json() print('# Connectors') print(json.dumps(data, indent=4)) +#print(data) # Get services logging.info('Checking services') r = alkira_get(s, f'/tenantnetworks/{tenantNetworkId}/services') data = r.json() print('# Services') -print(json.dumps(data, indent=4)) +#print(json.dumps(data, indent=4)) # Get Global CIDR logging.info('Checking Global CIDR') r = alkira_get(s, f'/tenantnetworks/{tenantNetworkId}/global-cidr-lists') data = r.json() print('# Global CIDR') -print(json.dumps(data, indent=4)) +#print(json.dumps(data, indent=4)) diff --git a/push-debug.py b/push-debug.py new file mode 100755 index 0000000..926902d --- /dev/null +++ b/push-debug.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 + +import os +import sys +import re +import json +import time +import logging +import requests +import configparser + +############################################### + +CONFIG_FILE = "/Users/mischa/Alkira/xDev/alkira.cnf" +if not os.path.isfile(CONFIG_FILE): + logging.error(f"The config file {CONFIG_FILE} doesn't exist") + sys.exit(1) +config = configparser.RawConfigParser() +config.read(CONFIG_FILE) + +ALKIRA_TENANT = config.get('alkira', 'ALKIRA_TENANT') +ALKIRA_USERNAME = config.get('alkira', 'ALKIRA_USERNAME') +ALKIRA_PASSWORD = config.get('alkira', 'ALKIRA_PASSWORD') +ALKIRA_BASE_URI = f'https://{ALKIRA_TENANT}/api' + +############################################### + +# Set default headers +headers = {'Content-Type': "application/json"} + +# Authenticate +body = {'userName': ALKIRA_USERNAME, + 'password': ALKIRA_PASSWORD} +url = f'{ALKIRA_BASE_URI}/login' +session = requests.session() +response = session.post(url, data=json.dumps(body), headers=headers) + +# Get TenantID +url = f'{ALKIRA_BASE_URI}/tenantnetworks' +response = session.get(url, headers=headers) +data = response.json() +tenantNetworkId = data[0]['id'] +tenantName = data[0]['name'] +logging.info(f'Tenant Name: {tenantName}') +logging.info(f'Tenant ID: {tenantNetworkId}') + +# Do Things +with open ('dump.txt', 'r') as f: + body = json.load(f) +print(json.dumps(body)) + +url = f'{ALKIRA_BASE_URI}/tenantnetworks/{tenantNetworkId}/awsvpcconnectors' +response = session.post(url, data=json.dumps(body), headers=headers) +print(response.status_code) +print(response.content) diff --git a/push.py b/push.py index 9ea9611..4d541a7 100755 --- a/push.py +++ b/push.py @@ -92,23 +92,9 @@ logging.info(f'Tenant ID: {tenantNetworkId}') # Push connectors logging.info('Push Connectors') -body = { - "customerName": "AlkiraEMEA_US-East2-2-vpc", - "customerRegion": "us-east-2", - "vpcId": "vpc-007815b7e755ac4b3", - "vpcOwnerId": "138319602003", - "credentialId": "b269e6d7-2b7d-45dc-9fb5-5ac1f49db139", - "segments": [ - "Corporate" - ], - "size": "MEDIUM", - "name": "AlkiraEMEA_US-East2-2-vpc", - "cxp": "US-EAST-2", - "group": "Users", - "billingTags": [ - 333 - ], -} +with open ('dump.txt', 'r') as f: + body = json.load(f) +print(json.dumps(body)) r = alkira_post(s, f'/tenantnetworks/{tenantNetworkId}/awsvpcconnectors', body) data = r.json() diff --git a/validate-json.py b/validate-json.py new file mode 100755 index 0000000..a701825 --- /dev/null +++ b/validate-json.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python3 + +import json + +with open ('dump.txt', 'r') as f: + body = json.load(f) +print(body)