def start_client(proto, server): manager = tendril.get_manager(proto) manager.start() tend = manager.connect(server, EchoApplicationClient) return manager, tend.application
def __init__(self, endpoints): """ Initialize a ``HubServer`` object. :param endpoints: A list of tuples of addresses and ports to listen on. """ # A dictionary to keep track of the subscribers self._subscribers = {} # A dictionary to keep track of the listeners self._listeners = {} # Keep track of whether we're running self._running = False # Set up the tendril managers for endpoint in endpoints: self._listeners[endpoint] = tendril.get_manager('tcp', endpoint) # Set up behavior on signals gevent.signal(signal.SIGINT, self.stop) gevent.signal(signal.SIGTERM, self.stop) try: # pragma: no cover # Force an immediate shutdown gevent.signal(signal.SIGUSR1, self.shutdown) except Exception: # pragma: no cover # Ignore errors; SIGUSR1 isn't everywhere pass
def __init__(self, hub, cert_conf=None, secure=True, app_name=None, app_id=None): """ Initialize a ``NotificationServer`` object. :param hub: The address of the hub, as a tuple of hostname and port. :param cert_conf: The path to the certificate configuration file. Optional. :param secure: If ``False``, SSL will not be used. Defaults to ``True``. :param app_name: The name of the application. If not specified, the name is derived from ``sys.argv[0]``. :param app_id: A UUID for notifications generated internal to the notifier. If not specified, a random UUID will be generated. """ # Handle the arguments self._hub = hub self._manager = tendril.get_manager('tcp', util.outgoing_endpoint(hub)) self._wrapper = util.cert_wrapper(cert_conf, 'notifier', secure=secure) # Save the app name and ID self._app_name = app_name or os.path.basename(sys.argv[0]) self._app_id = app_id or str(uuid.uuid4()) # Track running status and the queue of notifications self._hub_app = None self._notifications = [] self._notify_event = gevent.event.Event() # Set up behavior on signals gevent.signal(signal.SIGINT, self.stop) gevent.signal(signal.SIGTERM, self.stop) try: # pragma: no cover # Force an immediate shutdown gevent.signal(signal.SIGUSR1, self.shutdown) except Exception: # pragma: no cover # Ignore errors; SIGUSR1 isn't everywhere pass
def send_notification(hub, app_name, summary, body, urgency=None, category=None, id=None, cert_conf=None, secure=True): """ Sends a notification via the configured HeyU hub. The hub address is read from the "~/.heyu.hub" file, which should contain either "hostname" or "hostname:port". If the file doesn't exist, and "--host" is not given, "localhost" will be tried. Prints out the notification ID if the notification is accepted. Note that certificate configuration is specified in "~/.heyu.cert" by default. :param hub: The address of the hub, as a tuple of hostname and port. :param app_name: The name of the application the notification is for. :param summary: A summary of the notification. :param body: The body of the notification. :param urgency: The urgency level for the notification. Optional. :param category: A category for the notification. Optional. :param id: The ID of a notification to replace. Optional. :param cert_conf: The path to the certificate configuration file. Optional. :param secure: If ``False``, SSL will not be used. Defaults to ``True``. """ # Look up the manager manager = tendril.get_manager('tcp', util.outgoing_endpoint(hub)) manager.start() # Connect to the hub app = tendril.TendrilPartial(SubmitterApplication, app_name, summary, body, urgency, category, id) wrapper = util.cert_wrapper(cert_conf, 'submitter', secure=secure) manager.connect(hub, app, wrapper) # Wait for the submitter to exit gevent.wait()
def start_server(proto): manager = tendril.get_manager(proto, ('127.0.0.1', 0)) manager.start(EchoApplicationServer) return manager
def start_server(proto): manager = tendril.get_manager(proto, ("127.0.0.1", 0)) manager.start(EchoApplicationServer) return manager