ZeroMQ has a sendpyonj option that makes the payload a pickle inline,

how friggin cool is that!
This commit is contained in:
Thomas S Hatch 2011-03-07 22:14:13 -07:00
parent 12c08a782a
commit c78c64fbdc
2 changed files with 1 additions and 55 deletions

View file

@ -230,57 +230,3 @@ class ReqServer(threading.Thread):
'''
self.__bind()
class LocalServer(ReqServer):
'''
Create the localhost communication interface for root clients to connect
to
'''
def __init__(self, opts):
ReqServer.__init__(self, opts)
self.num_threads = self.opts['local_threads']
# Prep context
self.context = zmq.Context(1)
# Initialize Publisher
self.publisher = Publisher(opts)
self.publisher.start()
# Create clients socket
self.c_uri = 'tcp://127.0.0.1:' + self.opts['local_port']
self.clients = self.context.socket(zmq.XREP)
# Create workers inproc
self.w_uri = 'inproc://locals'
self.workers = self.context.socket(zmq.XREQ)
# Generate communication key - make this key more awesome
self.key = self.__prep_key()
def __prep_key(self):
'''
A key needs to be placed in the filesystem with permissions 0400 so
clients are required to run as root.
'''
keyfile = os.path.join(self.opts['cachedir'], 'root_key')
key = str(random.randint(100000000000000000000000,
999999999999999999999999))
open(keyfile, 'w+').write(key)
return key
def __worker(self):
'''
A localserver worker needs to run some extra checks
'''
socket = self.context.socket(zmq.REP)
socket.connect(self.w_uri)
while True:
message = socket.recv()
if not message.has_key('key'):
socket.send(0) # Reply false
continue
if not message.has_key('cmd'):
socket.send(0) # Reply false
continue
if not message['key'] == self.key:
socket.send(0) # Reply false
continue
cmd = salt.utils.prep_publish_cmd(message['cmd'])
self.publisher.command(cmd)

View file

@ -92,6 +92,6 @@ class Minion(object):
socket.connect(master_pub)
socket.setsockopt(zmq.SUBSCRIBE, '')
while True:
payload = socket.recv()
payload = socket.recv_pyobj()
self._handle_payload(payload)