def main():
    """
    Main subscribe tenants routine
    :return: None
    """
    # Take login credentials from the command line if provided
    # Otherwise, take them from your environment variables file ~/.profile
    description = ('Simple application using event subscription for the'
                   'Tenant class. When run, this application will log '
                   'into the APIC and subscribe to events on the Tenant '
                   'class.  If a new tenant is created, the event will be'
                   'printed on the screen. Likewise, if an existing tenant'
                   'is deleted.')
    creds = aci.Credentials('apic', description)
    args = creds.get()

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

    aci.Tenant.subscribe(session)

    while True:
        if aci.Tenant.has_events(session):
            tenant = aci.Tenant.get_event(session)
            if tenant.is_deleted():
                print('Tenant', tenant.name, 'has been deleted.')
            else:
                print('Tenant', tenant.name, 'has been created or modified.')
Exemple #2
0
def main():
    description = 'Simple application that logs on to the APIC and displays stats for all of the Interfaces.'
    creds = ACI.Credentials('apic', description)
    # group = creds.add_mutually_exclusive_group()
    group1 = creds.add_argument_group('Export', 'Export a cable plan')
    group1.add_argument('-e', '--export_file', default=None, const='export text', dest='export_file', nargs='?',
                        help='Export cableplan from running fabric.  If EXPORT_FILE is specified, the '
                             'cableplan will be written to EXPORT_FILE')
    group2 = creds.add_argument_group('Compare', 'Compare cable plans')
    group2.add_argument('-c1', '--cableplan1',
                        type=str, nargs=1,
                        default=None,
                        help="Name of cableplan xml file.  If only CABLEPLAN1 is specified, "
                             "it will be compared to the running fabric.  If it is specified with "
                             "CABLEPLAN2 (the -c2 option), then it will compare CABLEPLAN1 with CABLEPLAN2")
    group2.add_argument('-c2', '--cableplan2',
                        type=str, nargs=1,
                        default=None,
                        help="Name of second cableplan xml file.  The second cableplan file.  This file will "
                             "be compared to CABLEPLAN1.  This option must only be used "
                             "in conjunction with the -c1 option.")

    args = creds.get()

    session = ACI.Session(args.url, args.login, args.password)

    if args.export_file and (args.cableplan1 or args.cableplan2):
        creds.print_help()
        print '\nError: export and compare operations are mutually exclusive'
        exit()

    if args.cableplan2 and not args.cableplan1:
        creds.print_help()
        print '\nError: -c2 option only valid with -c1 option'
        exit()

    if not args.export_file and not args.cableplan1:
        creds.print_help()
        print '\nError: Either export (-e) or compare (-c1) is required'
        exit()

    if args.export_file:
        if args.export_file == 'export text':
            export_to_file(session)
        else:
            export_to_file(session, args.export_file)

    if args.cableplan1:
        if args.cableplan2:
            compare_cable_plans(session, args.cableplan1[0], args.cableplan2[0])
        else:
            compare_cable_plans(session, args.cableplan1[0])
Exemple #3
0
def main():
    """
    Main execution routine
    """
    description = ('Simple application that logs on to the APIC'
                   ' and displays all the faults. If tenant name is given, '
                   ' shows the faults associated with that tenant')
    creds = ACI.Credentials('apic', description)
    creds.add_argument(
        "-t",
        "--tenant_name",
        help="name of the tenant of which faults are to be displayed")
    creds.add_argument('--continuous',
                       action='store_true',
                       help='Continuously monitor for tenant faults')
    args = creds.get()

    # Login to APIC
    session = ACI.Session(args.url, args.login, args.password)
    resp = session.login()
    if not resp.ok:
        print('%% Could not login to APIC')
        return
    if args.tenant_name is not None:
        tenant_name = args.tenant_name
    else:
        tenant_name = None

    faults_obj = Faults()
    faults_obj.subscribe_faults(session)
    while faults_obj.has_faults(session) or args.continuous:
        if faults_obj.has_faults(session):
            faults = faults_obj.get_faults(session, tenant_name=tenant_name)
            if faults is not None:
                for fault in faults:
                    if fault is not None:
                        print("****************")
                        if fault.descr is not None:
                            print("     descr     : " + fault.descr)
                        else:
                            print("     descr     : " + "  ")
                        print("     dn        : " + fault.dn)
                        print("     rule      : " + fault.rule)
                        print("     severity  : " + fault.severity)
                        print("     type      : " + fault.type)
                        print("     domain    : " + fault.domain)
Exemple #4
0
def main():
    """
    Main execution path when run from the command line
    """
    # Get all the arguments
    description = 'Configuration Snapshot and Rollback tool for APIC. v0.2'
    creds = ACI.Credentials('apic', description)
    commands = creds.add_mutually_exclusive_group()
    commands.add_argument('-s',
                          '--snapshot',
                          action='store_true',
                          help='Take a snapshot of the APIC configuration')
    commands.add_argument('-ls',
                          '--list-snapshots',
                          action='store_true',
                          help='List all of the available snapshots')
    help_txt = ('Configuration file responses include all properties of'
                ' the returned managed objects.')
    creds.add_argument('-a',
                       '--all-properties',
                       action='store_true',
                       default=False,
                       help=help_txt)
    help_txt = ('Configuration snapshot using the method available in v0.1.')
    creds.add_argument('--v1',
                       action='store_true',
                       default=False,
                       help=help_txt)
    help_txt = 'List all of the available configuration files.'
    commands.add_argument('-lc',
                          '--list-configfiles',
                          nargs='*',
                          metavar=('VERSION'),
                          default=None,
                          help=help_txt)
    help_txt = ('Rollback the configuration to the specified version.'
                ' Optionally only for certain configuration files.')
    commands.add_argument('--rollback',
                          nargs='+',
                          metavar=('VERSION'),
                          help=help_txt)
    help_txt = ('Show the contents of a particular configfile'
                ' from a particular snapshot version.')
    commands.add_argument('--show',
                          nargs=2,
                          metavar=('VERSION', 'CONFIGFILE'),
                          help=help_txt)
    args = creds.get()

    cdb = ConfigDB()
    try:
        resp = cdb.login(args)
        if not resp.ok:
            print '%% Could not login to APIC'
            sys.exit(0)
    except (Timeout, ConnectionError):
        print '%% Could not login to APIC'
        sys.exit(0)
    if args.list_configfiles is not None:
        if len(args.list_configfiles):
            version = args.list_configfiles[0]
            cdb.print_filenames(version)
        else:
            versions = cdb.get_versions()
            if len(versions):
                cdb.print_filenames(versions[-1])
    elif args.list_snapshots:
        cdb.print_versions()
    elif args.snapshot:
        if args.all_properties:
            cdb.rsp_prop_include = 'all'
        if args.v1:
            cdb.take_snapshot()
        else:
            cdb.take_snapshot_using_export_policy()
    elif args.rollback is not None:
        version = args.rollback[0]
        cdb.rollback_using_import_policy(version)
    elif args.show is not None:
        version = args.show[0]
        filename = args.show[1]
        config = cdb.get_file(version, filename)
        print config
################################################################################
"""
Simple application that logs on to the APIC and displays all
of the Interfaces.
"""
import datetime
from operator import attrgetter
import sys

# noinspection PyPep8Naming
import acitoolkit as ACI

# 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 APIC and displays reports for the switches.'
creds = ACI.Credentials('apic, nosnapshotfiles', description)
creds.add_argument('-s',
                   '--switch',
                   type=str,
                   default=None,
                   help='Specify a particular switch id, e.g. "102"')
creds.add_argument('-all',
                   action="store_true",
                   help='Show all detailed information')
creds.add_argument('-basic',
                   action="store_true",
                   help='Show basic switch info')
creds.add_argument('-linecard', action="store_true", help='Show Lincard info')
creds.add_argument('-supervisor',
                   action="store_true",
                   help='Show Supervisor Card info')
################################################################################
"""
Simple application that logs on to the APIC and displays all
of the Interfaces.
"""
import datetime
from operator import attrgetter
import sys

# noinspection PyPep8Naming
import acitoolkit as ACI

# 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 APIC and displays reports for the switches.'
creds = ACI.Credentials('apic', description)
creds.add_argument('-s',
                   '--switch',
                   type=str,
                   default=None,
                   help='Specify a particular switch id, e.g. "102"')
creds.add_argument('-all',
                   action="store_true",
                   help='Show all detailed information')
creds.add_argument('-basic',
                   action="store_true",
                   help='Show basic switch info')
creds.add_argument('-linecard', action="store_true", help='Show Lincard info')
creds.add_argument('-supervisor',
                   action="store_true",
                   help='Show Supervisor Card info')