Beispiel #1
0
 def run(self):
     self.createTables(Network)
     Network(name="172.28.141.192/28",
             network="172.28.141.192/28",
             gateway="172.28.141.249").add()
     Network(name="172.28.138.128/25",
             network="172.28.138.128/25",
             gateway="172.28.138.249",
             disabled=1).add()
     Network(name="172.28.147.0/24",
             network="172.28.147.0/24",
             gateway="172.28.147.249",
             disabled=1).add()
     Network(name="10.16.197.64/26",
             network="10.16.197.64/26",
             gateway="10.16.197.249",
             disabled=1).add()
     Network(name="10.16.198.0/24",
             network="10.16.198.0/24",
             gateway="10.16.198.249",
             disabled=1).add()
     Db.commit()
     self.createTables(Address)
     self.createTables(Node)
     return self.results
 def add(self):
     masterPassword = "******"
     kvargs = self.__dict__
     if kvargs["publicKey"] is None:
         kvargs["publicKey"], kvargs["secretKey"] = RSA.generate(
             masterPassword)
     kvargs["lastChange"] = f"{{:{config.datetimeFormat}}}".format(
         datetime.now())
     self.id = super().add(table, **kvargs)
     Db.commit()
     return self
    def run(self):
        self.createTables(Session)
        self.createTables(User)
        self.createTables(Account)
        usr = User(
            firstName="Andrey",
            lastName="Petrishchev",
            description="Administrator",
            tags="Admin",
        ).add()
        acc = Account(ownerId=usr.id,
                      login="******",
                      password=md5("12345"),
                      tags="master",
                      description="Administrators master account").add()
        acc = Account(ownerId=usr.id,
                      login="******",
                      password=md5("54321"),
                      tags="Win",
                      description="Windows installer account").add()
        acc = Account(ownerId=usr.id,
                      login="******",
                      password=md5("54321"),
                      tags="Win",
                      description="Windows installer account").add()
        acc = Account(ownerId=usr.id,
                      login="******",
                      password=md5("54123"),
                      tags="Win",
                      description="Windows installer account").add()
        acc = Account(ownerId=usr.id,
                      login="******",
                      password="******",
                      tags="Nix",
                      description="Nix installer account").add()
        acc = Account(ownerId=usr.id,
                      login="******",
                      password=md5("54321"),
                      tags="Nix",
                      description="Nix installer account").add()
        acc = Account(ownerId=usr.id,
                      login="******",
                      password=md5("54123"),
                      tags="Nix",
                      description="Nix installer account").add()
        acc = Account(ownerId=usr.id,
                      login="******",
                      password="******",
                      tags="SNMP",
                      description="SNMP").add()
        print(acc)

        usr = User(firstName="Viktor",
                   lastName="Maslov",
                   description="Network Administrator",
                   tags="Networks Addresses NetDevices").add()
        acc = Account(
            ownerId=usr.id,
            login="******",
            password=md5("12345"),
            tags="master",
            description="Network Administrator master account").add()
        Db.commit()
        return self.results
	def delete(self):
		super().delete(table, f'id="{self.id}"')
		Db.commit()
	def update(self, where):
		super().update(table, where, **self.__dict__)
		Db.commit()
		return self
	def add(self):
		self.id = super().add(table, **self.__dict__)
		Db.commit()
		return self
 def update(self, where):
     kvargs = self.__dict__
     # kvargs["lastChange"] = f"{{:{config.datetimeFormat}}}".format(datetime.now())
     super().update(table, where, **kvargs)
     Db.commit()
     return self
Beispiel #8
0
	def update(self, where):
		kvargs = self.__dict__
		super().update(table, where, **kvargs)
		Db.commit()
		return self
Beispiel #9
0
	def add(self):
		kvargs = self.__dict__
		kvargs["created"] = f"{{:{config.datetimeFormat}}}".format(datetime.now())
		super().add(table, **kvargs)
		Db.commit()
		return self
Beispiel #10
0
 def loop(self):
     sleep(10)
     while True:
         Events.onStart()
         for network in Network.getNetworks(where="disabled=0").values():
             addresses = Address.getAddresses(
                 where=f'network="{network.network}"')
             with Pool(processes=config.discovery.numProc) as pool:
                 for netId, ip, availabled in pool.starmap_async(
                         self.ping,
                         zip(repeat(network.network),
                             IPv4Network(network.network).hosts())).get():
                     if ip in addresses:
                         address = addresses[ip]
                         if address.disabled == 0:
                             address.setAvailabled(availabled)
                             if availabled == 1:
                                 if address.isChanged:
                                     print("log>",
                                           f'Address "{ip}" availabled')
                                 # if address.nodeId is None:
                                 self.getNode(address)
                             else:
                                 if datetime.fromisoformat(
                                         address.lastChange) + timedelta(
                                             days=config.discovery.
                                             notAvailDeleteDelay
                                         ) > datetime.now():
                                     node = Node().get(
                                         where='id="%{address.nodeId}%"')
                                     if node.id:
                                         if ip == node.addresses:
                                             node.delete()
                                             print(
                                                 "log>",
                                                 f'Node "{node.id} ({node.name})" not availabled more then {config.discovery.notAvailDeleteDelay} days. Node deleted'
                                             )
                                         else:
                                             node.removeAddress(ip)
                                             node.update()
                                     address.delete()
                                     print(
                                         "log>",
                                         f'Address "{ip}" not availabled more then {config.discovery.notAvailDeleteDelay} days. Address deleted'
                                     )
                                 elif address.isChanged:
                                     print(
                                         "log>",
                                         f'Address "{ip}" not availabled')
                         address.update()
                         if address.isChanged:
                             print(address)
                     elif availabled == 1:
                         address = Address(network=netId,
                                           ip=ip,
                                           availabled=1)
                         self.getNode(address)
                         address.add()
                         print("log>", f'Address "{ip}" availabled')
                         print("add", address)
         Db.commit()
         Events.onStop
         sleep(config.discovery.period * 3600)