Ejemplo n.º 1
0
def get_port_channels(fabricName,attached_net_len = -1):
    from dcnm_modules import get_switch_role
    from dcnm_modules import get_leaf_nodes
    leaf_nodes = get_leaf_nodes(fabricName)
    leafs_serial = []
    for i in leaf_nodes:
        leafs_serial.append(i['serial_no'])
    username = dcnm_credentials.username
    password = dcnm_credentials.password
    url = 'https://' + dcnm_credentials.node_ip
    posturl = url + f'/rest/control/fabrics/{fabricName}'
    dcnm_token = dcnm_auth.auth(url, username, password)
    headers = {'Dcnm-Token': dcnm_token, 'Content-Type': 'application/json'}
    response1 = requests.get(posturl, verify=False, headers=headers)
    fabric = json.loads(response1.text)
    fabric_id = fabric['id']
    posturl = url + f'/rest/globalInterface/?navId={fabric_id}'
    headers = {'Dcnm-Token': dcnm_token, 'Content-Type': 'application/json'}
    response = requests.get(posturl, verify=False, headers=headers)
    po_list = []
    attached_net =[]
    po_list_per_attached_net = []
    if response.status_code == 200:
        output = json.loads(response.text)
        #pprint.pprint(output)
        print('Checking all the interface types in the fabric..')
        for item in output:
            if item['serialNo'] in leafs_serial and  item['underlayPoliciesStr'] != None and item['ifType'].upper() == 'INTERFACE_PORT_CHANNEL':
                po_type = re.findall('vpc_peer_link',item['underlayPoliciesStr'])
                if len(po_type) > 0:
                    peer_link = True
                else:
                    peer_link = False
                    port_channel = {'leaf': item['sysName'], 'serial_no': item['serialNo'],
                                    'vpc_id': item['vpcId'], 'po_name': item['underlayPolicies'][0]['entityName'],
                                    'source': item['underlayPolicies'][0]['source'],
                                    'po_member_list': item['portChannelMemberList'],
                                    'vpc_pair_serial_no': item['vpcEntityId'], 'vrf': item['vrf'],
                                    'vpc_name': item['underlayPolicies'][0]['source'],
                                    'if_type': item['ifType'],'interfaceDbId': item['interfaceDbId'],
                                    'po_policy': item['underlayPoliciesStr']
                                    }
                    if len(item['overlayNetwork']) > 0:
                        for net in item['overlayNetwork']:
                            attached_net.append(net['templateName'])
                        port_channel['attached_net'] = attached_net
                    else:
                        port_channel['attached_net'] = []

                    po_list.append(port_channel)
    if attached_net_len == -1:
        #pprint.pprint(po_list)
        return po_list
    elif attached_net_len >= 0:
        for po in po_list:
            if len(po['attached_net']) == attached_net_len:
                po_list_per_attached_net.append(po)
        return po_list_per_attached_net
Ejemplo n.º 2
0
if len(sys.argv) < 3:
    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'],
Ejemplo n.º 3
0
intf = re.split(',',intf_range)
int_per_chnl_list = []
intf_count = 0
intfChnl = ''
#print(intf_range)
for interface in intf:
    intfChnl += f'{interface},'
    intf_count += 1
    if intf_count == int(intf_per_chnl):
        int_per_chnl_list.append(intfChnl[:-1])
        intfChnl = ''
        intf_count = 0


print(int_per_chnl_list)
port_channel_all_nodes = dcnm_modules.get_leaf_nodes(fabricName)

if port_channel_type == 'trunk':
    port_channel_dict = port_channel_template.trunk
elif port_channel_type == 'access':
    port_channel_dict = port_channel_template.access
elif port_channel_type == 'dot1qtunnel':
    port_channel_dict = port_channel_template.dot1qtunnel
elif port_channel_type == 'routed':
    port_channel_dict = port_channel_template.routed_chnl
    vrf = input('Please enter the vrf name for the routed port channel: default if there is no vrf:')
    ip_add = input('Please enter the starting ipv4/ipv6 address for the routed port channel:')
    mask = input('Please enter ipv4/ipv6 address prefix length:')
    ip_address = ipaddress.ip_address(ip_add)