Ejemplo n.º 1
0
def only_once(action=None):
    """
    Register the decorated function to be run once, and only once.

    This decorator will never cause arguments to be passed to the handler.
    """
    if action is None:
        # allow to be used as @only_once or @only_once()
        return only_once

    action_id = _action_id(action)
    handler = Handler.get(action)
    handler.add_predicate(lambda: not was_invoked(action_id))
    handler.add_post_callback(partial(mark_invoked, action_id))
    return action
Ejemplo n.º 2
0
def only_once(action=None):
    """
    Register the decorated function to be run once, and only once.

    This decorator will never cause arguments to be passed to the handler.
    """
    if action is None:
        # allow to be used as @only_once or @only_once()
        return only_once

    action_id = _action_id(action)
    handler = Handler.get(action)
    handler.add_predicate(lambda: not was_invoked(action_id))
    handler.add_post_callback(partial(mark_invoked, action_id))
    return action
Ejemplo n.º 3
0
def only_once(action=None):
    """
    .. deprecated:: 0.5.0
       Use :func:`when_not` in combination with :func:`set_state` instead. This
       handler is deprecated because it might actually be
       `called multiple times <https://github.com/juju-solutions/charms.reactive/issues/22>`_.

    Register the decorated function to be run once, and only once.

    This decorator will never cause arguments to be passed to the handler.
    """
    if action is None:
        # allow to be used as @only_once or @only_once()
        return only_once

    action_id = _action_id(action)
    handler = Handler.get(action)
    handler.add_predicate(lambda: not was_invoked(action_id))
    handler.add_post_callback(partial(mark_invoked, action_id))
    return action
Ejemplo n.º 4
0
Archivo: ovn.py Proyecto: satva/ovn4nfv
def sign_and_send(mconfig):
    data = mconfig.get_worker_data()
    central_ip = get_my_ip()
    master_hostname = run_command('hostname')

    signed_certs = {}
    for unit in data:
        worker_hostname = unit['worker_hostname']

        if not was_invoked(worker_hostname):
            mark_invoked(worker_hostname)
            cert = unit['cert_to_sign']
            worker_subnet = get_worker_subnet()

            os.chdir('/tmp/')
            cert_file = open('/tmp/ovncontroller-req.pem', 'w+')
            cert_file.truncate(0)
            cert_file.seek(0, 0)
            cert_file.write(cert)
            cert_file.close()
            run_command(
                'sudo ovs-pki -d /certs/pki -b sign ovncontroller switch --force'
            )

            cert_file = open('ovncontroller-cert.pem', 'r')
            signed_cert = cert_file.read()

            signed_certs[worker_hostname] = {
                "central_ip": central_ip,
                "signed_cert": signed_cert,
                "master_hostname": master_hostname,
                "worker_hostname": worker_hostname,
                "worker_subnet": worker_subnet,
            }

    mconfig.send_signed_certs(signed_certs)
Ejemplo n.º 5
0
def only_once(handler_id):
    """
    Check if handler has already been run in the past.
    """
    return not helpers.was_invoked(handler_id)
Ejemplo n.º 6
0
 def wrapper(*args, **kwargs):
     action_id = _action_id(action)
     if not was_invoked(action_id):
         action(*args, **kwargs)
         mark_invoked(action_id)