def prepare(self): LOGC.debug("Starting ZMQ Transport") if not os.path.exists(self.sock_dir): os.makedirs(self.sock_dir) if os.name == 'nt': req_queue_uri = 'tcp://127.0.0.1:54111' job_queue_uri = 'tcp://127.0.0.1:54112' ssl_proxy_uri = 'tcp://127.0.0.1:54114' else: req_queue_uri = 'inproc://req-queue.sock' job_queue_uri = 'inproc://job-queue.sock' ssl_proxy_uri = 'inproc://ssl-proxy-uri' self.buses = { 'requests': ['', req_queue_uri], 'jobs': [ssl_proxy_uri, ssl_proxy_uri], 'ssl_proxy': [self.master_repl, ssl_proxy_uri], 'router': [job_queue_uri, ''] } # Run worker threads LOGC.info('Running client in direct mode') LOGC.info("Master socket: %s" % self.master_repl) listener = Thread(target=self.listener_device) listener.start() self.main_sock = self.context.socket(zmq.ROUTER) self.main_sock.bind(self.buses['ssl_proxy'][0]) def verify_client(x509, *args): subj = x509.get_subject() cn = str(subj.CN) fprint = x509.get_fingerprint('sha1') # find user:fprint in local cache if (cn, fprint) in self.user_store: return True return False self.ssl_socket = TLSZmqServerSocket(self.main_sock, self.buses['router'][0], self.node_cert, self.node_key, cert_password=self.cert_pass, route_packets=True, verify_func=verify_client) def ssl_proxy(): # Runs the SSL Thread while not self.stopped.is_set(): try: self.ssl_socket.start() # Start TLSZMQ server socket except zmq.ZMQError, zerr: if (zerr.errno == zmq.ETERM or zerr.errno == zmq.ENOTSUP or zerr.errno == zmq.ENOTSOCK): # System interrupt break except KeyboardInterrupt: break except Exception, ex: LOGR.exception(ex)
def prepare(self): LOGC.debug("Starting ZMQ Transport") if not os.path.exists(self.sock_dir): os.makedirs(self.sock_dir) if os.name == 'nt': req_queue_uri = 'tcp://127.0.0.1:54111' job_queue_uri = 'tcp://127.0.0.1:54112' ssl_proxy_uri = 'tcp://127.0.0.1:54114' else: req_queue_uri = 'inproc://req-queue.sock' job_queue_uri = 'inproc://job-queue.sock' ssl_proxy_uri = 'inproc://ssl-proxy-uri' self.buses = { 'requests': ['', req_queue_uri], 'jobs': [ssl_proxy_uri, ssl_proxy_uri], 'ssl_proxy': [self.master_repl, ssl_proxy_uri], 'router': [job_queue_uri, ''] } # Run worker threads LOGC.info('Running client in direct mode') LOGC.info("Master socket: %s" % self.master_repl) listener = Thread(target=self.listener_device) listener.start() self.main_sock = self.context.socket(zmq.ROUTER) self.main_sock.bind(self.buses['ssl_proxy'][0]) def verify_client(x509, *args): subj = x509.get_subject() cn = str(subj.CN) fprint = x509.get_fingerprint('sha1') # find user:fprint in local cache if (cn, fprint) in self.user_store: return True return False self.ssl_socket = TLSZmqServerSocket( self.main_sock, self.buses['router'][0], self.node_cert, self.node_key, cert_password=self.cert_pass, route_packets=True, verify_func=verify_client) def ssl_proxy(): # Runs the SSL Thread while not self.stopped.is_set(): try: self.ssl_socket.start() # Start TLSZMQ server socket except zmq.ZMQError, zerr: if (zerr.errno == zmq.ETERM or zerr.errno == zmq.ENOTSUP or zerr.errno == zmq.ENOTSOCK): # System interrupt break except KeyboardInterrupt: break except Exception, ex: LOGR.exception(ex)
class NodeTransport(TransportBackend): """ Single-user node transport """ proto = 'zmq+ssl' config_options = [ "node_id", "master_repl", "worker_count", "sock_dir", "user_store", "security.node_cert", "security.node_key", "security.ca", "security.cert_pass" ] def __init__(self, node_id, master_repl, worker_count=5, sock_dir=None, node_cert=None, node_key=None, ca=None, user_store=None, cert_pass=None, **kwargs): self.node_id = node_id or socket.gethostname() self.master_repl = 'tcp://%s' % master_repl self.worker_count = worker_count self.sock_dir = sock_dir or os.path.join(LIB_DIR, 'cloudrunner', 'sock') self.node_cert = node_cert self.node_key = node_key self.ca = ca self.cert_pass = cert_pass self._sockets = [] self.context = zmq.Context() self.stopped = Event() if not user_store: user_store = os.path.join(LIB_DIR, 'cloudrunner', 'user_store.db') self.user_store = CertStore(user_store) def meta(self): return {} def loop(self): ioloop.IOLoop.instance().start() def prepare(self): LOGC.debug("Starting ZMQ Transport") if not os.path.exists(self.sock_dir): os.makedirs(self.sock_dir) if os.name == 'nt': req_queue_uri = 'tcp://127.0.0.1:54111' job_queue_uri = 'tcp://127.0.0.1:54112' ssl_proxy_uri = 'tcp://127.0.0.1:54114' else: req_queue_uri = 'inproc://req-queue.sock' job_queue_uri = 'inproc://job-queue.sock' ssl_proxy_uri = 'inproc://ssl-proxy-uri' self.buses = { 'requests': ['', req_queue_uri], 'jobs': [ssl_proxy_uri, ssl_proxy_uri], 'ssl_proxy': [self.master_repl, ssl_proxy_uri], 'router': [job_queue_uri, ''] } # Run worker threads LOGC.info('Running client in direct mode') LOGC.info("Master socket: %s" % self.master_repl) listener = Thread(target=self.listener_device) listener.start() self.main_sock = self.context.socket(zmq.ROUTER) self.main_sock.bind(self.buses['ssl_proxy'][0]) def verify_client(x509, *args): subj = x509.get_subject() cn = str(subj.CN) fprint = x509.get_fingerprint('sha1') # find user:fprint in local cache if (cn, fprint) in self.user_store: return True return False self.ssl_socket = TLSZmqServerSocket(self.main_sock, self.buses['router'][0], self.node_cert, self.node_key, cert_password=self.cert_pass, route_packets=True, verify_func=verify_client) def ssl_proxy(): # Runs the SSL Thread while not self.stopped.is_set(): try: self.ssl_socket.start() # Start TLSZMQ server socket except zmq.ZMQError, zerr: if (zerr.errno == zmq.ETERM or zerr.errno == zmq.ENOTSUP or zerr.errno == zmq.ENOTSOCK): # System interrupt break except KeyboardInterrupt: break except Exception, ex: LOGR.exception(ex)
class NodeTransport(TransportBackend): """ Single-user node transport """ proto = 'zmq+ssl' config_options = ["node_id", "master_repl", "worker_count", "sock_dir", "user_store", "security.node_cert", "security.node_key", "security.ca", "security.cert_pass"] def __init__(self, node_id, master_repl, worker_count=5, sock_dir=None, node_cert=None, node_key=None, ca=None, user_store=None, cert_pass=None, **kwargs): self.node_id = node_id or socket.gethostname() self.master_repl = 'tcp://%s' % master_repl self.worker_count = worker_count self.sock_dir = sock_dir or os.path.join( LIB_DIR, 'cloudrunner', 'sock') self.node_cert = node_cert self.node_key = node_key self.ca = ca self.cert_pass = cert_pass self._sockets = [] self.context = zmq.Context() self.stopped = Event() if not user_store: user_store = os.path.join(LIB_DIR, 'cloudrunner', 'user_store.db') self.user_store = CertStore(user_store) def meta(self): return {} def loop(self): ioloop.IOLoop.instance().start() def prepare(self): LOGC.debug("Starting ZMQ Transport") if not os.path.exists(self.sock_dir): os.makedirs(self.sock_dir) if os.name == 'nt': req_queue_uri = 'tcp://127.0.0.1:54111' job_queue_uri = 'tcp://127.0.0.1:54112' ssl_proxy_uri = 'tcp://127.0.0.1:54114' else: req_queue_uri = 'inproc://req-queue.sock' job_queue_uri = 'inproc://job-queue.sock' ssl_proxy_uri = 'inproc://ssl-proxy-uri' self.buses = { 'requests': ['', req_queue_uri], 'jobs': [ssl_proxy_uri, ssl_proxy_uri], 'ssl_proxy': [self.master_repl, ssl_proxy_uri], 'router': [job_queue_uri, ''] } # Run worker threads LOGC.info('Running client in direct mode') LOGC.info("Master socket: %s" % self.master_repl) listener = Thread(target=self.listener_device) listener.start() self.main_sock = self.context.socket(zmq.ROUTER) self.main_sock.bind(self.buses['ssl_proxy'][0]) def verify_client(x509, *args): subj = x509.get_subject() cn = str(subj.CN) fprint = x509.get_fingerprint('sha1') # find user:fprint in local cache if (cn, fprint) in self.user_store: return True return False self.ssl_socket = TLSZmqServerSocket( self.main_sock, self.buses['router'][0], self.node_cert, self.node_key, cert_password=self.cert_pass, route_packets=True, verify_func=verify_client) def ssl_proxy(): # Runs the SSL Thread while not self.stopped.is_set(): try: self.ssl_socket.start() # Start TLSZMQ server socket except zmq.ZMQError, zerr: if (zerr.errno == zmq.ETERM or zerr.errno == zmq.ENOTSUP or zerr.errno == zmq.ENOTSOCK): # System interrupt break except KeyboardInterrupt: break except Exception, ex: LOGR.exception(ex)