import re if len(sys.argv) < 2: print(f'usage python {sys.argv[0]} fabric-name [net-prefix]') sys.exit() fabricName = sys.argv[1] if len(sys.argv) == 3: netPrefix = str(sys.argv[2]) username = dcnm_credentials.username password = dcnm_credentials.password url = 'https://' + dcnm_credentials.node_ip dcnm_token = dcnm_auth.auth(url,username,password) headers = {'Dcnm-Token': dcnm_token, 'Content-Type': 'application/json'} po_list = dcnm_modules.get_port_channels(fabricName) #print(po_list) payload_list =[] for item in po_list: if len(item['attached_net']) == 0 and int(item['vpc_id']) != 0: sr_no = re.split('~',item['vpc_pair_serial_no']) serialNum = f"{sr_no[0]}~{sr_no[1]}" payload =[{ 'ifName': item['vpc_name'], 'serialNumber': serialNum }] payload_list.append(json.dumps(payload)) elif len(sys.argv) == 3: for net in item['attached_net']: if net.lower()[:3] == netPrefix.lower()[:3]: sr_no = re.split('~', item['vpc_pair_serial_no'])
#!/usr/bin/python # Author Ahamed Sadayan import dcnm_modules import sys import pprint if len(sys.argv) < 2: print( f'usage python {sys.argv[0]} fabric-name [network_numers] # 0 means no network attached to interface' ) sys.exit() fabricName = sys.argv[1] if len(sys.argv) == 3: number_of_networks = int(sys.argv[2]) else: number_of_networks = -1 po_list = dcnm_modules.get_port_channels(fabricName, number_of_networks) pprint.pprint(po_list)