Пример #1
0
def generate_commands(app):
    path = os.path.join(app.srcdir, "for-ops", "commands")
    ext = app.config['source_suffix']
    if not os.path.exists(path):
        os.makedirs(path)

    tocname = os.path.join(app.srcdir, "for-ops", "commands%s" % ext)

    commands = get_commands()
    items = commands.items()
    items = sorted(items)

    with open(tocname, "w") as toc:
        toc.write(".. include:: commands-intro%s\n\n" % ext)
        toc.write("circus-ctl commands\n")
        toc.write("-------------------\n\n")

        commands = get_commands()
        for name, cmd in items:
            toc.write("- **%s**: :doc:`commands/%s`\n" % (name, name))

            # write the command file
            refline = ".. _%s:" % name
            fname = os.path.join(path, "%s%s" % (name, ext))
            with open(fname, "w") as f:
                f.write("\n".join([refline, "\n", cmd.desc, ""]))

        toc.write("\n")
        toc.write(".. toctree::\n")
        toc.write("   :hidden:\n")
        toc.write("   :glob:\n\n")
        toc.write("   commands/*\n")
Пример #2
0
 def __init__(self,
              endpoint,
              pubsub_endoint,
              stats_endpoint,
              ssh_server,
              delay=1.):
     self.topic = 'watcher.'
     self.delay = delay
     self.ctx = zmq.Context()
     self.pubsub_endpoint = pubsub_endoint
     self.sub_socket = self.ctx.socket(zmq.SUB)
     self.sub_socket.setsockopt(zmq.SUBSCRIBE, self.topic)
     self.sub_socket.connect(self.pubsub_endpoint)
     self.loop = ioloop.IOLoop.instance()  # events coming from circusd
     self.substream = zmqstream.ZMQStream(self.sub_socket, self.loop)
     self.substream.on_recv(self.handle_recv)
     self.client = CircusClient(context=self.ctx,
                                endpoint=endpoint,
                                ssh_server=ssh_server)
     self.cmds = get_commands()
     self._pids = defaultdict(list)
     self._callbacks = dict()
     self.publisher = StatsPublisher(stats_endpoint, self.ctx)
     self.running = False  # should the streamer be running?
     self.stopped = False  # did the collect started yet?
     self.circus_pids = {}
     self.sockets = []
Пример #3
0
 def __init__(self):
     self.commands = get_commands()
     _Help.commands = self.commands
     self.options = {
         'endpoint': {'default': None, 'help': 'connection endpoint'},
         'timeout': {'default': 5, 'help': 'connection timeout'},
         'json': {'default': False, 'action': 'store_true',
                  'help': 'output to JSON'},
         'prettify': {'default': False, 'action': 'store_true',
                      'help': 'prettify output'},
         'version': {'default': False, 'action': 'store_true',
                     'help': 'display version and exit'}
     }
Пример #4
0
def main():
    # TODO, we should ask the server for its command list
    commands = get_commands()

    globalopts = parse_arguments(sys.argv[1:], commands)
    if globalopts['endpoint'] is None:
        globalopts['endpoint'] = os.environ.get('CIRCUSCTL_ENDPOINT',
                                                DEFAULT_ENDPOINT_DEALER)
    client = CircusClient(endpoint=globalopts['endpoint'],
                          timeout=globalopts['timeout'],
                          ssh_server=globalopts['ssh'],
                          ssh_keyfile=globalopts['ssh_keyfile'])

    CircusCtl(client, commands).start(globalopts)
Пример #5
0
    def __init__(self, endpoint, context, loop, arbiter, check_delay=1.0):
        self.arbiter = arbiter
        self.endpoint = endpoint
        self.context = context
        self.loop = loop
        self.check_delay = check_delay * 1000

        self.jobs = Queue()

        # initialize the sys handler
        self.sys_hdl = SysHandler(self)

        # get registered commands
        self.commands = get_commands()
Пример #6
0
def main():
    logging.basicConfig()
    # TODO, we should ask the server for its command list
    commands = get_commands()
    globalopts = parse_arguments(sys.argv[1:], commands)
    if globalopts['endpoint'] is None:
        globalopts['endpoint'] = os.environ.get('CIRCUSCTL_ENDPOINT',
                                                DEFAULT_ENDPOINT_DEALER)
    client = CircusClient(endpoint=globalopts['endpoint'],
                          timeout=globalopts['timeout'],
                          ssh_server=globalopts['ssh'],
                          ssh_keyfile=globalopts['ssh_keyfile'])

    CircusCtl(client, commands).start(globalopts)
Пример #7
0
def main():
    # TODO, we should ask the server for its command list
    commands = get_commands()

    globalopts = parse_arguments(sys.argv[1:], commands)
    if globalopts['endpoint'] is None:
        globalopts['endpoint'] = DEFAULT_ENDPOINT_DEALER

    client = CircusClient(endpoint=globalopts['endpoint'],
                          timeout=globalopts['timeout'],
                          ssh_server=globalopts['ssh'],
                          ssh_keyfile=globalopts['ssh_keyfile'])

    CircusCtl(client, commands).start(globalopts)
Пример #8
0
    def __init__(self, endpoint, context, loop, arbiter, check_delay=1.0):
        self.arbiter = arbiter
        self.endpoint = endpoint
        self.context = context
        self.loop = loop
        self.check_delay = check_delay * 1000

        self.jobs = Queue()

        # initialize the sys handler
        self.sys_hdl = SysHandler(self)

        # get registered commands
        self.commands = get_commands()
Пример #9
0
    def __init__(self, endpoint, multicast_endpoint, context, loop, arbiter,
                 check_delay=1.0):
        self.arbiter = arbiter
        self.endpoint = endpoint
        self.multicast_endpoint = multicast_endpoint
        self.context = context
        self.loop = loop
        self.check_delay = check_delay * 1000
        self.started = False

        # initialize the sys handler
        self._init_syshandler()

        # get registered commands
        self.commands = get_commands()
Пример #10
0
    def __init__(self, endpoint, multicast_endpoint, context, loop, arbiter,
                 check_delay=1.0, endpoint_owner=None):
        self.arbiter = arbiter
        self.caller = None
        self.endpoint = endpoint
        self.multicast_endpoint = multicast_endpoint
        self.context = context
        self.loop = loop
        self.check_delay = check_delay * 1000
        self.endpoint_owner = endpoint_owner
        self.started = False

        # initialize the sys handler
        self._init_syshandler()

        # get registered commands
        self.commands = get_commands()
Пример #11
0
 def __init__(self, endpoint, pubsub_endoint, stats_endpoint,
              ssh_server=None, delay=1., loop=None):
     self.topic = b'watcher.'
     self.delay = delay
     self.ctx = zmq.Context()
     self.pubsub_endpoint = pubsub_endoint
     self.sub_socket = self.ctx.socket(zmq.SUB)
     self.sub_socket.setsockopt(zmq.SUBSCRIBE, self.topic)
     self.sub_socket.connect(self.pubsub_endpoint)
     self.loop = loop or ioloop.IOLoop.current()
     self.substream = zmqstream.ZMQStream(self.sub_socket, self.loop)
     self.substream.on_recv(self.handle_recv)
     self.client = CircusClient(context=self.ctx, endpoint=endpoint,
                                ssh_server=ssh_server)
     self.cmds = get_commands()
     self.publisher = StatsPublisher(stats_endpoint, self.ctx)
     self._initialize()
Пример #12
0
 def __init__(self, endpoint, pubsub_endoint, stats_endpoint,
              ssh_server=None, delay=1., loop=None):
     self.topic = b'watcher.'
     self.delay = delay
     self.ctx = zmq.Context()
     self.pubsub_endpoint = pubsub_endoint
     self.sub_socket = self.ctx.socket(zmq.SUB)
     self.sub_socket.setsockopt(zmq.SUBSCRIBE, self.topic)
     self.sub_socket.connect(self.pubsub_endpoint)
     self.loop = loop or ioloop.IOLoop.instance()
     self.substream = zmqstream.ZMQStream(self.sub_socket, self.loop)
     self.substream.on_recv(self.handle_recv)
     self.client = CircusClient(context=self.ctx, endpoint=endpoint,
                                ssh_server=ssh_server)
     self.cmds = get_commands()
     self.publisher = StatsPublisher(stats_endpoint, self.ctx)
     self._initialize()
Пример #13
0
    def __init__(self, endpoint, multicast_endpoint, context, loop, arbiter,
                 check_delay=1.0, endpoint_owner=None):
        self.arbiter = arbiter
        self.caller = None
        self.endpoint = endpoint
        self.multicast_endpoint = multicast_endpoint
        self.context = context
        self.loop = loop
        self.check_delay = check_delay * 1000
        self.endpoint_owner = endpoint_owner
        self.started = False
        self._managing_watchers_future = None

        # initialize the sys handler
        self._init_syshandler()

        # get registered commands
        self.commands = get_commands()
Пример #14
0
 def __init__(self, endpoint, pubsub_endoint, stats_endpoint):
     self.topic = 'watcher.'
     self.ctx = zmq.Context()
     self.pubsub_endpoint = pubsub_endoint
     self.sub_socket = self.ctx.socket(zmq.SUB)
     self.sub_socket.setsockopt(zmq.SUBSCRIBE, self.topic)
     self.sub_socket.connect(self.pubsub_endpoint)
     self.loop = ioloop.IOLoop()
     self.substream = zmqstream.ZMQStream(self.sub_socket, self.loop)
     self.substream.on_recv(self.handle_recv)
     self.client = CircusClient(context=self.ctx, endpoint=endpoint)
     self.cmds = get_commands()
     self.watchers = defaultdict(list)
     self._pids = defaultdict(list)
     self.running = False
     self.stopped = False
     self.lock = threading.RLock()
     self.results = Queue.Queue()
     self.stats = StatsCollector(self)
     self.publisher = StatsPublisher(self, stats_endpoint, context=self.ctx)
Пример #15
0
 def __init__(self, endpoint, pubsub_endoint, stats_endpoint, delay=1.):
     self.topic = 'watcher.'
     self.delay = delay
     self.ctx = zmq.Context()
     self.pubsub_endpoint = pubsub_endoint
     self.sub_socket = self.ctx.socket(zmq.SUB)
     self.sub_socket.setsockopt(zmq.SUBSCRIBE, self.topic)
     self.sub_socket.connect(self.pubsub_endpoint)
     self.loop = ioloop.IOLoop()  # events coming from circusd
     self.substream = zmqstream.ZMQStream(self.sub_socket, self.loop)
     self.substream.on_recv(self.handle_recv)
     self.client = CircusClient(context=self.ctx, endpoint=endpoint)
     self.cmds = get_commands()
     self._pids = defaultdict(list)
     self._callbacks = dict()
     self.collector = StatsCollector()
     self.publisher = StatsPublisher(stats_endpoint, self.ctx)
     self.running = False  # should the streamer be running?
     self.stopped = False  # did the collect started yet?
     self.circus_pids = {}
Пример #16
0
    def autocomplete(self, autocomplete=False, words=None, cword=None):
        """
        Output completion suggestions for BASH.

        The output of this function is passed to BASH's `COMREPLY` variable and
        treated as completion suggestions. `COMREPLY` expects a space
        separated string as the result.

        The `COMP_WORDS` and `COMP_CWORD` BASH environment variables are used
        to get information about the cli input. Please refer to the BASH
        man-page for more information about this variables.

        Subcommand options are saved as pairs. A pair consists of
        the long option string (e.g. '--exclude') and a boolean
        value indicating if the option requires arguments. When printing to
        stdout, a equal sign is appended to options which require arguments.

        Note: If debugging this function, it is recommended to write the debug
        output in a separate file. Otherwise the debug output will be treated
        and formatted as potential completion suggestions.
        """
        autocomplete = autocomplete or 'AUTO_COMPLETE' in os.environ

        # Don't complete if user hasn't sourced bash_completion file.
        if not autocomplete:
            return

        words = words or os.environ['COMP_WORDS'].split()[1:]
        cword = cword or int(os.environ['COMP_CWORD'])

        try:
            curr = words[cword - 1]
        except IndexError:
            curr = ''

        subcommands = get_commands()

        if cword == 1:  # if completing the command name
            print(' '.join(sorted(filter(lambda x: x.startswith(curr),
                                         subcommands))))
        sys.exit(1)
Пример #17
0
    def autocomplete(self, autocomplete=False, words=None, cword=None):
        """
        Output completion suggestions for BASH.

        The output of this function is passed to BASH's `COMREPLY` variable and
        treated as completion suggestions. `COMREPLY` expects a space
        separated string as the result.

        The `COMP_WORDS` and `COMP_CWORD` BASH environment variables are used
        to get information about the cli input. Please refer to the BASH
        man-page for more information about this variables.

        Subcommand options are saved as pairs. A pair consists of
        the long option string (e.g. '--exclude') and a boolean
        value indicating if the option requires arguments. When printing to
        stdout, a equal sign is appended to options which require arguments.

        Note: If debugging this function, it is recommended to write the debug
        output in a separate file. Otherwise the debug output will be treated
        and formatted as potential completion suggestions.
        """
        autocomplete = autocomplete or 'AUTO_COMPLETE' in os.environ

        # Don't complete if user hasn't sourced bash_completion file.
        if not autocomplete:
            return

        words = words or os.environ['COMP_WORDS'].split()[1:]
        cword = cword or int(os.environ['COMP_CWORD'])

        try:
            curr = words[cword - 1]
        except IndexError:
            curr = ''

        subcommands = get_commands()

        if cword == 1:  # if completing the command name
            print(' '.join(
                sorted(filter(lambda x: x.startswith(curr), subcommands))))
        sys.exit(1)
Пример #18
0
 def __init__(self):
     self.commands = get_commands()
Пример #19
0
 def __init__(self):
     self.commands = get_commands()
Пример #20
0
from circus.commands import get_commands
from circusweb.client import AsynchronousCircusClient
from circusweb.stats_client import AsynchronousStatsConsumer
from circusweb.namespace import SocketIOConnection

from tornado import gen

cmds = get_commands()


class Controller(object):
    def __init__(self, loop, ssh_server=None):
        self.clients = {}
        self.stats_clients = {}
        self.loop = loop
        self.ssh_server = ssh_server

    @gen.coroutine
    def connect(self, endpoint):
        endpoint = str(endpoint)
        if endpoint not in self.clients:
            client = AsynchronousCircusClient(self.loop, endpoint,
                                              ssh_server=self.ssh_server)
            yield gen.Task(client.update_watchers)
        else:
            client = self.get_client(endpoint)
        client.count += 1
        self.clients[endpoint] = client

    def disconnect(self, endpoint):
        endpoint = str(endpoint)
Пример #21
0
import os
from collections import defaultdict
from threading import Thread
from circus.commands import get_commands
from circus.client import CircusClient, CallError
from circus.stats.client import StatsClient

_DIR = os.path.dirname(__file__)
client = None
cmds = get_commands()
MAX_STATS = 25


class Refresher(Thread):
    def __init__(self, client):
        Thread.__init__(self)
        self.client = client
        self.daemon = True
        self.running = False
        self.cclient = None

    def _check_size(self, stat):
        if len(stat) > MAX_STATS:
            start = len(stat) - MAX_STATS
            stat[:] = stat[start:]

    def run(self):
        self.cclient = StatsClient(endpoint=self.client.stats_endpoint)
        stats = self.client.stats
        dstats = self.client.dstats
        self.running = True