add exceptions for OCI and simplify push-debug file regex

This commit is contained in:
mischa 2022-06-17 18:18:03 +02:00
parent 7452f8fa44
commit 5ebeee4c8d
2 changed files with 17 additions and 3 deletions

View File

@ -77,6 +77,15 @@ ALKIRA_BASE_URI = f'https://{ALKIRA_TENANT}/api'
# Set default headers
headers = {'Content-Type': "application/json"}
# Naming exceptions
service_exceptions = {
"saas": "internet",
"pan": "panfw",
"ftntfw": "ftnt-fw-",
"chkpfw": "chkp-fw-",
"ocivcnconnectors": "oci-vcn-connectors"
}
# Authenticate
body = {'userName': ALKIRA_USERNAME,
'password': ALKIRA_PASSWORD}
@ -96,10 +105,10 @@ logging.info(f'Tenant ID: {tenantNetworkId}')
print(json_file)
# Do Things
connector_result = re.match(r'(.*)\/?(\w+)(\d+)', json_file)
connector_result = re.match(r'(\w+)(\d+)', json_file)
connector_name = connector_result.group(1)
connector_number = connector_result.group(2)
logging.debug(f'Connector Name: {connector_name} - Number: {connecter_nunber}')
with open (json_file, 'r') as f:
body = json.load(f)
if args.pretty:
@ -107,6 +116,8 @@ with open (json_file, 'r') as f:
else:
print(json.dumps(body))
if connector_name in service_exceptions.keys():
connector_name = service_exceptions[connector_name]
url = f'{ALKIRA_BASE_URI}/tenantnetworks/{tenantNetworkId}/{connector_name}'
response = session.post(url, data=json.dumps(body), headers=headers)
print(response.status_code)

View File

@ -85,7 +85,8 @@ service_exceptions = {
"saas": "internet",
"pan": "panfw",
"ftntfw": "ftnt-fw-",
"chkpfw": "chkp-fw-"
"chkpfw": "chkp-fw-",
"ocivcnconnectors": "oci-vcn-connectors"
}
def alkira_login():
@ -184,6 +185,8 @@ for connector in config.sections():
logging.debug(json.dumps(body))
logging.info(f'Pushing {connector_name} to {cxp} (network segment: {segments}; group: {group})')
if connector_name in service_exceptions.keys():
connector_name = service_exceptions[connector_name]
r = alkira_post(s, f'/tenantnetworks/{tenantNetworkId}/{connector_name}', body)
logging.info(r.status_code)
logging.debug(r.content)