def __init__(self, *args, **kwargs): super(BaseRMQSensor, self).__init__(*args, **kwargs) # getting values from config rabbit_host = config.get('rabbit_host') rabbit_port = config.get('rabbit_port') self.rmqapi = api.RMQPublisher(self._gen_routing_key(), rabbit_host=rabbit_host, rabbit_port=rabbit_port)
def redis(args): host = config.get('redis_host') port = config.get('redis_port') try: red = RedisAPI(host, port) print str(red.get(args.uid)) except RedisConnError: print 'No Redis host found'
def redis(args): host = config.get("redis_host") port = config.get("redis_port") try: red = RedisAPI(host, port) print str(red.get(args.uid)) except RedisConnError: print "No Redis host found"
def __init__(self, *args, **kwargs): super(BaseRMQSensor, self).__init__(*args, **kwargs) # getting values from config rabbit_host = config.get('rabbit_host') rabbit_port = config.get('rabbit_port') self.rmqapi = api.RMQPublisher( self._gen_routing_key(), rabbit_host=rabbit_host, rabbit_port=rabbit_port )
def rmq(args): host = config.get("rabbit_host") port = config.get("rabbit_port") try: cons = RMQConsumer(args.topic, host, port) for method, _, msg in cons.consume(): print "{}: {}".format(method.routing_key, msg) except RMQConnError: print "No RabbitMQ host found." except KeyboardInterrupt: cons.close_connection() print "Connection closed"
def rmq(args): host = config.get('rabbit_host') port = config.get('rabbit_port') try: cons = RMQConsumer(args.topic, host, port) for method, _, msg in cons.consume(): print '{}: {}'.format(method.routing_key, msg) except RMQConnError: print 'No RabbitMQ host found.' except KeyboardInterrupt: cons.close_connection() print 'Connection closed'
def run(): parser = argparse.ArgumentParser( description="Client to start Sy's daemon.") parser.add_argument('-d', dest='daemon', action='store_true', help='Start server as daemon') parser.add_argument('-D', dest='debug', action='store_true', help='Start server in debug mode') args = parser.parse_args() daemon.debug = args.debug port = config.get('sy_port') if args.daemon: #TODO handle better command string cmd = 'python bin/sy-agent' if args.debug: cmd += ' -D' DEVNULL = open(os.devnull, 'wb') p = sp.Popen(cmd.split(), stdout=DEVNULL, stderr=DEVNULL) print 'Daemon\'s PID: {}'.format(p.pid) else: daemon.run(port=port)
def __init__(self, *args, **kwargs): Greenlet.__init__(self) Model.__init__(self, *args, **kwargs) docker_url = config.get('docker_url') self.container = api.DockerAPI(self.cid, docker_url) self._lock = Semaphore() self._lock.acquire() # locking semaphore self._new_data = None
def start_redis(): # launch a redis container and bind it to port given by config: # docker run -d --name test-redis -p <redis_port>:6379 redis # first, ensure that we have the image docker_client.pull('redis', tag='latest') # then create the container redis_port = config.get('redis_port') cid = docker_client.create_container( image='redis:latest', detach=True, name='test-redis', ports=[redis_port], host_config=create_host_config(port_bindings={redis_port: 6379}))['Id'] # now we can start it docker_client.start(cid) return cid
def start_redis(): # launch a redis container and bind it to port given by config: # docker run -d --name test-redis -p <redis_port>:6379 redis # first, ensure that we have the image docker_client.pull("redis", tag="latest") # then create the container redis_port = config.get("redis_port") cid = docker_client.create_container( image="redis:latest", detach=True, name="test-redis", ports=[redis_port], host_config=create_host_config(port_bindings={redis_port: 6379}), )["Id"] # now we can start it docker_client.start(cid) return cid
def start_rabbit(): # launch a rabbitmq container and bind it to port given by config: # docker run -d -e RABBITMQ_NODENAME=test-rabbit --name test-rabbit -p <rabbit_port>:5672 rabbitmq:3 # first, ensure that we have the image docker_client.pull("rabbitmq", tag="3") # then create the container rabbit_port = config.get("rabbit_port") cid = docker_client.create_container( image="rabbitmq:3", detach=True, environment={"RABBITMQ_NODENAME": "test-rabbit"}, name="test-rabbit", ports=[rabbit_port], host_config=create_host_config(port_bindings={rabbit_port: 5672}), )["Id"] # now we can start it docker_client.start(cid) wait_for_rabbit() return cid
def start_rabbit(): # launch a rabbitmq container and bind it to port given by config: # docker run -d -e RABBITMQ_NODENAME=test-rabbit --name test-rabbit -p <rabbit_port>:5672 rabbitmq:3 # first, ensure that we have the image docker_client.pull('rabbitmq', tag='3') # then create the container rabbit_port = config.get('rabbit_port') cid = docker_client.create_container( image='rabbitmq:3', detach=True, environment={'RABBITMQ_NODENAME': 'test-rabbit'}, name='test-rabbit', ports=[rabbit_port], host_config=create_host_config( port_bindings={rabbit_port: 5672}))['Id'] # now we can start it docker_client.start(cid) wait_for_rabbit() return cid
def run(): parser = argparse.ArgumentParser( description="Client to start Sy's daemon." ) parser.add_argument('-d', dest='daemon', action='store_true', help='Start server as daemon') parser.add_argument('-D', dest='debug', action='store_true', help='Start server in debug mode') args = parser.parse_args() daemon.debug = args.debug port = config.get('sy_port') if args.daemon: #TODO handle better command string cmd = 'python bin/sy-agent' if args.debug: cmd += ' -D' DEVNULL = open(os.devnull, 'wb') p = sp.Popen(cmd.split(), stdout=DEVNULL, stderr=DEVNULL) print 'Daemon\'s PID: {}'.format(p.pid) else: daemon.run(port=port)
def __init__(self, *args, **kwargs): super(BaseRedisSensor, self).__init__(*args, **kwargs) # getting values from config redis_host = config.get('redis_host') redis_port = config.get('redis_port') self.redisapi = api.RedisAPI(redis_host, redis_port)
import argparse, requests, json from sy import config, log from sy.api import RMQConsumer, RedisAPI from pika.exceptions import AMQPConnectionError as RMQConnError from redis.exceptions import ConnectionError as RedisConnError LOG = log.get(__name__) host = config.get("sy_host") port = config.get("sy_port") base_url = "http://" + host + ":" + str(port) def _get_path(*args): tokens = [base_url] tokens.extend(args) return "/".join(tokens) def _print_resp(resp): req = resp.request print "[{}] {} {}".format(req.method, req.url, resp.status_code) print str(resp.text) def add(args): cid = args.cid stype = args.stype if not args.data: data = {}
import argparse, requests, json from sy import config, log from sy.api import RMQConsumer, RedisAPI from pika.exceptions import AMQPConnectionError as RMQConnError from redis.exceptions import ConnectionError as RedisConnError LOG = log.get(__name__) host = config.get('sy_host') port = config.get('sy_port') base_url = 'http://' + host + ':' + str(port) def _get_path(*args): tokens = [ base_url, ] tokens.extend(args) return '/'.join(tokens) def _print_resp(resp): req = resp.request print '[{}] {} {}'.format(req.method, req.url, resp.status_code) print str(resp.text) def add(args): cid = args.cid stype = args.stype