reworked configfile parsing and setting of JSON
This commit is contained in:
parent
8dccb11da5
commit
af1fc945e2
|
@ -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",
|
||||
|
|
|
@ -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",
|
||||
|
|
49
push.py
49
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
|
||||
|
||||
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 and 'group' in globals():
|
||||
|
||||
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 and 'billingtags' in globals():
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue