예제 #1
0
    def testConstructor(self):
        host = Host('localhost')
        self.assertEqual(host.get_protocol(), 'telnet')
        host = Host('localhost', default_protocol='foo')
        self.assertEqual(host.get_protocol(), 'foo')

        for url, result in urls:
            host = Host(url)
            uri = Url.from_string(url)
            self.assertEqual(host.get_name(), uri.hostname)
            self.assertEqual(host.get_address(), uri.hostname)
            self.assertEqual(host.get_uri(), str(uri))
예제 #2
0
    def testGetAll(self):
        self.assertEqual(self.host.get_all(), {'testarg': 1})
        self.testSetAll()
        self.assertEqual(self.host.get_all(), {'test1': 1, 'test2': 2})

        host = Host('localhost')
        self.assertEqual(host.get_all(), {})
예제 #3
0
def run_command(rmq_channel, command, hosts, threads):
    """Execute command on remote host"""
    from Exscript import Account, Host
    from Exscript.util.start import start

    results = {}

    def do_something(thread, host, conn):
        #conn.execute('vtysh -c "%s"' % command)
        conn.execute(command)
        result = repr(conn.response)
        data = {
            host.address: {
                command: result
            },
        }
        body = json.dumps(data)
        rmq_channel.basic_publish(exchange='measure',
                                  routing_key="result",
                                  body=body)
        #conn.execute("exit")

    accounts = [Account("root", password="******")]

    hosts = [Host(h, default_protocol="ssh") for h in hosts]
    #TODO: open multiple ssh sessions
    start(accounts, hosts, do_something, max_threads=threads)
    return results
예제 #4
0
 def __init__(self, name = 'fake'):
     self.function = lambda x: None
     self.name     = name
     self.failures = 0
     self.data     = {'pipe':   0,
                      'stdout': sys.stdout,
                      'host':   Host('foo')}
예제 #5
0
 def testGetDict(self):
     host = Host('foo')
     host.set_address('foo2')
     self.assertEqual(host.get_dict(), {
         'hostname': 'foo',
         'address': 'foo2',
         'protocol': 'telnet',
         'port': 23
     })
예제 #6
0
파일: SeedDB.py 프로젝트: pheller/fresh
 def __get_host_from_row(self, row):
     assert row is not None
     tbl_h = self._table_map['host']
     host = Host(row[tbl_h.c.name])
     host.set_address(row[tbl_h.c.address])
     host.set_protocol(row[tbl_h.c.protocol])
     host.set_tcp_port(row[tbl_h.c.tcp_port])
     host.set('path', row[tbl_h.c.path])
     host.set('country', row[tbl_h.c.country])
     host.set('city', row[tbl_h.c.city])
     host.set('os', row[tbl_h.c.os])
     host.set('duration', row[tbl_h.c.duration])
     host.set('deleted', row[tbl_h.c.deleted])
     return host
예제 #7
0
    def testToHosts(self):
        from Exscript.util.cast import to_hosts
        self.assertRaises(TypeError, to_hosts, None)

        result = to_hosts([])
        self.assertIsInstance(result, list)
        self.assertEqual(len(result), 0)

        result = to_hosts('localhost')
        self.assertIsInstance(result, list)
        self.assertEqual(len(result), 1)
        self.assertIsInstance(result[0], Host)

        result = to_hosts(Host('localhost'))
        self.assertIsInstance(result, list)
        self.assertEqual(len(result), 1)
        self.assertIsInstance(result[0], Host)

        hosts = ['localhost', Host('1.2.3.4')]
        result = to_hosts(hosts)
        self.assertIsInstance(result, list)
        self.assertEqual(len(result), 2)
        self.assertIsInstance(result[0], Host)
        self.assertIsInstance(result[1], Host)
예제 #8
0
 def testToHost(self):
     from Exscript.util.cast import to_host
     self.assertIsInstance(to_host('localhost'), Host)
     self.assertIsInstance(to_host(Host('localhost')), Host)
     self.assertRaises(TypeError, to_host, None)
예제 #9
0
 def testGetUri(self):
     for url, result in urls:
         host = Host(url)
         uri = Url.from_string(url)
         self.assertEqual(host.get_uri().split('&').sort(),
                          str(uri).split('&').sort())
예제 #10
0
 def setUp(self):
     self.host = Host('localhost')
     self.host.set_all(dict(testarg=1))
예제 #11
0
        raise Exception('unsupported os: ' + repr(conn.guess_os()))

    # autoinit() automatically executes commands to make the remote
    # system behave more script-friendly. The specific commands depend
    # on the detected operating system, i.e. on what guess_os() returns.
    conn.autoinit()

    # Execute a simple command.
    conn.execute('show ip int brie')
    print "myvariable is", conn.get_host().get('myvariable')


def two(conn):
    conn.autoinit()
    conn.execute('show interface POS1/0')


accounts = get_accounts_from_file('accounts.cfg')

# Start on one host.
host = Host('localhost')
host.set('myvariable', 'foobar')
start(accounts, host1, one)

# Start on many hosts. In this case, the accounts from accounts.cfg
# are only used if the host url does not contain a username and password.
# The "max_threads" keyword indicates the maximum number of concurrent
# connections.
hosts = get_hosts_from_file('hostlist.txt')
start(accounts, hosts, two, max_threads=2)
예제 #12
0
# This script is not meant to provide a fully automated test, it's
# merely a hack/starting point for investigating memory consumption
# manually. The behavior also depends heavily on the version of meliae.
from meliae import scanner, loader
from Exscript import Account, Host

hostlist = [Host(str(i)) for i in range(1, 10000)]
#accountlist = [Account(str(i)) for i in range(1, 10000)]

scanner.dump_all_objects('test.dump')
om = loader.load('test.dump')
print om.summarize()
예제 #13
0
    from Exscript import Host

    basedir = os.path.dirname(os.path.dirname(__file__))
    prov_dir = os.path.join(basedir, 'providers')
    xsd_file = os.path.join(basedir, 'xsl', 'model.xsd')
    xslt_file = os.path.join(prov_dir, 'ios', 'xsl', 'generic.xsl')
    xml = etree.parse(sys.argv[1])
    proc_xml = xml.find('processor[@type="xslt"]')
    fs_dir = os.path.expandvars(xml.findtext('file-store/basedir'))
    proc_xml.find('xsl-dir').text = basedir
    print 'Assuming file store is in', fs_dir

    class FakeProvider(object):
        store = FileStore(fs_dir)

    prov = FakeProvider()

    p = XsltProcessor(basedir, proc_xml)
    p.debug = True
    host = Host('m4docirom1ea.do-a-11.de.ipmb.dtag.de')
    host.set('path', 'ipmb/pe/m4docirom1ea.do-a-11.de.ipmb.dtag.de')
    host.set('country', 'mycountry')
    host.set('city', 'mycity')
    p.start(prov,
            host,
            object,
            xslt=xslt_file,
            xsd=xsd_file,
            input='show_version.xml',
            output='not-used.xml')