Пример #1
0
 def setUp(self):
     self.logger = Logger()
     self.n_actions = 0
Пример #2
0
 def setUp(self):
     account = Account('sab', '')
     self.queue = Queue(verbose=0, max_threads=1)
     self.logger = Logger()
     self.queue.add_account(account)
Пример #3
0
#!/usr/bin/env python
from Exscript import Queue, Logger
from Exscript.util.log import log_to
from Exscript.util.decorator import autologin
from Exscript.util.file import get_hosts_from_file, get_accounts_from_file
from Exscript.util.report import status, summarize

logger = Logger()  # Logs everything to memory.


@log_to(logger)
@autologin()
def do_something(job, host, conn):
    conn.execute('show ip int brie')


# Read input data.
accounts = get_accounts_from_file('accounts.cfg')
hosts = get_hosts_from_file('hostlist.txt')

# Run do_something on each of the hosts. The given accounts are used
# round-robin. "verbose=0" instructs the queue to not generate any
# output on stdout.
queue = Queue(verbose=5, max_threads=5)
queue.add_account(accounts)  # Adds one or more accounts.
queue.run(hosts, do_something)  # Asynchronously enqueues all hosts.
queue.shutdown()  # Waits until all hosts are completed.

# Print a short report.
print status(logger)
print summarize(logger)
            
            # Send command to router to retrieve second part of VRF configuration
            socket.execute("show running-config | section SMVPN "+routeDistinguisher+" ")
            outputFile.write(socket.response)   # Write contents of running config to output file
        
            socket.send("exit\r")   # Send the "exit" command to log out of router gracefully
            socket.close()          # Close SSH connection

        # Exception: outputFile file could not be opened
        except IOError:
            print
            print "--> An error occurred opening "+outputFile+"."    

    print "--> "+vrfName+" backed up to "+outputFilename+"."

logger = Logger()   # Log stuff
@log_to(logger)     # Logging decorator; Must precede buildIndex!
@autologin()        # Exscript login decorator; Must precede buildIndex!
def buildIndex(job, host, socket):
# This function builds the index file by connecting to the router and extracting all
# matching sections.  I chose to search for "crypto keyring" because it is the only
# portion of a VPN config that contains the VRF name AND Peer IP.  Caveat is that
# the program temporarily captures the pre-shared key.  "crypto isakmp profile" was not
# a suitable query due to the possibility of multiple "match identity address" statements

    stdout.write(".")                   # Write period without trailing newline
    socket.execute("terminal length 0") # Disable user-prompt to page through config
                                        # Exscript doesn't always recognize Cisco IOS
                                        # for socket.autoinit() to work correctly

    # Send command to router to capture results
Пример #5
0
#!/usr/bin/env python
from Exscript                import Queue, Logger
from Exscript.util.decorator import autologin
from Exscript.util.file      import get_hosts_from_file, get_accounts_from_file
from Exscript.util.report    import status, summarize

@autologin
def do_something(conn):
    conn.execute('show ip int brie')

# Read input data.
accounts = get_accounts_from_file('accounts.cfg')
hosts    = get_hosts_from_file('hostlist.txt')

# Run do_something on each of the hosts. The given accounts are used
# round-robin. "verbose = 0" instructs the queue to not generate any
# output on stdout. Using "logdir = ..." is equivalent to the following:
#   logger = FileLogger(queue, 'my/logdir')
# It instructs the queue to automatically log everything to the filesystem;
# one file is created per host.
queue  = Queue(verbose = 0, max_threads = 5, logdir = 'my/logdir/')
logger = Logger(queue)          # Logs everything to memory.
queue.add_account(accounts)     # Adds one or more accounts.
queue.run(hosts, do_something)  # Asynchronously enqueues all hosts.
queue.shutdown()                # Waits until all hosts are completed.

# Print a short report.
print status(logger)
print summarize(logger)