def wrapper(*args, **kwargs):
     ctx = _find_context_arg(args, kwargs)
     if ctx is None:
         ctx = {}
     if not _is_cloudify_context(ctx):
         ctx = CloudifyContext(ctx)
         kwargs = _inject_argument('ctx', ctx, kwargs)
     try:
         result = func(*args, **kwargs)
     except BaseException as e:
         ctx.logger.error(
             'Exception raised on operation [%s] invocation',
             ctx.task_name, exc_info=True)
         raise e
     ctx.update()
     return result
Beispiel #2
0
def update_provider_context(data):
    ip = data['ip']
    username = data['rest_username']
    password = data['rest_password']
    rest_port = data['rest_port']
    rest_protocol = data['rest_protocol']
    print 'Updating provider context with broker_ip: {}'.format(ip)
    os.environ.update({
        'REST_HOST': ip,
        'REST_PORT': str(rest_port),
        'REST_PROTOCOL': rest_protocol,
        'SECURITY_ENABLED': str(password is not None),
        'VERIFY_REST_CERTIFICATE': '',
    })
    ctx = CloudifyContext({
        'rest_username': username,
        'rest_password': password
    })
    with current_ctx.push(ctx):
        client = get_rest_client()
    for _ in range(1800):
        try:
            context_obj = client.manager.get_context()
            break
        except:
            time.sleep(0.1)
    else:
        raise
    name = context_obj['name']
    context = context_obj['context']
    context['cloudify']['cloudify_agent']['broker_ip'] = ip
    client.manager.update_context(name, context)
 def wrapper(*args, **kwargs):
     ctx = _find_context_arg(args, kwargs, _is_cloudify_context)
     if ctx is None:
         ctx = {}
     if not _is_cloudify_context(ctx):
         ctx = CloudifyContext(ctx)
         kwargs['ctx'] = ctx
     try:
         current_ctx.set(ctx, kwargs)
         result = func(*args, **kwargs)
     except BaseException:
         ctx.logger.error(
             'Exception raised on operation [%s] invocation',
             ctx.task_name, exc_info=True)
         raise
     finally:
         current_ctx.clear()
         ctx.update()
     return result
Beispiel #4
0
def send_task_event(cloudify_context,
                    event_type,
                    message=None,
                    args=None,
                    additional_context=None,
                    out_func=None):
    """Send a task event to RabbitMQ

    :param cloudify_context: a __cloudify_context struct as passed to
                             operations
    :param event_type: The event type
    :param message: The message
    :param args: additional arguments that may be added to the message
    :param additional_context: additional context to be added to the context
    """
    # import here to avoid cyclic dependencies
    from cloudify.context import CloudifyContext
    _send_event(CloudifyContext(cloudify_context), 'task', event_type, message,
                args, additional_context, out_func)