prettying up debug scripts
This commit is contained in:
parent
63485d65eb
commit
649a092071
|
@ -8,10 +8,29 @@ import time
|
|||
import logging
|
||||
import requests
|
||||
import configparser
|
||||
import argparse
|
||||
|
||||
# Parse all arguments
|
||||
parser = argparse.ArgumentParser(description="Push JSON connfig to AlkirAPI")
|
||||
parser.add_argument("-t", "--tenant", type=str, default='alkira.cnf', help="location of alikira.cnf (default: alkira.cnf")
|
||||
parser.add_argument("-f", "--file", type=str, help="location of the JSON connector file")
|
||||
parser.add_argument("-p", "--pretty", help="make the JSON pretty!", action="store_true")
|
||||
if len(sys.argv)==1:
|
||||
parser.print_help(sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
args = parser.parse_args()
|
||||
ALKIRA_CONFIG = args.tenant
|
||||
json_file = args.file
|
||||
|
||||
except argparse.ArgumentError as e:
|
||||
print(str(e))
|
||||
sys.exit()
|
||||
|
||||
###############################################
|
||||
|
||||
ALKIRA_CONFIG= "/Users/mischa/Alkira/xDev/alkira.cnf"
|
||||
# Tenant config
|
||||
if not os.path.isfile(ALKIRA_CONFIG):
|
||||
logging.error(f"The config file {ALKIRA_CONFIG} doesn't exist")
|
||||
sys.exit(1)
|
||||
|
@ -44,12 +63,21 @@ tenantName = data[0]['name']
|
|||
logging.info(f'Tenant Name: {tenantName}')
|
||||
logging.info(f'Tenant ID: {tenantNetworkId}')
|
||||
|
||||
print(json_file)
|
||||
|
||||
# Do Things
|
||||
with open ('config/panfwservices1.txt', 'r') as f:
|
||||
connector_result = re.match(r'(.*)\/?(\w+)(\d+)', json_file)
|
||||
connector_name = connector_result.group(1)
|
||||
connector_number = connector_result.group(2)
|
||||
|
||||
with open (json_file, 'r') as f:
|
||||
body = json.load(f)
|
||||
print(json.dumps(body, indent=4))
|
||||
print(json.dumps(body))
|
||||
url = f'{ALKIRA_BASE_URI}/tenantnetworks/{tenantNetworkId}/panfwservices'
|
||||
if args.pretty:
|
||||
print(json.dumps(body, indent=4))
|
||||
else:
|
||||
print(json.dumps(body))
|
||||
|
||||
url = f'{ALKIRA_BASE_URI}/tenantnetworks/{tenantNetworkId}/{connector_name}'
|
||||
response = session.post(url, data=json.dumps(body), headers=headers)
|
||||
print(response.status_code)
|
||||
print(response.content)
|
||||
|
|
|
@ -6,7 +6,7 @@ import argparse
|
|||
|
||||
# Parse all arguments
|
||||
parser = argparse.ArgumentParser(description="Push JSON connfig to AlkirAPI")
|
||||
parser.add_argument("-f", "--file", type=str, help="location of the JSON connector files")
|
||||
parser.add_argument("-f", "--file", type=str, help="location of the JSON connector file")
|
||||
parser.add_argument("-p", "--pretty", help="make the JSON pretty!", action="store_true")
|
||||
if len(sys.argv)==1:
|
||||
parser.print_help(sys.stderr)
|
||||
|
@ -25,4 +25,4 @@ with open (json_file, 'r') as f:
|
|||
if args.pretty:
|
||||
print(json.dumps(body, indent=4))
|
||||
else:
|
||||
print(body)
|
||||
print(json.dumps(body))
|
||||
|
|
Loading…
Reference in New Issue