def vlan_pool_details(base_url, cookies, physdom): # vlan_pool_template = Template('node/mo/uni/phys-${physdom}.json?query-target=children&target-subtree-class=infraRsVlanNs') # vlan_pool_name = vlan_pool_template.substitute(physdom=physdom) # new_url = url + vlan_pool_name vlan_pool_name_full_url = '{}node/mo/uni/phys-{}.json?query-target=children&target-subtree-class=infraRsVlanNs'.format(base_url,physdom) get_vlan_pool_name = make_get_api_call(vlan_pool_name_full_url, cookies=cookies) vlan_pool = get_vlan_pool_name.text vlan_pool_json = json.loads(vlan_pool) vlan_pool_name = vlan_pool_json['imdata'][0]['infraRsVlanNs']['attributes']['tDn'] # vlan_pool_details_template = Template('node/mo/${vlan_pool_name}.json?query-target=children&target-subtree-class=fvnsEncapBlk') # vlan_pool_details = vlan_pool_details_template.substitute(vlan_pool_name=vlan_pool_name) # new_url = url + vlan_pool_details vlan_pool_details_full_url = '{}node/mo/{}.json?query-target=children&target-subtree-class=fvnsEncapBlk'.format(base_url,vlan_pool_name) get_vlan_pool_details = make_get_api_call(vlan_pool_details_full_url, cookies=cookies) vlan_pool_details = get_vlan_pool_details.text print(vlan_pool_details) vlan_pool_dets = json.loads(vlan_pool_details) from_vlan = vlan_pool_dets['imdata'][0]['fvnsEncapBlk']['attributes']['from'] to_vlan = vlan_pool_dets['imdata'][0]['fvnsEncapBlk']['attributes']['to'] return from_vlan, to_vlan
def find_endpoint(endpoint_ip, url, cookies): endpoints_url = url + "node/class/fvCEp.json?query-target-filter=and(eq(fvCEp.ip, " '"{}"' "))".format( endpoint_ip) output_raw = make_get_api_call(endpoints_url, cookies=cookies) print(endpoints_url) temp1 = str(output_raw.text) temp3 = json.loads(temp1) file_name = '/tmp/endpoint.csv' print(temp3) endpoint = temp3['imdata'][0] dn = endpoint['fvCEp']['attributes']['dn'] ip = endpoint['fvCEp']['attributes']['ip'] mac = endpoint['fvCEp']['attributes']['mac'] encap = endpoint['fvCEp']['attributes']['encap'] reg = '/' dn_list = [] dn_list = dn.split(reg) tenant_name = dn_list[1] ap_profile = dn_list[2] epg = dn_list[3] cep = dn_list[4] expression = r'epg-(.*)' epg1 = re.search(expression, epg) epg_name = epg1.group(1) epg_info = url + "node/class/fvAEPg.json?query-target=children" epg_output_raw = output_raw = make_get_api_call(epg_info, cookies=cookies) temp = epg_output_raw.text temp_dict = json.loads(temp) epg_list = temp_dict['imdata'] mystring = 'uni/{}/{}/{}'.format(tenant_name, ap_profile, epg) cons_list = [] prov_list = [] #Find the consumed & provided contracts for item in epg_list: try: if mystring in item['fvRsProv']['attributes']['dn']: prov_list.append(item) except: continue for item in epg_list: try: if mystring in item['fvRsCons']['attributes']['dn']: cons_list.append(item) except: continue if cons_list: consumed_contract = cons_list[0]['fvRsCons']['attributes'][ 'tnVzBrCPName'] else: consumed_contract = '' if prov_list: provided_contract = prov_list[0]['fvRsProv']['attributes'][ 'tnVzBrCPName'] else: provided_contract = '' return ip, mac, tenant_name, ap_profile, epg_name, consumed_contract, provided_contract
def check_bd_exists(base_url, cookies, tenant_name, bd): bd_url_full = '{}node/mo/uni/tn-{}/BD-{}.json'.format(base_url, tenant_name, bd) bd_exist = make_get_api_call(bd_url_full, cookies=cookies) json_data = json.loads(bd_exist.text) if json_data['imdata'] == []: return False else: return True
def check_tenant_exists(base_url, cookies, tenant_name): tenant_full_url = '{}node/mo/uni/tn-{}.json'.format(base_url, tenant_name) print(tenant_full_url) tenant_exist_response = make_get_api_call(tenant_full_url, cookies=cookies) json_data = json.loads(tenant_exist_response.text) if json_data['imdata'] == []: return False else: return True
def check_epg_exists(base_url, cookies, tenant_name, ap,epg): epg_create_url_full = '{}node/mo/uni/tn-{}/ap-{}/epg-{}.json'.format(base_url,tenant_name,ap,epg) print(epg_create_url_full) epg_exists = make_get_api_call(epg_create_url_full, cookies=cookies) json_data = json.loads(epg_exists.text) if json_data['imdata'] == []: return False else: return True
def check_epg_exists(base_url, cookies, tenant_name, ap, epg): # epg_url_template = Template('node/mo/uni/tn-${tenant_name}/ap-${ap_name}/epg-${epg_name}.json') # epg_url = epg_url_template.substitute(tenant_name=tenant_name, ap_name=ap, epg_name=epg) # new_url = url + epg_url epg_url_template_full = '{}node/mo/uni/tn-{}/ap-{}/epg-{}.json'.format(base_url,tenant_name,ap,epg) print(epg_url_template_full) epg_exists = make_get_api_call(epg_url_template_full, cookies=cookies) json_data = json.loads(epg_exists.text) if json_data['imdata'] == []: return False else: return True
def check_tenant_exists(base_url, cookies, tenant_name): # tenant_url_template=Template('node/mo/uni/tn-${tenant_name}.json') # tenant_url=tenant_url_template.substitute(tenant_name=tenant_name) # new_url=url + tenant_url tenant_url_full = '{}node/mo/uni/tn-{}.json'.format(base_url, tenant_name) tenant_exists = make_get_api_call(tenant_url_full, cookies=cookies) json_data = json.loads(tenant_exists.text) if json_data['imdata'] == []: return False else: return True
def check_bd_exists(base_url, cookies, tenant_name, bd): # bd_url_template = Template('node/mo/uni/tn-${tenant_name}/BD-${bd_name}.json') # bd_url = bd_url_template.substitute(tenant_name=tenant_name, bd_name=bd) # new_url = url + bd_url # # bd_exists = requests.get(url=new_url, cookies=cookies, verify=False) bd_url_full = '{}node/mo/uni/tn-{}/BD-{}.json'.format(base_url, tenant_name, bd) bd_exist = make_get_api_call(bd_url_full, cookies=cookies) json_data = json.loads(bd_exist.text) if json_data['imdata'] == []: return False else: return True
def check_tenant_exists(base_url, cookies, tenant_name): # tenant_url_template=Template('node/mo/uni/tn-${tenant_name}.json') # tenant_url = tenant_url_template.substitute(tenant_name=tenant_name) # new_url = url + tenant_url # tenant_exists = requests.get(url=new_url, cookies=cookies, verify=False) tenant_full_url = '{}node/mo/uni/tn-{}.json'.format(base_url, tenant_name) print(tenant_full_url) tenant_exist_response = make_get_api_call(tenant_full_url, cookies=cookies) json_data = json.loads(tenant_exist_response.text) if json_data['imdata'] == []: return False else: return True