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 = '''Simple application that logs on to the Switch
                    and configure SVI.'''
    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)

    # Create ConfigureInterfaces to do multiple SVI configuration at a time
    config = NX.ConfigInterfaces()

    # Create SVI objects providing vlans
    svi1 = NX.SVI('vlan33')
    svi2 = NX.SVI('vlan44')

    # Add svis to the config
    config.add_svis(svi1)
    config.add_svis(svi2)

    # Push entire configuration to the switch
    # Note: Using svi1.get_url() and svi1.get_json() only one svi
    # configuration can be pushed to the switch
    resp = session.push_to_switch(config.get_url(), config.get_json())
    if not resp.ok:
        print('%% Could not login to Switch')
        print resp.text
        sys.exit(0)

    data = []
    svis = NX.SVI.get(session)
    for svi in svis:
        data.append((svi.id, svi.admin_st, svi.bw, svi.mtu, svi.descr))

    # Display the data downloaded (Uncomment below
    # lines to get the configured SVI)
    template = "{0:15} {1:15} {2:15} {3:15} {4:40}"
    print(
        template.format("  ID     ", " ADMIN ", " BANDWIDTH ", " MTU   ",
                        "  DESCR."))
    print(
        template.format("---------", "-------", "-----------", "------ ",
                        "--------"))
    for rec in data:
        print(template.format(*rec))

    # Uncomment below lines to delete the created svi
    '''
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 = '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.º 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 SVI.'''
    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)

    # Create ConfigureInterfaces to do multiple SVI configuration at a time
    config = NX.ConfigInterfaces()

    # Create SVI objects providing vlans
    svi1 = NX.SVI('vlan301')

    # Add svis to the config
    config.add_svis(svi1)

    # Push entire configuration to the switch
    # Note: Using svi1.get_url() and svi1.get_json() only one svi
    # configuration can be pushed to the switch

    for id in [svi1]:
        resp = session.delete(svi1.get_delete_url(id))
        if not resp.ok:
            print('%% Could not login to Switch')
            print resp.text
            sys.exit(0)
Ejemplo n.º 4
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 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)

    int1 = NX.Interface('eth1/2')
    int2 = NX.Interface('eth1/3')

    # ConfigInterfacs object is used to configure multiple
    # interfaces at a time (No need of multiple REST calls)
    # Note: Using Interface object also an interface can be configured
    config = NX.ConfigInterfaces()

    # Adding interfaces to be configured
    config.add_interface(int1)
    config.add_interface(int2)

    # Setting interface attributes
    # Note: if attributes are not set, then default values will be used
    int1.set_admin_status('up')
    int1.set_layer('Layer2')
    int1.set_duplex('auto')
    int1.set_link_log('default')
    int1.set_mode('access')
    int1.set_speed('10G')
    int1.set_access_vlan('vlan-300')
    int1.set_trunk_log('default')
    int1.set_link_log('default')
    int1.set_descr('configured by nxtoolkit')

    # Push entire configuration to the switch
    # Note:To configure only one interface use int1.get_url() & int1.get_json()
    resp = session.push_to_switch(config.get_url(), config.get_json())
    if not resp.ok:
        print('%% Could not push to Switch')
        print resp.text
        sys.exit(0)

    ethpm = NX.Ethpm()
    ethpm.set_default_admin_st('up')
    ethpm.set_default_layer('Layer2')
    ethpm.set_jumbomtu('9216')
    ethpm.set_unsupported_transceiver('yes')

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

    # Uncomment below lines to get the configured ethpm
    '''   
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)

    #Ensure that  port as layer 3 mode
    int1 = NX.Interface('eth1/2')
    int2 = NX.Interface('eth1/3')

    # ConfigInterfacs object is used to configure multiple
    # interfaces at a time (No need of multiple REST calls)
    # Note: Using Interface object also an interface can be configured
    config = NX.ConfigInterfaces()

    # Adding interfaces to be configured
    config.add_interface(int1)
    config.add_interface(int2)

    # Setting interface attributes
    # Note: if attributes are not set, then default values will be used
    int1.set_admin_status('up')
    int1.set_layer('Layer3')


    # Push entire configuration to the switch
    # Note:To configure only one interface use int1.get_url() & int1.get_json()
    resp = session.push_to_switch(config.get_url(), config.get_json())
    if not resp.ok:
        print ('%% Could not push to Switch')
        print resp.text
        sys.exit(0)



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



    # 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, '192.168.60.1/24')

  #  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
    '''