def __init__(self, address): try: host, port = address.split(':') except ValueError: raise ValueError('incorrectly formatted address "%s"; expected ' '"ip:port"' % address) self.etcd_client = etcd.Etcd(host=host, port=int(port))
def main(): format = '%(asctime)s %(levelname)-8s %(name)s: %(message)s' logging.basicConfig(level=logging.DEBUG, format=format) requests_log = logging.getLogger("requests") requests_log.setLevel(logging.WARNING) formation = os.getenv('GILLIAM_FORMATION') instance = os.getenv('GILLIAM_INSTANCE') srnodes = os.getenv('GILLIAM_SERVICE_REGISTRY_NODES') check_interval = int(os.getenv('CHECK_INTERVAL', 10)) store_client = etcd.Etcd(host='_store.%s.service' % (formation,)) store_command = store.InstanceStoreCommand(store_client) store_query = store.InstanceStoreQuery(store_client, store_command) registry_client = ServiceRegistryClient(time, srnodes.split(',')) executor_manager = ExecutorManager(time, registry_client, store_query, check_interval) policy = RequirementRankPlacementPolicy() services = [ Scheduler(time, store_query, executor_manager, policy), Updater(time, store_query, executor_manager), Terminator(time, store_query, executor_manager) ] leader_lock = util.Lock(store_client, 'leader', instance) with leader_lock: store_query.start() executor_manager.start() for service in services: service.start() _worker(executor_manager, store_query)
def main(): parser = OptionParser() parser.add_option("-s", "--service-registry", dest="service_registry", default=os.getenv('GILLIAM_SERVICE_REGISTRY', ''), help="service registry nodes", metavar="HOSTS") (options, args) = parser.parse_args() format = '%(asctime)s %(levelname)-8s %(name)s: %(message)s' logging.basicConfig(level=logging.DEBUG, format=format) formation = os.getenv('GILLIAM_FORMATION', 'scheduler') store_client = etcd.Etcd(host='_store.%s.service' % (formation, ), autostart=False) store_command = store.InstanceStoreCommand(store_client) store_query = store.InstanceStoreQuery(store_client, store_command) release_store = ReleaseStore(store_client) registry_client = ServiceRegistryClient( time, options.service_registry.split(',')) executor_manager = ExecutorManager(time, registry_client, store_query, 5) executor_manager.start() _bootstrap0(registry_client, executor_manager, store_client, store_command, release_store, formation)
def get_appname(hostname): """Parse the application name for the incoming. """ e=etcd.Etcd(host="172.17.42.1") try: appname=hostname.split(".")[0] listofinstances=[] ls = e.get("apps/"+appname+"/running") for key in ls: listofinstances.append(key.value()) port=choice(listofinstances) return "172.17.42.1:"+port except: return ""
def main(): parser = OptionParser() parser.add_option("-p", "--port", dest="port", type=int, default=80, help="listen port", metavar="PORT") (options, args) = parser.parse_args() format = '%(levelname)-8s %(name)s: %(message)s' logging.basicConfig(level=logging.DEBUG, format=format) requests_log = logging.getLogger("requests") requests_log.setLevel(logging.WARNING) formation = os.getenv('GILLIAM_FORMATION') store_client = etcd.Etcd(host='_store.%s.service' % (formation, )) formation_store = FormationStore(store_client) release_store = ReleaseStore(store_client) store_command = store.InstanceStoreCommand(store_client) store_query = store.InstanceStoreQuery(store_client, store_command) store_query.start() api = API(logging.getLogger('api'), {}) api.add( 'formation', FormationResource(logging.getLogger('api.formation'), partial(api.url, 'formation'), partial(api.url, 'formations'), formation_store)) api.add( 'release', ReleaseResource(logging.getLogger('api.release'), partial(api.url, 'release'), partial(api.url, 'releases'), release_store, partial(Release, store_command, store_query))) api.add( 'instance', InstanceResource(logging.getLogger('api.release'), partial(api.url, 'instance'), partial(api.url, 'instances'), store_query, store_command)) pywsgi.WSGIServer(('', options.port), api).serve_forever()
def main(): parser = OptionParser() parser.add_option("-p", "--port", dest="port", type=int, default=80, help="listen port", metavar="PORT") (options, args) = parser.parse_args() format = '%(levelname)-8s %(name)s: %(message)s' logging.basicConfig(level=logging.DEBUG, format=format) formation = os.getenv('GILLIAM_FORMATION') store_client = etcd.Etcd(host='_store.%s.service' % (formation,)) store_command = store.RouteStoreCommand(store_client) store_query = store.RouteStoreQuery(store_client) store_query.start() api = API(logging.getLogger('api')) api.add('route', RouteResource(store_command, store_query)) pywsgi.WSGIServer(('', options.port), api.create_app()).serve_forever()
def main(): parser = OptionParser() parser.add_option("-p", "--port", dest="port", type=int, default=80, help="listen port", metavar="PORT") (options, args) = parser.parse_args() format = '%(levelname)-8s %(name)s: %(message)s' logging.basicConfig(level=logging.DEBUG, format=format) formation = os.getenv('GILLIAM_FORMATION') store_client = etcd.Etcd(host='_store.%s.service' % (formation, )) store_query = RouteStoreQuery(store_client) store_query.start() app = Proxy(requests.Session(), Router(store_query)) logging.info("start accepting connections on %d" % (options.port, )) pywsgi.WSGIServer(('', options.port), app).serve_forever()
import etcd import time import json template = """ tickTime=2000 initLimit=10 syncLimit=5 dataDir=/var/lib/zookeeper clientPort=2181 autopurge.snapRetainCount=3 autopurge.purgeInterval=1 """ e = etcd.Etcd(host='172.17.42.1') KEY = 'zoo-' + os.environ["ETCD_KEY"] def registry(): print 'Registering Config' servers = [] i = 1 while True: try: servers.append(os.environ['ZOOKEEPER_' + str(i)]) except: break i = i + 1
import traceback import sys import json import hashlib import gevent from gevent.queue import Queue import etcd import docker import zmq.green as zmq import requests import gevent.monkey gevent.monkey.patch_socket() etcd_client = etcd.Etcd("172.17.42.1") # we mount the coreos /var/ to /coreos_run/ docker_client = docker.Client("unix://coreos_run/docker.sock") # tasks that should be sent to the master/director director_tasks = Queue() # tasks that should be performed via the docker api docker_tasks = Queue() def get_director_ip(): """trying to get the director address to the master server (ZeroMQ)""" try: addr = etcd_client.get("services/director") return addr.value except:
def setUp(self): self.e = etcd.Etcd("10.0.1.110")