def __init__(self, nsp_name: str, ipdb: IPDB): """ Creats a namespace for a specific vlan_iface :param nsp_name: :param vlan_iface_name: :param ipdb: IPDB is a transactional database, containing records, representing network stack objects. Any change in the database is not reflected immidiately in OS, but waits until commit() is called. """ Logger().debug("Create Namespace ...", 2) self.nsp_name = nsp_name self.id = id self.vlan_iface_name = "" self.vlan_iface_ip = "0.0.0.0" self.ipdb = ipdb self.ipdb_netns = None try: self.ipdb_netns = IPDB(nl=NetNS(nsp_name)) netns.setns(nsp_name) self.ipdb_netns.interfaces['lo'].up().commit() Logger().debug("[+] Namespace(" + nsp_name + ") successfully created", 3) # self.encapsulate_interface() except Exception as e: Logger().debug("[-] Couldn't create Namespace(" + nsp_name + ")", 3) for tb in traceback.format_tb(sys.exc_info()[2]): Logger().error(tb, 3) Logger().error(str(e), 3) self.remove()
def __init__(self, ipdb: IPDB, nsp_name: str): """ Creats a namespace for a specific vlan_iface :param nsp_name: :param ipdb: IPDB is a transactional database, containing records, representing network stack objects. Any change in the database is not reflected immidiately in OS, but waits until commit() is called. """ logging.debug("%sCreate Namespace ...", LoggerSetup.get_log_deep(2)) self.ipdb = ipdb if ipdb else IPDB() self.ipdb_netns = None self.nsp_name = nsp_name try: self.ipdb_netns = IPDB(nl=NetNS(nsp_name)) self.ipdb_netns.interfaces['lo'].up().commit() logging.debug( "%s[+] Namespace(" + nsp_name + ") successfully created", LoggerSetup.get_log_deep(3)) # self.encapsulate_interface() except Exception as e: logging.debug("%s[-] Couldn't create Namespace(" + nsp_name + ")", LoggerSetup.get_log_deep(3)) for tb in traceback.format_tb(sys.exc_info()[2]): logging.error("%s" + tb, LoggerSetup.get_log_deep(3)) logging.error("%s" + str(e), LoggerSetup.get_log_deep(3)) self.remove()
def start(self) -> None: """Start host Raises: HostUpException: If host is already running. """ if self.__ns is not None: raise HostUpException() try: self.__ns = NetNS(self.name) except FileExistsError: raise HostUpException() self.__files = _setup_etc(self.name) self.__ipdb = pyroute2.ipdb.main.IPDB(nl=self.__ns) self.__ipdb.interfaces["lo"].up().commit() if self.__manager is not None: self.__manager.register(self)