當前位置: 首頁>>代碼示例>>Python>>正文


Python Credentials.add_argument方法代碼示例

本文整理匯總了Python中acitoolkit.acitoolkit.Credentials.add_argument方法的典型用法代碼示例。如果您正苦於以下問題:Python Credentials.add_argument方法的具體用法?Python Credentials.add_argument怎麽用?Python Credentials.add_argument使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在acitoolkit.acitoolkit.Credentials的用法示例。


在下文中一共展示了Credentials.add_argument方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_interface_stats_from_nodes

# 需要導入模塊: from acitoolkit.acitoolkit import Credentials [as 別名]
# 或者: from acitoolkit.acitoolkit.Credentials import add_argument [as 別名]
def get_interface_stats_from_nodes():
    """
    Main execution routine

    :return: None
    """
    description = ('get_stats - A program to fetch statistics from an ACI '
                   'Fabric.')
    creds = Credentials('apic', description)
    creds.add_argument('-f', '--format', required=False, default='text',
                       help='Specify output format [csv, text]')
    creds.add_argument('-i', '--interval', required=False, default='15min',
                       help='Specify the aggregation interval')
    creds.add_argument('-n', '--node_type', required=False, default='spine',
                       help='Specify the type of node [spine, leaf, both]')
    creds.add_argument('-t', '--threshold', required=False, default=60,
                       type=int,
                       help='Specify the threshold for printing usage.')
    creds.add_argument('-v', '--verbose', action='count',
                       help='Specify verbosity of debug output.')

    args = creds.get()
    if args.format not in ['text', 'csv']:
        print >> sys.stderr, "Error: Unknown output format: '{}'".format(
            args.format)
        sys.exit(3)
    if args.interval not in ['5min', '15min', '1h', '1d', '1w', '1mo', '1qtr',
                             '1year']:
        print >> sys.stderr, "Error: Unknown interval '{}'".format(
            args.interval)
        sys.exit(4)
    if args.node_type in ['spine', 'leaf']:
        node_type = [args.node_type]
    elif args.node_type in ['both']:
        node_type = ['spine', 'leaf']
    else:
        print >> sys.stderr, "Error: Unknown node type: '{}'".format(
            args.node_type)
        sys.exit(5)
    if args.threshold > 100:
        threshold = 100
    elif args.threshold < 0:
        threshold = 0
    else:
        threshold = args.threshold

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

    statistics = Stats(session, args.format, args.verbose)
    statistics.get_int_traffic(node_type, args.interval, threshold)
開發者ID:datacenter,項目名稱:acitoolkit,代碼行數:57,代碼來源:aci-get-interface-stats-from-nodes.py

示例2: acilint

# 需要導入模塊: from acitoolkit.acitoolkit import Credentials [as 別名]
# 或者: from acitoolkit.acitoolkit.Credentials import add_argument [as 別名]
def acilint():
    """
    Main execution routine

    :return: None
    """
    description = ('acilint - A static configuration analysis tool. '
                   'Checks can be individually disabled by generating'
                   ' and editing a configuration file.  If no config '
                   'file is given, all checks will be run.')
    creds = Credentials('apic', description)
    creds.add_argument('-c', '--configfile', type=argparse.FileType('r'))
    creds.add_argument('-g', '--generateconfigfile',
                       type=argparse.FileType('w'))
    args = creds.get()

    if args.generateconfigfile:
        print 'Generating configuration file....'
        f = args.generateconfigfile
        f.write(('# acilint configuration file\n# Remove or comment out any '
                 'warnings or errors that you no longer wish to see\n'))
        methods = dir(Checker)
        for method in methods:
            if method.startswith(('warning_', 'critical_', 'error_')):
                f.write(method + '\n')
        f.close()
        sys.exit(0)

    methods = []
    if args.configfile:
        f = args.configfile
        for line in f:
            method = line.split('\n')[0]
            if method in dir(Checker) and method.startswith(('warning_', 'error_', 'critical_')):
                methods.append(method)
        f.close()
    else:
        for method in dir(Checker):
            if method.startswith(('warning_', 'error_', 'critical_')):
                methods.append(method)

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

    checker = Checker(session)
    checker.execute(methods)
開發者ID:KarlHarrisSungardAS,項目名稱:acitoolkit,代碼行數:55,代碼來源:acilint.py

示例3: acilint

# 需要導入模塊: from acitoolkit.acitoolkit import Credentials [as 別名]
# 或者: from acitoolkit.acitoolkit.Credentials import add_argument [as 別名]
def acilint():
    """
    Main execution routine

    :return: None
    """
    description = ('acilint - A static configuration analysis tool. '
                   'Checks can be individually disabled by generating'
                   ' and editing a configuration file.  If no config '
                   'file is given, all checks will be run.')
    creds = Credentials('apic', description)
    creds.add_argument('-c', '--configfile', type=argparse.FileType('r'))
    creds.add_argument('-g', '--generateconfigfile',
                       type=argparse.FileType('w'))
    creds.add_argument('-o', '--output', required=False, default='console')
    args = creds.get()
    if args.generateconfigfile:
        print('Generating configuration file....')
        f = args.generateconfigfile
        f.write(('# acilint configuration file\n# Remove or comment out any '
                 'warnings or errors that you no longer wish to see\n'))
        methods = dir(Checker)
        for method in methods:
            if method.startswith(('warning_', 'critical_', 'error_')):
                f.write(method + '\n')
        f.close()
        sys.exit(0)

    methods = []
    if args.configfile:
        f = args.configfile
        for line in f:
            method = line.split('\n')[0]
            if method in dir(Checker) and method.startswith(('warning_', 'error_', 'critical_')):
                methods.append(method)
        f.close()
    else:
        for method in dir(Checker):
            if method.startswith(('warning_', 'error_', 'critical_')):
                methods.append(method)

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

    html = None
    if args.output == 'html':
        print('Creating file lint.html')
        html = open('lint.html', 'w')
        html.write("""
        <table border="2" style="width:100%">
        <tr>
        <th>Severity</th>
        <th>Rule</th>
        <th>Description</th>
        </tr>
        """)

    checker = Checker(session, args.output, html)
    checker.execute(methods)
開發者ID:datacenter,項目名稱:acitoolkit,代碼行數:68,代碼來源:acilint.py

示例4: output

# 需要導入模塊: from acitoolkit.acitoolkit import Credentials [as 別名]
# 或者: from acitoolkit.acitoolkit.Credentials import add_argument [as 別名]
                output("%s:%s was %s" % (key, obj[key]['attributes']['dn'], obj[key]['attributes']['status'])  )


# Start of the execution
if __name__ == "__main__":

    # Argument parsing. We use the ACI toolkit logic here, which tries to
    # retrieve credentials from the following places:
    # 1. Command line options
    # 2. Configuration file called credentials.py
    # 3. Environment variables
    # 4. Interactively querying the user
    # At the end, we should have an object args with all the necessary info.
    description = 'APIC credentials'
    creds = Credentials('apic', description)
    creds.add_argument('-d', "--debug", default=None, help='Enable Debug mode')
    args = creds.get()
    
    # Process all relevant command-line parameters and print our welcome banner
    if args.debug is not None:
        debug_enable()
    print_banner()
    
    # Now, we log into the APIC
    session = Session(args.url, args.login, args.password)
    response = session.login()
    if response.ok is False:
        fatal(response.content)
    else:
        output("Successfully connected to %s" % args.url)
開發者ID:datacenter,項目名稱:aci-vigilante,代碼行數:32,代碼來源:aci-vigilante.py

示例5: output

# 需要導入模塊: from acitoolkit.acitoolkit import Credentials [as 別名]
# 或者: from acitoolkit.acitoolkit.Credentials import add_argument [as 別名]
    output("                                                                   ")
    output("  == A tool to deploy physical configuration on an ACI fabric ==   \n")

# Start of the execution
if __name__ == "__main__":
    
    # Argument parsing. We use the ACI toolkit logic here, which tries to
    # retrieve credentials from the following places:
    # 1. Command line options
    # 2. Configuration file called credentials.py
    # 3. Environment variables
    # 4. Interactively querying the user
    # At the end, we should have an object args with all the necessary info.
    description = 'APIC credentials'
    creds = Credentials('apic', description)
    creds.add_argument('-i', "--input", default=None, help='Input file')
    creds.add_argument('-d', "--debug", default=None, help='Input file')
    args = creds.get()
    
    # Let's check if the user passed all relevant parameters
    if args.input is None:
        fatal("[E] Input filename missing. Please pass it using --input <filename>")
    if args.debug is not None:
        debug_enable()

    # First of all, parse the input file.
    data = parse_spreadsheet(args.input)
    
    interfaces = [] # List of interfaces to push to the fabric
    
    for config_line in data['PortMapping']:        
開發者ID:datacenter,項目名稱:aci-fabric-deploy,代碼行數:33,代碼來源:aci-fabric-deploy.py

示例6: Credentials

# 需要導入模塊: from acitoolkit.acitoolkit import Credentials [as 別名]
# 或者: from acitoolkit.acitoolkit.Credentials import add_argument [as 別名]
# Start of the execution
if __name__ == "__main__":

    items = {"left": {}, "right": {}}

    # Argument parsing. We use the ACI toolkit logic here, which tries to
    # retrieve credentials from the following places:
    # 1. Command line options
    # 2. Configuration file called credentials.py
    # 3. Environment variables
    # 4. Interactively querying the user
    # At the end, we should have an object args with all the necessary info.
    description = "APIC credentials"
    creds = Credentials("apic", description)
    creds.add_argument("-L", "--left", default=None, help="Object on the left")
    creds.add_argument("-R", "--right", default=None, help="Object on the right")
    creds.add_argument("-t", "--type", default=None, help="Object type")
    args = creds.get()

    # Arg validation
    if args.right is None:
        fatal("[E] Right object missing. Please pass it using --right <obj_name>")
    if args.left is None:
        fatal("[E] Left object missing. Please pass it using --left <obj_name>")
    if args.type is None:
        sys.stderr.write("[W] WARNING: No type supplied. Defaulting to 'Tenant'\n")
        args.type = "Tenant"

    # Process the supplied left and right data, according to the supplied type
開發者ID:datacenter,項目名稱:aci-diff,代碼行數:31,代碼來源:aci-diff.py

示例7: run

# 需要導入模塊: from acitoolkit.acitoolkit import Credentials [as 別名]
# 或者: from acitoolkit.acitoolkit.Credentials import add_argument [as 別名]
    def run():
        # Argument parsing. We use the ACI toolkit logic here, which tries to
        # retrieve credentials from the following places:
        # 1. Command line options
        # 2. Configuration file called credentials.py
        # 3. Environment variables
        # 4. Interactively querying the user
        # At the end, we should have an object args with all the necessary info.
        description = "APIC credentials"
        creds = Credentials("apic", description)
        creds.add_argument("-d", "--debug", default=None, help="Enable debug mode")
        creds.add_argument("-A", "--address", default=None, help="Local IP address")
        creds.add_argument("-P", "--port", default=None, help="Local Port for FTP connections")
        creds.add_argument("-K", "--key", default=None, help="ACI encryption key")
        args = creds.get()

        # Print welcome banner
        ACIExport.print_banner()

        # Let's check if the user passed all relevant parameters
        if args.debug is not None:
            debug_enable()
        if args.address is None:
            # If the user didn't pass any IP address, let's figure out what IPs we
            # have configured locally. If it's only one, use it. Otherwise, ask
            # the user interactively to pick one
            candidates = {}
            for iface in netifaces.interfaces():
                for addr in netifaces.ifaddresses(iface):
                    addr_str = netifaces.ifaddresses(iface)[addr][0]["addr"]
                    # Skip IPv6 addresses
                    if addr_str.count(":") > 0:
                        continue
                    # Skip localhost and unassigned addresses
                    elif addr_str == "0.0.0.0" or addr_str == "127.0.0.1":
                        continue
                    # Skip Microsoft auto-assigned addresses
                    elif addr_str.startswith("169.254."):
                        continue
                    else:
                        candidates[addr_str] = addr_str
            output("Please indicate which local IP address should be used (enter its sequence number):")
            for i in range(0, len(candidates)):
                print(" -> [%i] %s" % (i, candidates.keys()[i]))
            answer = -1
            while not (answer >= 0 and answer < len(candidates)):
                try:
                    answer = int(input("$: "))
                except:
                    continue
            args.address = candidates[candidates.keys()[answer]]
            output("Address selected: %s" % args.address)
        if args.port is None:
            args.port = DEFAULT_FTP_PORT
        else:
            args.port = int(args.port)
        if args.key is None:
            args.key = DEFAULT_KEY

        # Now, we log into the APIC
        fabric = Fabric(args.url, args.login, args.password)
        fabric.connect()

        # Instance our FTP server
        ftplistener = FTPListener(addr=args.address, port=args.port)
        ftplistener.daemon = True
        ftplistener.start()

        # Nasty thing: sleep for 1 sec to give enough time to the FTP server to
        # initialize @todo: use decent concurrency control mechanisms
        time.sleep(1)

        # Push config to the fabric
        pols = ConfExportPolicy(addr=args.address, port=args.port, key=args.key)
        fabric.push_to_apic(pols)

        output("Waiting for the ACI fabric to send its configuration export file...")
        while g_do_exit is False:
            time.sleep(1)

        output("File '%s' was successfully received. Closing..." % g_recv_file)

        output("Please make a note of the encryption key: '%s'" % args.key)

        # Finally, stop the server and quit
        ftplistener.stop()

        return True
開發者ID:datacenter,項目名稱:aci-export,代碼行數:90,代碼來源:aci-export.py


注:本文中的acitoolkit.acitoolkit.Credentials.add_argument方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。