clean clean.py

This commit is contained in:
mischa 2022-06-14 21:23:52 +02:00
parent a7583fef3c
commit 9a2d899116
1 changed files with 21 additions and 21 deletions

View File

@ -32,6 +32,14 @@ headers = {'Content-Type': "application/json"}
logging.basicConfig(level=logging.INFO)
logging = logging.getLogger('AlkiraAPI')
# Naming exceptions
service_exceptions = {
"saas": "internet",
"pan": "panfw",
"ftntfw": "ftnt-fw-",
"chkpfw": "chkp-fw-"
}
def alkira_login():
body = {'userName': ALKIRA_USERNAME,
'password': ALKIRA_PASSWORD}
@ -73,60 +81,52 @@ def alkira_delete(session, uri):
s = alkira_login()
logging.debug(s)
ducks = {
"saas": "internet",
"pan": "panfw",
"ftntfw": "ftnt-fw-",
"chkpfw": "chkp-fw-"
}
# Get TenantID
r = alkira_get(s, '/tenantnetworks')
data = r.json()
print('Tenant Name:', data[0]['name'])
print('Tenant ID:', data[0]['id'])
tenantNetworkId = data[0]['id']
tenantName = data[0]['name']
logging.info(f'Tenant Name: {tenantName}')
logging.info(f'Tenant ID: {tenantNetworkId}')
# Clean connectors
logging.info('Checking Connectors')
r = alkira_get(s, f'/tenantnetworks/{tenantNetworkId}/connectors')
data = r.json()
logging.debug(json.dumps(data, indent=4))
for item in data:
#print("ID:", item.get('id'))
#print("Name:", item.get('name'))
#print("Type:", item.get('type'))
name = item.get('name')
connectorId = item.get('id')
type = item.get('type').lower().replace('_', '')
if type in ducks.keys():
type = ducks[type]
if type in service_exceptions.keys():
type = service_exceptions[type]
logging.debug(f'/tenantnetworks/{tenantNetworkId}/{type}connectors/{connectorId}')
logging.info(f'Removing {name}')
r = alkira_delete(s, f'/tenantnetworks/{tenantNetworkId}/{type}connectors/{connectorId}')
logging.info(r.status_code)
# Clean services
logging.info('Checking services')
r = alkira_get(s, f'/tenantnetworks/{tenantNetworkId}/services')
data = r.json()
logging.debug(json.dumps(data, indent=4))
for item in data:
#print("ID:", item.get('id'))
#print("Name:", item.get('name'))
#print("Type:", item.get('type'))
name = item.get('name')
serviceId = item.get('id')
type = item.get('type').lower()
if type in ducks.keys():
type = ducks[type]
if type in service_exceptions.keys():
type = service_exceptions[type]
logging.debug(f'/tenantnetworks/{tenantNetworkId}/{type}services/{serviceId}')
logging.info(f'Removing {name}')
r = alkira_delete(s, f'/tenantnetworks/{tenantNetworkId}/{type}services/{serviceId}')
logging.info(r.status_code)
# Clean Global CIDR
logging.info('Checking Global CIDR')
r = alkira_get(s, f'/tenantnetworks/{tenantNetworkId}/global-cidr-lists')
data = r.json()
logging.debug(json.dumps(data, indent=4))
for item in data:
#print("ID:", item.get('id'))
#print("Name:", item.get('name'))
name = item.get('name')
GlobalCidrListId = item.get('id')
logging.debug(f'/tenantnetworks/{tenantNetworkId}/global-cidr-lists/{GlobalCidrListId}')