Exemplo n.º 1
0
def check_switch(device):
    """Helper function that does the actual checking"""
    p = PingInventory(c.get("ping_inventory","ini_file"))
    inventory = set([x.ip for x in p.latest().nodes])
    ips = set( device.active_node_ips )
    remove = set()
    for ip in ips:
        if ip not in inventory:
            remove.add(ip)
    
    ips = ips - remove
    up = set(ping_wrapper.ping_many(ips))
    down = ips - up
        
    return up, down
Exemplo n.º 2
0
def check_switch(device):
    """Helper function that does the actual checking"""
    p = PingInventory(c.get("ping_inventory", "ini_file"))
    inventory = set([x.ip for x in p.latest().nodes])
    ips = set(device.active_node_ips)
    remove = set()
    for ip in ips:
        if ip not in inventory:
            remove.add(ip)

    ips = ips - remove
    up = set(ping_wrapper.ping_many(ips))
    down = ips - up

    return up, down
Exemplo n.º 3
0
def main():
    if len(sys.argv) < 3:
        sys.stderr.write("Usage %s file.ini command [args]\n" % sys.argv[0])
        sys.stderr.write("Commands:\n"
                         "  take_inventory\n"
                         "  list\n"
                         "  graph\n"
                         "  show [inventory_id]\n"
                         "  show_ip ip\n")

        sys.exit(1)
    ini_file = sys.argv[1]
    command = sys.argv[2]
    args = sys.argv[3:]

    p = PingInventory(ini_file)
    func = globals()[command]
    func(p, *args)
Exemplo n.º 4
0
class InventoryTest(TestCase):
    def setUp(self):
        self.p = PingInventory("test.ini")
        model.metadata.drop_all()
        model.metadata.create_all()

    def test_inventory_simple(self):
        def fake_scan():
            return ['1.2.3.4', '5.6.7.8']

        i = self.p.take_inventory(fake_scan)
        assert i.numup == 2
        r = self.p.get_latest_up_nodes()
        assert r == ['1.2.3.4', '5.6.7.8']

    def test_inventory_ip_history(self):
        def fake_scan_a():
            return ['1.2.3.4', '5.6.7.8', '9.10.11.12']

        def fake_scan_b():
            return ['1.2.3.4', '9.10.11.12']

        i1 = self.p.take_inventory(fake_scan_a)
        i2 = self.p.take_inventory(fake_scan_b)
        i3 = self.p.take_inventory(fake_scan_a)
        i4 = self.p.take_inventory(fake_scan_a)

        hist = self.p.get_ip_history('5.6.7.8')
        assert len(hist) == 4

        hist = list(self.p.get_ip_history_short('5.6.7.8'))
        assert len(hist) == 3

        assert hist[0][0] == i1.starttime
        assert hist[1][0] == i2.starttime
        assert hist[2][0] == i3.starttime

        assert hist[1][1] == False
Exemplo n.º 5
0
class InventoryTest(TestCase):
    def setUp(self):
        self.p = PingInventory("test.ini")
        model.metadata.drop_all()
        model.metadata.create_all()

    def test_inventory_simple(self):
        def fake_scan():
            return ['1.2.3.4','5.6.7.8']

        i = self.p.take_inventory(fake_scan)
        assert i.numup == 2
        r = self.p.get_latest_up_nodes()
        assert r == ['1.2.3.4','5.6.7.8']

    def test_inventory_ip_history(self):
        def fake_scan_a():
            return ['1.2.3.4','5.6.7.8','9.10.11.12']
        def fake_scan_b():
            return ['1.2.3.4','9.10.11.12']

        i1 = self.p.take_inventory(fake_scan_a)
        i2 = self.p.take_inventory(fake_scan_b)
        i3 = self.p.take_inventory(fake_scan_a)
        i4 = self.p.take_inventory(fake_scan_a)

        hist = self.p.get_ip_history('5.6.7.8')
        assert len(hist) == 4

        hist = list(self.p.get_ip_history_short('5.6.7.8'))
        assert len(hist) == 3

        assert hist[0][0] == i1.starttime
        assert hist[1][0] == i2.starttime
        assert hist[2][0] == i3.starttime

        assert hist[1][1] == False
Exemplo n.º 6
0
 def setUp(self):
     self.p = PingInventory("test.ini")
     model.metadata.drop_all()
     model.metadata.create_all()
Exemplo n.º 7
0
 def setUp(self):
     self.p = PingInventory("test.ini")
     model.metadata.drop_all()
     model.metadata.create_all()