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
# STP Policy if config_line['iface-bpdu-guard'].lower() in [ "enabled", "enable", "y", "yes" ]: iface.stp_bpdu_guard() if config_line['iface-bpdu-filter'].lower() in [ "enabled", "enable", "y", "yes" ]: iface.stp_bpdu_filter() # We are done with this interface. Add it to the list so we can push it # to the fabric later interfaces.append(iface) # Now, we log into the APIC fabric = Fabric(args.url, args.login, args.password) fabric.connect() # First, deploy basic interface policies (CDP_Enabled, LACP_Active, etc) ifpols = InterfacePolicies() print_banner() output("[+] Creating standard interface policies") fabric.push_to_apic(ifpols) # Now push every interface we created earlier for iface in interfaces: output("[+] Creating interface '%s'" % iface.name) fabric.push_to_apic(iface) sys.exit(0)
iface.link(config_line['iface-speed'], False) else: warning("[W] Unexpected Link Speed negotation policy (%s) on interface %s. Setting to 'default'" % (config_line['speed-auto'], config_line['iface-name'])) # STP Policy if config_line['iface-bpdu-guard'].lower() in ["enabled", "enable", "y", "yes"]: iface.stp_bpdu_guard() if config_line['iface-bpdu-filter'].lower() in ["enabled", "enable", "y", "yes"]: iface.stp_bpdu_filter() # We are done with this interface. Add it to the list so we can push it # to the fabric later interfaces.append(iface) # Now, we log into the APIC fabric = Fabric(args.url, args.login, args.password) fabric.connect() # First, deploy basic interface policies (CDP_Enabled, LACP_Active, etc) ifpols = InterfacePolicies() print_banner() output("[+] Creating standard interface policies") fabric.push_to_apic(ifpols) # Now push every interface we created earlier for iface in interfaces: output("[+] Creating interface '%s'" % iface.name) fabric.push_to_apic(iface) sys.exit(0)
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