def __init__(self, *argv, **kwarg): self._argv = tuple(argv) self._kwarg = dict(kwarg) if 'router' in kwarg: self._mitogen_broker = None self._mitogen_router = kwarg.pop('router') else: self._mitogen_broker = mitogen.master.Broker() self._mitogen_router = mitogen.master.Router(self._mitogen_broker) netns = kwarg.get('netns', None) if 'context' in kwarg: context = kwarg['context'] else: protocol = kwarg.pop('protocol', 'local') context = getattr(self._mitogen_router, protocol)(*argv, **kwarg) try: ch_in = mitogen.core.Receiver(self._mitogen_router, respondent=context) self._mitogen_call = context.call_async(MitogenServer, ch_out=ch_in.to_sender(), netns=netns) ch_out = ch_in.get().unpickle() super(RemoteIPRoute, self).__init__(Transport(Channel(ch_in)), Transport(Channel(ch_out))) except Exception: if self._mitogen_broker is not None: self._mitogen_broker.shutdown() self._mitogen_broker.join() raise self.marshal = MarshalRtnl()
def __init__(self, netns, flags=os.O_CREAT): self.netns = netns self.flags = flags self.cmdch, cmdch = MpPipe() self.brdch, brdch = MpPipe() self.server = MpProcess(target=NetNServer, args=(self.netns, cmdch, brdch, self.flags)) self.server.start() super(NetNS, self).__init__() self.marshal = MarshalRtnl()
def __init__(self, netns, flags=os.O_CREAT): self.netns = netns self.flags = flags self.cmdch, self._cmdch = config.MpPipe() self.brdch, self._brdch = config.MpPipe() atexit.register(self.close) self.server = config.MpProcess(target=NetNServer, args=(self.netns, self._cmdch, self._brdch, self.flags)) self.server.start() super(NetNS, self).__init__() self.marshal = MarshalRtnl()
def __init__(self, netns, flags=os.O_CREAT, target=None, libc=None): self.netns = netns self.flags = flags target = target or netns trnsp_in, self.remote_trnsp_out = [Transport(FD(x)) for x in os.pipe()] self.remote_trnsp_in, trnsp_out = [Transport(FD(x)) for x in os.pipe()] self.child = os.fork() if self.child == 0: # child process trnsp_in.close() trnsp_out.close() trnsp_in.file_obj.close() trnsp_out.file_obj.close() try: setns(self.netns, self.flags, libc=libc) except OSError as e: (self .remote_trnsp_out .send({'stage': 'init', 'error': e})) os._exit(e.errno) except Exception as e: (self. remote_trnsp_out .send({'stage': 'init', 'error': OSError(errno.ECOMM, str(e), self.netns)})) os._exit(255) try: Server(self.remote_trnsp_in, self.remote_trnsp_out, target=target) finally: os._exit(0) try: self.remote_trnsp_in.close() self.remote_trnsp_out.close() super(NetNS, self).__init__(trnsp_in, trnsp_out) self.target = target except Exception: self.close() raise atexit.register(self.close) self.marshal = MarshalRtnl()
def __init__(self, url): if url.startswith('tcp://'): hostname = urlparse(url).netloc self.cmdch = SocketChannel(hostname, 4336) self.brdch = SocketChannel(hostname, 4336) self.uuid = uuid32() self.cmdch.send({'stage': 'init', 'domain': 'command', 'client': self.uuid}) self.brdch.send({'stage': 'init', 'domain': 'broadcast', 'client': self.uuid}) else: raise TypeError('remote connection type not supported') super(RemoteSocket, self).__init__() self.marshal = MarshalRtnl()
def __init__(self, target): self.target = target cmd = '%s python -m pyroute2.remote' % target self.shell = subprocess.Popen(cmd.split(), bufsize=0, stdin=subprocess.PIPE, stdout=subprocess.PIPE) trnsp_in = Transport(self.shell.stdout) trnsp_out = Transport(self.shell.stdin) try: super(ShellIPR, self).__init__(trnsp_in, trnsp_out) except Exception: self.close() raise atexit.register(self.close) self.marshal = MarshalRtnl()
def __init__(self, netns, flags=os.O_CREAT): self.netns = netns self.flags = flags self.trnsp_in, remote_trnsp_out = [Transport(FD(x)) for x in os.pipe()] remote_trnsp_in, self.trnsp_out = [Transport(FD(x)) for x in os.pipe()] self.child = os.fork() if self.child == 0: # child process self.trnsp_in.close() self.trnsp_out.close() try: setns(self.netns, self.flags) except OSError as e: remote_trnsp_out.send({'stage': 'init', 'error': e}) os._exit(e.errno) except Exception as e: remote_trnsp_out.send({ 'stage': 'init', 'error': OSError(errno.ECOMM, str(e), self.netns) }) os._exit(255) try: Server(remote_trnsp_in, remote_trnsp_out) finally: os._exit(0) remote_trnsp_in.close() remote_trnsp_out.close() try: super(NetNS, self).__init__() except Exception: self.close() raise atexit.register(self.close) self.marshal = MarshalRtnl()
def __init__(self, netns, flags=os.O_CREAT): self.netns = netns self.flags = flags super(NetNS, self).__init__() self.marshal = MarshalRtnl()