def do_user_get(kclient, args):
    """Display user details."""
    if args.by_name:
        user = kclient.users.get_by_name(args.id)
    else:
        user = kclient.users.get(args.id)
    utils.print_dict(user._info)
Exemplo n.º 2
0
def do_quota_create(kc, args):
    """Create quota."""
    quota = kc.quotas.create(user_id=args.user_id,
                             project_id=args.tenant_id,
                             resource_id=args.resource_id,
                             limit=args.limit)
    utils.print_dict(quota._info)
def do_tenant_create(kc, args):
    """Create new tenant."""
    tenant = kc.tenants.create(args.name,
                               description=args.description,
                               parent_project_id=args.parent_project_id,
                               enabled=strutils.bool_from_string(args.enabled))
    utils.print_dict(tenant._info)
Exemplo n.º 4
0
def do_tenant_create(kc, args):
    """Create new tenant"""
    tenant = kc.tenants.create(args.name,
                               description=args.description,
                               enabled=utils.string_to_bool(args.enabled),
                               props=args.props)
    utils.print_dict(tenant._info)
Exemplo n.º 5
0
def do_quota_create(kc, args):
    """Create quota."""
    quota = kc.quotas.create(user_id=args.user_id,
                             project_id=args.tenant_id,
                             resource_id=args.resource_id,
                             limit=args.limit)
    utils.print_dict(quota._info)
def do_user_create(kc, args):
    user = kc.users.create(args.username,
                           args.password,
                           args.email,
                           tenant_id=args.default_tenant,
                           enabled=args.enabled)
    utils.print_dict(user._info)
def do_tenant_get(kclient, args):
    """Display tenant details"""
    if args.by_name:
        tenant = kclient.tenants.get_by_name(args.id)
    else:
        tenant = kclient.tenants.get(args.id)
    utils.print_dict(tenant._info)
def do_tenant_create(kc, args):
    """Create new tenant."""
    tenant = kc.tenants.create(args.name,
                               description=args.description,
                               parent_project_id=args.parent_project_id,
                               enabled=strutils.bool_from_string(args.enabled))
    utils.print_dict(tenant._info)
Exemplo n.º 9
0
def do_user_create(kc, args):
    """Create new user"""
    user = kc.users.create(args.name,
                           args.passwd,
                           args.email,
                           tenant_id=args.tenant_id,
                           enabled=utils.string_to_bool(args.enabled))
    utils.print_dict(user._info)
Exemplo n.º 10
0
def do_catalog(kc, args):
    """List service catalog, possibly filtered by service."""
    endpoints = kc.service_catalog.get_endpoints(service_type=args.service)
    for (service, service_endpoints) in six.iteritems(endpoints):
        if len(service_endpoints) > 0:
            print("Service: %s" % service)
            for ep in service_endpoints:
                utils.print_dict(ep)
Exemplo n.º 11
0
def do_catalog(kc, args):
    """List service catalog, possibly filtered by service."""
    endpoints = kc.service_catalog.get_endpoints(service_type=args.service)
    for (service, service_endpoints) in six.iteritems(endpoints):
        if len(service_endpoints) > 0:
            print(_("Service: %s") % service)
            for ep in service_endpoints:
                utils.print_dict(ep)
Exemplo n.º 12
0
def do_ec2_credentials_get(kc, args):
    """Display EC2-compatible credentials."""
    if not args.user_id:
        # use the authenticated user id as a default
        args.user_id = kc.auth_user_id
    cred = kc.ec2.get(args.user_id, args.access)
    if cred:
        utils.print_dict(cred._info)
Exemplo n.º 13
0
def do_endpoint_create(kc, args):
    """Create a new endpoint associated with a service"""
    endpoint = kc.endpoints.create(args.region,
                                   args.service_id,
                                   args.publicurl,
                                   args.adminurl,
                                   args.internalurl)
    utils.print_dict(endpoint._info)
Exemplo n.º 14
0
def do_endpoint_create(kc, args):
    """Create a new endpoint associated with a service"""
    endpoint = kc.endpoints.create(args.region,
                                   args.service_id,
                                   args.publicurl,
                                   args.adminurl,
                                   args.internalurl)
    utils.print_dict(endpoint._info)
Exemplo n.º 15
0
def do_ec2_credentials_get(kc, args):
    """Display EC2-compatible credentials."""
    if not args.user_id:
        # use the authenticated user id as a default
        args.user_id = kc.auth_user_id
    cred = kc.ec2.get(args.user_id, args.access)
    if cred:
        utils.print_dict(cred._info)
Exemplo n.º 16
0
def do_endpoint_create(kc, args):
    """Create a new endpoint associated with a service."""
    service_id = utils.find_resource(kc.services, args.service).id
    endpoint = kc.endpoints.create(args.region,
                                   service_id,
                                   args.publicurl,
                                   args.adminurl,
                                   args.internalurl)
    utils.print_dict(endpoint._info)
Exemplo n.º 17
0
def do_endpoint_create(kc, args):
    """Create a new endpoint associated with a service."""
    service_id = utils.find_resource(kc.services, args.service).id
    endpoint = kc.endpoints.create(args.region,
                                   service_id,
                                   args.publicurl,
                                   args.adminurl,
                                   args.internalurl)
    utils.print_dict(endpoint._info)
Exemplo n.º 18
0
 def test_print_dict_unicode(self):
     name = u'\u540d\u5b57'
     utils.print_dict({'name': name})
     output = self.stdout.getvalue()
     # In Python 2, output will be bytes, while in Python 3, it will not.
     # Let's decode the value if needed.
     if isinstance(output, six.binary_type):
         output = output.decode('utf-8')
     self.assertIn(name, output)
Exemplo n.º 19
0
def do_ec2_credentials_create(kc, args):
    """Create EC2-compatible credentials for user per tenant."""
    if not args.tenant_id:
        # use the authenticated tenant id as a default
        args.tenant_id = kc.auth_tenant_id
    if not args.user_id:
        # use the authenticated user id as a default
        args.user_id = kc.auth_user_id
    credentials = kc.ec2.create(args.user_id, args.tenant_id)
    utils.print_dict(credentials._info)
Exemplo n.º 20
0
def do_ec2_credentials_create(kc, args):
    """Create EC2-compatible credentials for user per tenant."""
    if not args.tenant_id:
        # use the authenticated tenant id as a default
        args.tenant_id = kc.auth_tenant_id
    if not args.user_id:
        # use the authenticated user id as a default
        args.user_id = kc.auth_user_id
    credentials = kc.ec2.create(args.user_id, args.tenant_id)
    utils.print_dict(credentials._info)
Exemplo n.º 21
0
def do_policy_create(kc, args):
    """Create new user"""
    import json
    try:
        with open(args.policy,"r") as f:
            blob = json.load(f,object_hook=utils.convert)
    except IOError as e:
        print "I/O error({0}): {1}".format(e.errno, e.strerror)
    policy = kc.policies.create(json.dumps(blob), args.service_id,args.type)
    utils.print_dict(policy._info,100)
Exemplo n.º 22
0
def do_tenant_create(kc, args):
    """Create new tenant"""
    domain_id = args.domain_id
    if not domain_id:
        domain = utils.find_resource(kc.domains, kc.project_domain_name)
        domain_id = domain.id
    tenant = kc.projects.create(args.name,
                                domain_id,
                                description=args.description,
                                enabled=utils.string_to_bool(args.enabled))
    utils.print_dict(tenant._info)
Exemplo n.º 23
0
def do_user_create(kc, args):
    """Create new user"""
    domain_id = args.domain_id
    if not domain_id:
        domain = utils.find_resource(kc.domains, kc.project_domain_name)
        domain_id = domain.id
    user = kc.users.create(name=args.name, password=args.passwd,
                           email=args.email,
                           project=args.tenant_id, domain=domain_id,
                           enabled=utils.string_to_bool(args.enabled))
    utils.print_dict(user._info)
Exemplo n.º 24
0
def do_tenant_create(kc, args):
    """Create new tenant"""
    domain_id = args.domain_id
    if not domain_id:
        domain = utils.find_resource(kc.domains, kc.project_domain_name)
        domain_id = domain.id
    tenant = kc.projects.create(args.name,
                                domain_id,
                                description=args.description,
                                enabled=utils.string_to_bool(args.enabled))
    utils.print_dict(tenant._info)
Exemplo n.º 25
0
def do_user_create(kc, args):
    """Create new user"""
    if args.tenant:
        tenant_id = utils.find_resource(kc.tenants, args.tenant).id
    elif args.tenant_id:
        tenant_id = args.tenant_id
    else:
        tenant_id = None
    user = kc.users.create(args.name, args.passwd, args.email,
                           tenant_id=tenant_id,
                           enabled=utils.string_to_bool(args.enabled))
    utils.print_dict(user._info)
Exemplo n.º 26
0
def do_user_create(kc, args):
    """Create new user"""
    if args.tenant:
        tenant_id = utils.find_resource(kc.tenants, args.tenant).id
    elif args.tenant_id:
        tenant_id = args.tenant_id
    else:
        tenant_id = None
    user = kc.users.create(args.name, args.passwd, args.email,
                           tenant_id=tenant_id,
                           enabled=utils.string_to_bool(args.enabled))
    utils.print_dict(user._info)
Exemplo n.º 27
0
def do_endpoint_get(kc, args):
    """Find endpoint filtered by a specific attribute or service type."""
    kwargs = {"service_type": args.service, "endpoint_type": args.endpoint_type}

    if args.attr and args.value:
        kwargs.update({"attr": args.attr, "filter_value": args.value})
    elif args.attr or args.value:
        print("Both --attr and --value required.")
        return

    url = kc.service_catalog.url_for(**kwargs)
    utils.print_dict({"%s.%s" % (args.service, args.endpoint_type): url})
Exemplo n.º 28
0
def do_user_create(kc, args):
    """Create new user"""
    domain_id = args.domain_id
    if not domain_id:
        domain = utils.find_resource(kc.domains, kc.project_domain_name)
        domain_id = domain.id
    user = kc.users.create(name=args.name,
                           password=args.passwd,
                           email=args.email,
                           project=args.tenant_id,
                           domain=domain_id,
                           enabled=utils.string_to_bool(args.enabled))
    utils.print_dict(user._info)
Exemplo n.º 29
0
def do_domain_update(kc, args):
    """Update a domain name, description or/and enabled status."""
    kwargs = {}
    if args.name:
        kwargs['name'] = args.name
    if args.description:
        kwargs['description'] = args.description
    if args.enabled:
        kwargs['enabled'] = utils.string_to_bool(args.enabled)
    if not len(kwargs):
        print "Domain not updated, no arguments present."
        return
    domain = utils.find_resource(kc.domains, args.domain)
    updt_domain = kc.domains.update(domain=domain, **kwargs)
    utils.print_dict(updt_domain._info)
Exemplo n.º 30
0
def do_domain_update(kc, args):
    """Update a domain name, description or/and enabled status."""
    kwargs = {}
    if args.name:
        kwargs['name'] = args.name
    if args.description:
        kwargs['description'] = args.description
    if args.enabled:
        kwargs['enabled'] = utils.string_to_bool(args.enabled)
    if not len(kwargs):
        print "Domain not updated, no arguments present."
        return
    domain = utils.find_resource(kc.domains, args.domain)
    updt_domain = kc.domains.update(domain=domain, **kwargs)
    utils.print_dict(updt_domain._info)
Exemplo n.º 31
0
def do_endpoint_get(kc, args):
    """Find endpoint filtered by a specific attribute or service type."""
    kwargs = {
        'service_type': args.service,
        'endpoint_type': args.endpoint_type,
    }

    if args.attr and args.value:
        kwargs.update({'attr': args.attr, 'filter_value': args.value})
    elif args.attr or args.value:
        print(_('Both --attr and --value required.'))
        return

    url = kc.service_catalog.url_for(**kwargs)
    utils.print_dict({'%s.%s' % (args.service, args.endpoint_type): url})
Exemplo n.º 32
0
def do_endpoint_get(kc, args):
    """Find endpoint filtered by a specific attribute or service type."""
    kwargs = {
        'service_type': args.service,
        'endpoint_type': args.endpoint_type,
    }

    if args.attr and args.value:
        kwargs.update({'attr': args.attr, 'filter_value': args.value})
    elif args.attr or args.value:
        print('Both --attr and --value required.')
        return

    url = kc.service_catalog.url_for(**kwargs)
    utils.print_dict({'%s.%s' % (args.service, args.endpoint_type): url})
Exemplo n.º 33
0
def do_user_create(kc, args):
    """Create new user."""
    if args.tenant:
        tenant_id = utils.find_resource(kc.tenants, args.tenant).id
    elif args.tenant_id:
        tenant_id = args.tenant_id
    else:
        tenant_id = None
    new_passwd = args.passwd
    if args.passwd is ASK_FOR_PASSWORD:
        new_passwd = utils.prompt_for_password()
    user = kc.users.create(args.name, new_passwd, args.email,
                           tenant_id=tenant_id,
                           enabled=strutils.bool_from_string(args.enabled))
    utils.print_dict(user._info)
Exemplo n.º 34
0
def do_user_create(kc, args):
    """Create new user"""
    if args.tenant:
        tenant_id = utils.find_resource(kc.tenants, args.tenant).id
    elif args.tenant_id:
        tenant_id = args.tenant_id
    else:
        tenant_id = None
    new_passwd = args.passwd
    if args.passwd is ASK_FOR_PASSWORD:
        new_passwd = utils.prompt_for_password()
    user = kc.users.create(args.name,
                           new_passwd,
                           args.email,
                           tenant_id=tenant_id,
                           enabled=strutils.bool_from_string(args.enabled))
    utils.print_dict(user._info)
Exemplo n.º 35
0
def do_service_get(kc, args):
    """Display service from Service Catalog"""
    service = kc.services.get(args.id)
    utils.print_dict(service._info)
Exemplo n.º 36
0
def do_token_get(kc, args):
    """Display the current user token."""
    utils.print_dict(kc.service_catalog.get_token(), wrap=int(args.wrap))
Exemplo n.º 37
0
def do_user_create(kc, args):
    """Create new user"""
    user = kc.users.create(args.name, args.passwd, args.email,
                           tenant_id=args.tenant_id, enabled=args.enabled)
    utils.print_dict(user._info)
Exemplo n.º 38
0
def do_role_get(kc, args):
    """Display role details"""
    role = kc.roles.get(args.id)
    utils.print_dict(role._info)
Exemplo n.º 39
0
def do_role_create(kc, args):
    """Create new role."""
    role = kc.roles.create(args.name)
    utils.print_dict(role._info)
Exemplo n.º 40
0
def do_tenant_get(kc, args):
    """Display tenant details"""
    tenant = kc.tenants.get(args.id)
    utils.print_dict(tenant._info)
Exemplo n.º 41
0
def do_service_get(kc, args):
    """Display service from Service Catalog."""
    service = utils.find_resource(kc.services, args.service)
    utils.print_dict(service._info)
Exemplo n.º 42
0
def do_service_get(kc, args):
    service = kc.services.get(args.id)
    utils.print_dict(service._info)
Exemplo n.º 43
0
def do_tenant_get(kc, args):
    """Display tenant details."""
    tenant = utils.find_resource(kc.tenants, args.tenant)
    utils.print_dict(tenant._info)
Exemplo n.º 44
0
def do_service_create(kc, args):
    """Add service to Service Catalog."""
    service = kc.services.create(args.name, args.type, args.description)
    utils.print_dict(service._info)
Exemplo n.º 45
0
def do_tenant_create(kc, args):
    tenant = kc.tenants.create(args.tenant_name,
                               description=args.description,
                               enabled=args.enabled)
    utils.print_dict(tenant._info)
Exemplo n.º 46
0
def do_user_get(kc, args):
    """Display user details."""
    user = utils.find_resource(kc.users, args.user)
    utils.print_dict(user._info)
Exemplo n.º 47
0
def do_token_get(kc, args):
    """Display the current user token."""
    utils.print_dict(kc.service_catalog.get_token(),
                     wrap=int(args.wrap))
Exemplo n.º 48
0
def do_user_get(kc, args):
    """Display user details."""
    user = utils.find_resource(kc.users, args.user)
    utils.print_dict(user._info)
Exemplo n.º 49
0
def do_role_get(kc, args):
    """Display role details."""
    role = utils.find_resource(kc.roles, args.role)
    utils.print_dict(role._info)
Exemplo n.º 50
0
def do_role_create(kc, args):
    """Create new role."""
    role = kc.roles.create(args.name)
    utils.print_dict(role._info)
Exemplo n.º 51
0
def do_role_create(kc, args):
    role = kc.roles.create(args.role_name)
    utils.print_dict(role._info)
Exemplo n.º 52
0
def do_service_create(kc, args):
    service = kc.services.create(args.service_name, args.service_type,
                                 args.description)
    utils.print_dict(service._info)
Exemplo n.º 53
0
def do_tenant_get(kc, args):
    """Display tenant details."""
    tenant = utils.find_resource(kc.tenants, args.tenant)
    utils.print_dict(tenant._info)
Exemplo n.º 54
0
def do_role_get(kc, args):
    role = kc.roles.get(args.id)
    utils.print_dict(role._info)
Exemplo n.º 55
0
def do_service_create(kc, args):
    """Add service to Service Catalog."""
    service = kc.services.create(args.name,
                                 args.type,
                                 args.description)
    utils.print_dict(service._info)
Exemplo n.º 56
0
def do_ec2_create_credentials(kc, args):
    credentials = kc.ec2.create(args.user_id, args.tenant_id)
    utils.print_dict(credentials._info)
Exemplo n.º 57
0
def do_service_get(kc, args):
    """Display service from Service Catalog."""
    service = utils.find_resource(kc.services, args.service)
    utils.print_dict(service._info)
Exemplo n.º 58
0
def do_user_update_email(kc, args):
    user = kc.users.update_email(args.id, args.email)
    utils.print_dict(user._info)
Exemplo n.º 59
0
def do_role_get(kc, args):
    """Display role details."""
    role = utils.find_resource(kc.roles, args.role)
    utils.print_dict(role._info)