Ejemplo n.º 1
0
def main():
    """
    Main execution routine

    :return: None
    """
    # Take login credentials from the command line if provided
    # Otherwise, take them from your environment variables file ~/.profile
    description = 'create port channel and attach interface'
    creds = NX.Credentials('switch', description)
    args = creds.get()

    # Login to Switch
    session = NX.Session(args.url, args.login, args.password)
    resp = session.login()
    if not resp.ok:
        print('%% Could not login to Switch')
        sys.exit(0)

    # ConfigInterfaces instance is required to configure multiple port
    # channel at a time
    config = NX.ConfigInterfaces()

    # Create a POrtChannels object
    pc1 = NX.PortChannel('444')
    pc2 = NX.PortChannel('445')

    int1 = NX.Interface('eth1/5')
    int2 = NX.Interface('eth1/8')
    int3 = NX.Interface('eth1/9')

    # Attach interfaces to the port channel
    pc1.attach(int1)
    pc1.attach(int2)
    pc2.attach(int3)

    # Add port channels to the config object
    config.add_port_channel(pc1)
    config.add_port_channel(pc2)

    print config.get_json()

    # Push/ create the port channel object to the switch
    # Note: To configure only single port channel use pc1.get_url() and
    # pc1.get_json() instead of config.get_url() and config.get_json()
    resp = session.push_to_switch(config.get_url(), config.get_json())
    if not resp.ok:
        print('%% Could not push to Switch: %s' % (resp.text))
        sys.exit(0)
Ejemplo n.º 2
0
def main():
    """
    Main execution routine

    :return: None
    """
    # Take login credentials from the command line if provided
    # Otherwise, take them from your environment variables file ~/.profile
    description = '''Simple application that logs on to the Switch and 
                configure ipv6 on the Interfaces.'''
    creds = NX.Credentials('switch', description)
    args = creds.get()

    # Login to Switch
    session = NX.Session(args.url, args.login, args.password)
    resp = session.login()
    if not resp.ok:
        print('%% Could not login to Switch')
        sys.exit(0)

    # Creating interface objects
    # Note: interfaces should be L3 interface
    int1 = NX.Interface('eth1/20')

    # Create a L3 port channel
    pc1 = NX.PortChannel('211', layer='Layer3')

    # Create the port channel in the switch
    # Note:(port channel should be exist in the switch before
    # assigning IPv6 to it)
    resp = session.push_to_switch(pc1.get_url(), pc1.get_json())
    if not resp.ok:
        print('%% Could create port channel in the Switch')
        print resp.text
        sys.exit(0)

    ipv6 = NX.IP('v6')

    # Add interfaces
    ipv6.add_interface_address(int1, '2004:0DB8::1/10', link_local='FE83::1')

    # Add port channel
    ipv6.add_interface_address(pc1, '2022:0DB8::1/13')

    # Configure IPv6 route and Nexthop information
    r1 = NX.IPRoute('2000:0::0/12', version='v6')
    r1.add_next_hop('234E:44::1', int1, vrf='default', track_id='0', tag='1')
    r1.add_next_hop('234E:44::4', pc1, vrf='default', track_id='1', tag='2')

    # Add route to IPv6
    ipv6.add_route(r1)

    print ipv6.get_url()
    print ipv6.get_json()
    resp = session.push_to_switch(ipv6.get_url(), ipv6.get_json())
    if not resp.ok:
        print('%% Could not push to Switch')
        print resp.text
        sys.exit(0)

    # Uncomment below to delete the resources
    '''
Ejemplo n.º 3
0
def main():
    """
    Main execution routine

    :return: None
    """
    # Take login credentials from the command line if provided
    # Otherwise, take them from your environment variables file ~/.profile
    description = '''Simple application that logs on to the Switch and 
                configure ipv4 on the Interfaces.'''
    creds = NX.Credentials('switch', description)
    args = creds.get()

    # Login to Switch
    session = NX.Session(args.url, args.login, args.password)
    resp = session.login()
    if not resp.ok:
        print('%% Could not login to Switch')
        sys.exit(0)

    # Creating interface objects
    # Note: interfaces should be L3 interface
    int1 = NX.Interface('eth1/20')

    # Create a L3 port channel
    pc1 = NX.PortChannel('211', layer='Layer3')

    # Create the port channel in the switch
    # Note:(port channel should be exist in the switch before
    # assigning IPv6 to it)
    resp = session.push_to_switch(pc1.get_url(), pc1.get_json())
    if not resp.ok:
        print('%% Could create port channel in the Switch')
        print resp.text
        sys.exit(0)

    # Create IPv4 instance
    ipv4 = NX.IP()

    # Enable ip directed broadcast on the interface
    ipv4.enable_directed_broadcast(int1)

    # Add interfaces
    ipv4.add_interface_address(int1, '1.1.1.1/20')

    # Add port channel
    ipv4.add_interface_address(pc1, '3.3.3.211/13')

    # Configure IPv4 route and Nexthop information
    r1 = NX.IPRoute('4.4.4.4/32')
    r1.add_next_hop('5.5.5.5', int1, vrf='default', track_id='0', tag='1')
    r1.add_next_hop('7.7.7.7', pc1, vrf='default', track_id='1', tag='2')

    # Add route to IPv4
    ipv4.add_route(r1)

    print ipv4.get_url()
    print ipv4.get_json()
    resp = session.push_to_switch(ipv4.get_url(), ipv4.get_json())
    if not resp.ok:
        print('%% Could not push to Switch.')
        print resp.text
        sys.exit(0)

    # Uncomment below to delete the resources
    '''