Exemplo n.º 1
0
def role(cmd_proc, operation):
    """Operations with Roles"""
    if cmd_proc.vca.service_type != VCA.VCA_SERVICE_TYPE_VCA:
        utils.print_message('Operation not supported '
                            'in this service type')
        sys.exit(1)
    result = cmd_proc.re_login()
    if not result:
        utils.print_error('Not logged in', cmd_proc)
        sys.exit(1)
    if 'list' == operation:
        headers = ['Role Name', 'Description', 'Permissions']
        table = []
        for r in cmd_proc.vca.get_roles():
            permissions = []
            if len(r.get('rights')) > 0:
                for p in r.get('rigths'):
                    permissions.append(str(p.get('name')))
            table.append([r.get('name'),
                          r.get('description'),
                          utils.beautified(permissions)])
        sorted_table = sorted(table, key=operator.itemgetter(0), reverse=False)
        utils.print_table("Available roles in instance '%s'"
                          ", profile '%s':" %
                          (cmd_proc.instance, cmd_proc.profile),
                          headers, sorted_table,
                          cmd_proc)
    cmd_proc.save_current_config()
Exemplo n.º 2
0
def user(cmd_proc, operation, username, user_id, password, new_password,
         first_name, last_name, roles, token):
    """Operations with Users"""
    if cmd_proc.vca.service_type != VCA.VCA_SERVICE_TYPE_VCA:
        utils.print_error('Operation not supported '
                          'in this service type')
        sys.exit(1)
    result = cmd_proc.re_login()
    if not result:
        utils.print_error('Not logged in', cmd_proc)
        sys.exit(1)
    try:
        if 'list' == operation:
            headers = ['User Name', 'First', 'Last', 'Email', 'State', 'Id',
                       'Roles']
            table = []
            for u in cmd_proc.vca.get_users():
                roles = []
                for r in u.get('roles').get('roles'):
                    roles.append(str(r.get('name')))
                table.append([u.get('userName'), u.get('givenName'),
                              u.get('familyName'), u.get('email'),
                              u.get('state'),
                              u.get('id'),
                              utils.beautified(roles)])
            sorted_table = sorted(table, key=operator.itemgetter(0),
                                  reverse=False)
            utils.print_table("Available users in instance '%s'"
                              ", profile '%s':" %
                              (cmd_proc.instance, cmd_proc.profile),
                              headers, sorted_table,
                              cmd_proc)
        elif 'info' == operation:
            cmd_proc.error_message = 'not implemented'
            sys.exit(1)
        elif 'create' == operation:
            roles_array = roles.split(',')
            result = cmd_proc.vca.add_user(username, first_name,
                                           last_name, roles_array)
            utils.print_message("User '%s' successfully created" % username)
        elif 'delete' == operation:
            result = cmd_proc.vca.del_user(user_id)
            utils.print_message("Successfully deleted user '%s'" %
                                cmd_proc.vca.username)
        elif 'change-password' == operation:
            result = cmd_proc.vca.change_password(password, new_password)
            utils.print_message("Successfully changed password for user '%s'"
                                % cmd_proc.vca.username)
        elif 'validate' == operation:
            result = cmd_proc.vca.validate_user(username, password, token)
            print result
        elif 'reset-password' == operation:
            result = cmd_proc.vca.reset_password(user_id)
            utils.print_message("Successfully reset password for user id"
                                "'%s', check email to enter new password"
                                % user_id)
    except:
        utils.print_error('An error has ocurred', cmd_proc)
        sys.exit(1)
    cmd_proc.save_current_config()
Exemplo n.º 3
0
def role(cmd_proc, operation):
    """Operations with Roles"""
    if cmd_proc.vca.service_type != VCA.VCA_SERVICE_TYPE_VCA:
        utils.print_message('Operation not supported ' 'in this service type')
        sys.exit(1)
    result = cmd_proc.re_login()
    if not result:
        utils.print_error('Not logged in', cmd_proc)
        sys.exit(1)
    if 'list' == operation:
        headers = ['Role Name', 'Description', 'Permissions']
        table = []
        for r in cmd_proc.vca.get_roles():
            permissions = []
            if len(r.get('rights')) > 0:
                for p in r.get('rigths'):
                    permissions.append(str(p.get('name')))
            table.append([
                r.get('name'),
                r.get('description'),
                utils.beautified(permissions)
            ])
        sorted_table = sorted(table, key=operator.itemgetter(0), reverse=False)
        utils.print_table(
            "Available roles in instance '%s'"
            ", profile '%s':" % (cmd_proc.instance, cmd_proc.profile), headers,
            sorted_table, cmd_proc)
    cmd_proc.save_current_config()
Exemplo n.º 4
0
def print_deployment_info(deployment, executions, events, execution_id,
                          ctx=None):
    headers = ['Blueprint Id', 'Deployment Id', 'Created', 'Workflows']
    table = []
    workflows = []
    for workflow in deployment.get('workflows'):
        workflows.append(workflow.get('name').encode('utf-8'))
    table.append(
        [deployment.get('blueprint_id'), deployment.get('id'),
         deployment.get('created_at')[:-7], utils.beautified(workflows)])
    print_table("Deployment information:\n-----------------------",
                'deployment',
                headers, table, ctx)
    print("\n")
    headers = ['Workflow', 'Created', 'Status', 'Execution Id']
    table = []
    if executions is None or len(executions) == 0:
        utils.print_message('no executions found', ctx)
        return
    for e in executions:
        table.append([e.get('workflow_id'),
                      e.get('created_at')[:-7],
                      e.get('status'), e.get('id')])
    sorted_table = sorted(table, key=operator.itemgetter(1), reverse=False)
    print_table("Workflow executions for deployment: '%s'"
                "\n----------------------------------"
                % deployment.get('id'), 'executions', headers, sorted_table,
                ctx)
    if events:
        headers = ['Type', 'Started', 'Message']
        table = []
        for event in events:
            if isinstance(
                    event, collections.Iterable) and 'event_type' in event:
                table.append(
                    [event.get('event_type'), event.get('timestamp')[:-9],
                     event.get('message').get('text')])
        print('\n')
        print_table("Events for execution id '%s'" %
                    execution_id, 'events',
                    headers, table, ctx)
Exemplo n.º 5
0
def print_deployment_info(deployment, executions, events, ctx=None):
    headers = ['Blueprint Id', 'Deployment Id', 'Created', 'Workflows']
    table = []
    workflows = []
    for workflow in deployment.get('workflows'):
        workflows.append(workflow.get('name').encode('utf-8'))
    table.append(
        [deployment.get('blueprint_id'), deployment.get('id'),
         deployment.get('created_at')[:-7], utils.beautified(workflows)])
    print_table("Deployment information:\n-----------------------",
                'deployment',
                headers, table, ctx)
    print("\n")
    headers = ['Workflow', 'Created', 'Status', 'Id']
    table = []
    if executions is None or len(executions) == 0:
        utils.print_message('no executions found', ctx)
        return
    for e in executions:
        table.append([e.get('workflow_id'),
                      e.get('created_at')[:-7],
                      e.get('status'), e.get('id')])
    sorted_table = sorted(table, key=operator.itemgetter(1), reverse=False)
    print_table("Workflow executions for deployment: '%s'"
                "\n----------------------------------"
                % deployment.get('id'), 'executions', headers, sorted_table,
                ctx)
    if events:
        headers = ['Type', 'Started', 'Message']
        table = []
        for event in events:
            if isinstance(
                    event, collections.Iterable) and 'event_type' in event:
                table.append(
                    [event.get('event_type'), event.get('timestamp'),
                     event.get('message').get('text')])
        print_table("Events for workflow '%s'" %
                    deployment.get('workflow_id'), 'events',
                    headers, table, ctx)
Exemplo n.º 6
0
def print_deployment_info(deployment, executions, events, execution_id, ctx=None):
    headers = ["Blueprint Id", "Deployment Id", "Created", "Workflows"]
    table = []
    workflows = []
    for workflow in deployment.get("workflows"):
        workflows.append(workflow.get("name").encode("utf-8"))
    table.append(
        [
            deployment.get("blueprint_id"),
            deployment.get("id"),
            deployment.get("created_at")[:-7],
            utils.beautified(workflows),
        ]
    )
    print_table("Deployment information:\n-----------------------", "deployment", headers, table, ctx)
    print("\n")
    headers = ["Workflow", "Created", "Status", "Execution Id"]
    table = []
    if executions is None or len(executions) == 0:
        utils.print_message("no executions found", ctx)
        return
    for e in executions:
        table.append([e.get("workflow_id"), e.get("created_at")[:-7], e.get("status"), e.get("id")])
    sorted_table = sorted(table, key=operator.itemgetter(1), reverse=False)
    print_table(
        "Workflow executions for deployment: '%s'" "\n----------------------------------" % deployment.get("id"),
        "executions",
        headers,
        sorted_table,
        ctx,
    )
    if events:
        headers = ["Type", "Started", "Message"]
        table = []
        for event in events:
            if isinstance(event, collections.Iterable) and "event_type" in event:
                table.append([event.get("event_type"), event.get("timestamp")[:-9], event.get("message").get("text")])
        print("\n")
        print_table("Events for execution id '%s'" % execution_id, "events", headers, table, ctx)
Exemplo n.º 7
0
def user(cmd_proc, operation, username, user_id, password, new_password,
         first_name, last_name, roles, token):
    """Operations with Users"""
    if cmd_proc.vca.service_type != VCA.VCA_SERVICE_TYPE_VCA:
        utils.print_error('Operation not supported ' 'in this service type')
        sys.exit(1)
    result = cmd_proc.re_login()
    if not result:
        utils.print_error('Not logged in', cmd_proc)
        sys.exit(1)
    try:
        if 'list' == operation:
            headers = [
                'User Name', 'First', 'Last', 'Email', 'State', 'Id', 'Roles'
            ]
            table = []
            for u in cmd_proc.vca.get_users():
                roles = []
                for r in u.get('roles').get('roles'):
                    roles.append(str(r.get('name')))
                table.append([
                    u.get('userName'),
                    u.get('givenName'),
                    u.get('familyName'),
                    u.get('email'),
                    u.get('state'),
                    u.get('id'),
                    utils.beautified(roles)
                ])
            sorted_table = sorted(table,
                                  key=operator.itemgetter(0),
                                  reverse=False)
            utils.print_table(
                "Available users in instance '%s'"
                ", profile '%s':" % (cmd_proc.instance, cmd_proc.profile),
                headers, sorted_table, cmd_proc)
        elif 'info' == operation:
            cmd_proc.error_message = 'not implemented'
            sys.exit(1)
        elif 'create' == operation:
            roles_array = roles.split(',')
            result = cmd_proc.vca.add_user(username, first_name, last_name,
                                           roles_array)
            utils.print_message("User '%s' successfully created" % username)
        elif 'delete' == operation:
            result = cmd_proc.vca.del_user(user_id)
            utils.print_message("Successfully deleted user '%s'" %
                                cmd_proc.vca.username)
        elif 'change-password' == operation:
            result = cmd_proc.vca.change_password(password, new_password)
            utils.print_message("Successfully changed password for user '%s'" %
                                cmd_proc.vca.username)
        elif 'validate' == operation:
            result = cmd_proc.vca.validate_user(username, password, token)
            print(result)
        elif 'reset-password' == operation:
            result = cmd_proc.vca.reset_password(user_id)
            utils.print_message("Successfully reset password for user id"
                                "'%s', check email to enter new password" %
                                user_id)
    except Exception:
        utils.print_error('An error has ocurred', cmd_proc)
        sys.exit(1)
    cmd_proc.save_current_config()