print(f'usage python {sys.argv[0]} fabric-name network_prefix') print('Example python dcnm_detach_intf cus') sys.exit() fabricName = sys.argv[1] network_prefix = sys.argv[2] interface = '' username = dcnm_credentials.username password = dcnm_credentials.password url = 'https://' + dcnm_credentials.node_ip posturl = url + f'/rest/top-down/fabrics/{fabricName}/networks/attachments' dcnm_token = dcnm_auth.auth(url,username,password) headers = {'Dcnm-Token': dcnm_token, 'Content-Type': 'application/json'} leaf_nodes = dcnm_modules.get_leaf_nodes(fabricName) network_list = dcnm_modules.network_list(fabricName,'all') payload_list = [] lanattachedlist = [] net_list = [] delete_list= [] for node in leaf_nodes: for network in network_list: if network['network'].lower()[:3] == network_prefix.lower(): net_list.append(network['network']) print(f"Network prefix matched, going to detach interface from network {network['network']}") delete_load = { "scopeType": "Device", "allocatedTo": network['network'], "serialNumber": node['serial_no'], "resourceId": "",
deploy_pair = { 'ifName': interface['ifName'], 'fabricName': fabricName, 'serialNumber' : interface['serialNumber']} deploy_port_channel_list.append(deploy_pair) attach_intf += f'Port-channel{sport_channel},' sport_channel += 1 port_channel_node_list.append((serial_no, peer_serial_no, attach_intf[:-1],f'{this_node}',item['vpc_domain'])) if port_channel_type == 'routed': print('No Network attachments for L3 routed port channel..') sys.exit() print(f'Starting port_channel deployment in the fabric {fabricName}') fetch = 'all' network_list = dcnm_modules.network_list(fabricName, fetch) network_list_prefix = [] port_channel_list = port_channel_node_list print(port_channel_list[0]) for network in network_list: if network['network'].lower()[:3] == network_prefix.lower(): network_list_prefix.append(network) print('Attaching port_channel port-channels to networks..') #pprint.pprint(port_channel_list) #sys.exit() dcnm_modules.attach_port_channel_interface(fabricName,network_list_prefix,port_channel_list) output = dcnm_modules.save_config(fabricName) print(output) output = dcnm_modules.deploy_config(fabricName)