diff --git a/config/ipsecconnectors1.txt b/config/ipsecconnectors1.txt index 217ed34..f61f3f8 100644 --- a/config/ipsecconnectors1.txt +++ b/config/ipsecconnectors1.txt @@ -1,7 +1,6 @@ { "name": "SanJose", "cxp": "US-EAST-2", - "cxpId": "5ada678d-ce4a-428a-ac8d-0dc636b72b10", "type": "IP_SEC", "group": "Users", "segments": [ @@ -13,7 +12,6 @@ "customerGwAsn": "60131" } }, - "groupType": "USER", "sites": [ { "name": "PAN", diff --git a/config/ipsecconnectors2.txt b/config/ipsecconnectors2.txt index 17bc5f0..5284049 100644 --- a/config/ipsecconnectors2.txt +++ b/config/ipsecconnectors2.txt @@ -1,7 +1,6 @@ { "name": "Amsterdam", "cxp": "US-EAST-2", - "cxpId": "5ada678d-ce4a-428a-ac8d-0dc636b72b10", "type": "IP_SEC", "group": "Users", "segments": [ @@ -13,7 +12,6 @@ "customerGwAsn": "60131" } }, - "groupType": "USER", "sites": [ { "name": "PAN", diff --git a/push.py b/push.py index 3cd5a35..99399d4 100755 --- a/push.py +++ b/push.py @@ -126,22 +126,6 @@ logging.info('Push Connectors') for connector in config.sections(): section = config[connector] - region = section['cxp'] - segments = section['segments'] - logging.debug(f'{section} - {region} - {segments}') - if 'region' in config: - region = section['region'] - logging.debug(region) - if 'segments' in config: - segments = section['segments'] - logging.debug(segments) - if 'group' in config: - group = section['group'] - logging.debug(group) - if 'billingtags' in config: - billingtags = section['billingtags'] - logging.debug(billingtags) - connector_result = re.match(r'(\w+)(\d+)', connector) connector_name = connector_result.group(1) connector_number = connector_result.group(2) @@ -149,16 +133,41 @@ for connector in config.sections(): config_path = (f'{connector_folder}/{connector_name}{connector_number}.txt') with open (config_path, 'r') as f: body = json.load(f) - body['cxp'] = region - body['segments'][0] = segments - if 'group' in body and 'group' in globals(): - body['group'] = group - if 'billingTags' in body and 'billingtags' in globals(): - body['billingTags'][0] = billingtags + if 'cxp' in body: + cxp = body['cxp'] + logging.debug(f'JSON cxp: {cxp}') + if 'cxp' in section: + cxp = section['cxp'] + logging.debug(f'CONFIG cxp: {cxp}') + body['cxp'] = cxp + + if 'segments' in body: + segments = body['segments'][0] + logging.debug(f'JSON segments: {segments}') + if 'segments' in section: + segments = section['segments'] + logging.debug(f'CONFIG segments: {segments}') + body['segments'][0] = segments + + if 'group' in body: + group = body['group'] + logging.debug(f'JSON group: {group}') + if 'group' in section: + group = section['group'] + logging.debug(f'CONFIG group: {group}') + body['group'] = group + + if 'billingTags' in body: + billingtags = body['billingTags'][0] + logging.debug(f'JSON billingtags: {billingtags}') + if 'billingtags' in section: + billingtags = section['billingtags'] + logging.debug(f'CONFIG billingtags: {billingtags}') + body['billingTags'][0] = billingtags logging.debug(json.dumps(body)) - logging.info(f'Pushing {connector_name} to {region} (network segment: {segments})') + logging.info(f'Pushing {connector_name} to {cxp} (network segment: {segments}; group: {group})') r = alkira_post(s, f'/tenantnetworks/{tenantNetworkId}/{connector_name}', body) logging.info(r.status_code) logging.debug(r.content)