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.')
Esempio n. 2
0
def main():
    """
    Main show Process routine
    :return: None
    """
    description = 'Simple application that logs on to the APIC and displays process information for a switch'
    creds = Credentials('apic', description)

    creds.add_argument('-s', '--switch',
                       type=str,
                       default=None,
                       help='Specify a particular switch id, e.g. "102"')
    args = creds.get()

    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)

    switches = ACI.Node.get(session, '1', args.switch)
    for switch in switches:
        if switch.role != 'controller':
            processes = ACI.Process.get(session, switch)
            tables = ACI.Process.get_table(processes, 'Process list for Switch ' + switch.name + '::')
            for table in tables:
                print table.get_text(tablefmt='fancy_grid') + '\n'
Esempio n. 3
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])
Esempio n. 4
0
    def login(self, args, timeout=2):
        """
        Login to the APIC

        :param args: An instance containing the APIC credentials.  Expected to
                     have the following instance variables; url, login, and
                     password.
        :param timeout:  Optional integer argument that indicates the timeout
                         value in seconds to use for APIC communication.
                         Default value is 2.
        :returns: Instance of Requests Response indicating the connection
                  status
        """
        self.session = ACI.Session(args.url, args.login, args.password)

        resp = self.session.login(timeout)
        return resp
Esempio n. 5
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)
Esempio n. 6
0
 def session(self):
     """
     session property will return an active session that has been logged in
     If a login had not previously occurred, it will proactively login first.
     :return: Session
     """
     if self._session is None:
         if self.args is not None:
             if self.args.login is not None:
                 self._session = ACI.Session(self.args.url, self.args.login,
                                             self.args.password)
                 resp = self.session.login(self.timeout)
             else:
                 raise LoginError
         else:
             raise LoginError
         if not resp.ok:
             raise LoginError
     return self._session
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')

    # Login to APIC
    session = ACI.Session(URL, LOGIN, 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):
        if faults_obj.has_faults(session):
            faults = faults_obj.get_faults(session)
            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("     code      : " +
                              fault.dn.split('fault-', 1)[1])
                        print("     dn        : " + fault.dn)
                        print("     rule      : " + fault.rule)
                        print("     severity  : " + fault.severity)
                        print("     type      : " + fault.type)
                        print("     domain    : " + fault.domain)
                        fault_code = fault.dn.split('fault-', 1)[1]
                        post_message_to_spark("{}\n {}".format(
                            fault_code, fault.descr))
def main():
    """
    Main execution routine
    """
    description = ('Simple application that logs on to the APIC'
                   ' and displays all the events. If tenant name is given, '
                   ' shows the events associated with that tenant')

    # Login to APIC
    session = ACI.Session(URL, LOGIN, 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

    #events_obj = ACI.Interface()
    events_obj = ACI.Interface.subscribe(session)
    while ACI.Interface.has_events(session):
        if ACI.Interface.has_events(session):
            events = ACI.Interface.get_event(session)
            if events is not None:
                for event in events:
                    if event is not None:
                        print("****************")
                        if event.descr is not None:
                            print("     descr     : " + event.descr)
                        else:

                            print("     descr     : " + "  ")
                        print("     code      : " +
                              event.dn.split('event-', 1)[1])
                        print("     dn        : " + event.dn)
                        print("     rule      : " + event.rule)
                        print("     severity  : " + event.severity)
                        print("     type      : " + event.type)
                        print("     domain    : " + event.domain)
                        fault_code = event.dn.split('event-', 1)[1]
Esempio n. 9
0
def main():
    """
    Main show Process routine
    :return: None
    """
    description = 'Simple application that logs on to the APIC and check cluster information for a fabric'
    creds = Credentials('apic', description)

    args = creds.get()

    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)

    cluster = ACI.Cluster('Cluster')
    configured_size = cluster.get_config_size(session)
    cluster_size = cluster.get_cluster_size(session)
    cluster_info = cluster.get_cluster_info(session)

    if configured_size != cluster_size:
        print("*******************************************************")
        sys.stdout.write("WARNING, configured cluster size ")
        sys.stdout.write(configured_size)
        sys.stdout.write(" :not equal to the actual size ")
        print cluster_size
        print "WARNING, desired stats collection might be lost"
        print("*******************************************************")
        print("APICs in the cluster are:")
        for apic in cluster_info:
            print json.dumps(apic['infraCont']['attributes']['dn'],
                             indent=4,
                             sort_keys=True)
    else:
        print("PASS")
Esempio n. 10
0
#!/usr/bin/env python
"""
Simple application that logs on to the APIC and displays all
EPGs.  Before running, please make sure that the credentials.py
file has the URL, LOGIN, and PASSWORD set for your APIC environment.
"""
import acitoolkit as ACI
import credentials

# Login to APIC
session = ACI.Session(credentials.URL, credentials.LOGIN, credentials.PASSWORD)
resp = session.login()
if not resp.ok:
    print '%% Could not login to APIC'

# Download all of the tenants, app profiles, and EPGs
# and store the names as tuples in a list
data = []
tenants = ACI.Tenant.get(session)
for tenant in tenants:
    apps = ACI.AppProfile.get(session, tenant)
    for app in apps:
        epgs = ACI.EPG.get(session, app, tenant)
        for epg in epgs:
            data.append((tenant.name, app.name, epg.name))

# Display the data downloaded
template = "{0:19} {1:20} {2:15}"
print template.format("TENANT", "APP_PROFILE", "EPG")
print template.format("------", "-----------", "---")
for rec in data:
Esempio n. 11
0
creds.add_argument('-endpoint',
                   action="store_true",
                   help='Show End Point info')
creds.add_argument('-portchannel',
                   action="store_true",
                   help='Show Port Channel and Virtual Port Channel info')
creds.add_argument('-overlay', action="store_true", help='Show Overlay info')
creds.add_argument('-tablefmt',
                   type=str,
                   default='fancy_grid',
                   help='Table format [fancy_grid, plain, simple, grid, '
                   'pipe, orgtbl, rst, mediawiki, latex, latex_booktabs]')
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)


def show_switch_short(switch_id, table_format):
    """
    Setup template and display header information for summary version of switch info

    :param table_format: The format to be used when rendering the table
    :param switch_id: Optional switch Id to select a specific switch.  If ommitted, will be all switches.
    """

    if switch_id:
Esempio n. 12
0
def main():
    session = acitoolkit.Session(URL, LOGIN, PASSWORD)
    session.login()
    subscribe_to_events(session)