def do_user_role_list(kc, args): """List roles granted to a user.""" if args.tenant: tenant_id = utils.find_resource(kc.tenants, args.tenant).id elif args.tenant_id: tenant_id = args.tenant_id else: # use the authenticated tenant id as a default tenant_id = kc.auth_tenant_id if args.user: user_id = utils.find_resource(kc.users, args.user).id elif args.user_id: user_id = args.user_id else: # use the authenticated user id as a default user_id = kc.auth_user_id roles = kc.roles.roles_for_user(user=user_id, tenant=tenant_id) # this makes the command output a bit more intuitive for role in roles: role.user_id = user_id role.tenant_id = tenant_id utils.print_list(roles, ['id', 'name', 'user_id', 'tenant_id'], order_by='name')
def test_print_list_unicode(self): name = u"\u540d\u5b57" objs = [FakeObject(name)] # NOTE(Jeffrey4l) If the text's encode is proper, this method will not # raise UnicodeEncodeError exceptions utils.print_list(objs, ["name"]) self.assertIn(name, self.stdout.getvalue().decode("utf8"))
def do_user_list(kc, args): """List users.""" if args.tenant: tenant_id = utils.find_resource(kc.tenants, args.tenant).id else: tenant_id = None users = kc.users.list(tenant_id=tenant_id) utils.print_list(users, ["id", "name", "enabled", "email"], order_by="name")
def do_user_list(kc, args): """List users.""" if args.tenant: tenant_id = utils.find_resource(kc.tenants, args.tenant).id else: tenant_id = None users = kc.users.list(tenant_id=tenant_id) utils.print_list(users, ['id', 'name', 'enabled', 'email'], order_by='name')
def test_print_list_unicode(self): name = u'\u540d\u5b57' objs = [FakeObject(name)] # NOTE(Jeffrey4l) If the text's encode is proper, this method will not # raise UnicodeEncodeError exceptions utils.print_list(objs, ['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)
def do_role_list(kc, args): """List all roles, or only those granted to a user.""" if bool(args.tenant_id) ^ bool(args.user): print 'User ID and Tenant ID are both required to list granted roles.' return if args.tenant_id and args.user: roles = kc.roles.roles_for_user(user=args.user, tenant=args.tenant_id) else: roles = kc.roles.list() utils.print_list(roles, ['id', 'name'])
def do_ec2_credentials_list(kc, args): """List EC2-compatible credentials for a user.""" if not args.user_id: # use the authenticated user id as a default args.user_id = kc.auth_user_id credentials = kc.ec2.list(args.user_id) for cred in credentials: try: cred.tenant = getattr(kc.tenants.get(cred.tenant_id), 'name') except Exception: # FIXME(dtroyer): Retrieving the tenant name fails for normal # users; stuff in the tenant_id instead. cred.tenant = cred.tenant_id utils.print_list(credentials, ['tenant', 'access', 'secret'])
def do_ec2_credentials_list(kc, args): """List EC2-compatibile credentials for a user""" if not args.user: # use the authenticated user id as a default args.user = kc.auth_user_id credentials = kc.ec2.list(args.user) for cred in credentials: try: cred.tenant = getattr(kc.tenants.get(cred.tenant_id), "name") except: # FIXME(dtroyer): Retrieving the tenant name fails for normal # users; stuff in the tenant_id instead. cred.tenant = cred.tenant_id utils.print_list(credentials, ["tenant", "access", "secret"])
def do_user_role_list(kc, args): """List roles granted to a user""" 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 roles = kc.roles.roles_for_user(user=args.user_id, tenant=args.tenant_id) # this makes the command output a bit more intuitive for role in roles: role.user_id = args.user_id role.tenant_id = args.tenant_id utils.print_list(roles, ['id', 'name', 'user_id', 'tenant_id'])
def do_endpoint_list(kc, args): """List configured service endpoints.""" endpoints = kc.endpoints.list() utils.print_list(endpoints, ["id", "region", "publicurl", "internalurl", "adminurl", "service_id"])
def do_service_list(kc, args): """List all services in Service Catalog.""" services = kc.services.list() utils.print_list(services, ["id", "name", "type", "description"], order_by="name")
def do_role_list(kc, args): """List all roles.""" roles = kc.roles.list() utils.print_list(roles, ["id", "name"], order_by="name")
def do_project_quota_list(kc, args): """List quotas.""" quotas = kc.quotas.list_project_quotas(project_id=args.tenant_id) utils.print_list(quotas, ['id', 'name', 'limit'], order_by='name')
#!/usr/bin/python from keystoneclient.v2_0 import client from keystoneclient import utils keystone = client.Client(token="token", endpoint="http://<controller_ip>:35357/v2.0" ) tenants = keystone.tenants.list() utils.print_list(tenants, ['id', 'name', 'enabled'], order_by='name')
def do_user_tenant_list(kc, args): """List all tenants""" tenants = kc.tenants.list(management=False) utils.print_list(tenants, ['id', 'name', 'enabled'])
def do_role_list(kc, args): """List all roles.""" roles = kc.roles.list() utils.print_list(roles, ['id', 'name'], order_by='name')
def do_user_list(kc, args): """List users""" users = kc.users.list(tenant_id=args.tenant_id) utils.print_list(users, ['id', 'name', 'enabled', 'email'], order_by='name')
def do_service_list(kc, args): """List all services in Service Catalog.""" services = kc.services.list() utils.print_list(services, ['id', 'name', 'type', 'description'], order_by='name')
def do_policy_list(kc, args): """Display Policies associated with a tenant""" policies = kc.policies.list() utils.print_list(policies, ['id', 'type', 'service_id'], order_by='id')
kc.roles.delete(args.id) print 'Role has been deleted.' except: print 'Unable to delete role.' @utils.arg('id', metavar='<user_id>', help='ID of User', nargs='?') def do_user_roles(kc, args): roles = kc.roles.get_user_role_refs(args.id) for role in roles: try: role.tenant = kc.tenants.get(role.tenantId).name except Exception, e: role.tenant = 'n/a' role.name = kc.roles.get(role.roleId).name utils.print_list(roles, ['tenant', 'name']) # TODO(jakedahn): refactor this to allow role, user, and tenant names. @utils.arg('tenant_id', metavar='<tenant_id>', help='ID of Tenant', nargs='?') @utils.arg('user_id', metavar='<user_id>', help='ID of User', nargs='?') @utils.arg('role_id', metavar='<role_id>', help='ID of Role', nargs='?') def do_user_add_tenant_role(kc, args): kc.roles.add_user_to_tenant(args.tenant_id, args.user_id, args.role_id) # TODO(jakedahn): refactor this to allow role, user, and tenant names. @utils.arg('tenant_id', metavar='<tenant_id>', help='ID of Tenant', nargs='?') @utils.arg('user_id', metavar='<user_id>', help='ID of User', nargs='?') @utils.arg('role_id', metavar='<role_id>', help='ID of Role', nargs='?') def do_user_remove_tenant_role(kc, args):
def do_ec2_list_credentials(kc, args): credentials = kc.ec2.list(args.user_id) for cred in credentials: cred.tenant = kc.tenants.get(cred.tenant_id).name utils.print_list(credentials, ['tenant', 'key', 'secret'])
def do_role_list(kc, args): roles = kc.roles.list() utils.print_list(roles, ['id', 'name'])
def do_service_list(kc, args): services = kc.services.list() utils.print_list(services, ['id', 'name', 'type', 'description'])
def do_quota_list(kc, args): """List quotas.""" quotas = kc.quotas.list(user_id=args.user_id, project_id=args.tenant_id) utils.print_list(quotas, ['id', 'resource_name', 'limit'], order_by='resource_name')
def do_resource_list(kc, args): """List resources.""" resources = kc.resources.list() utils.print_list(resources, ['id', 'name', 'description', 'default_limit'], order_by='name')
def do_endpoint_list(kc, args): """List configured service endpoints.""" endpoints = kc.endpoints.list() utils.print_list(endpoints, ['id', 'region', 'publicurl', 'internalurl', 'adminurl', 'service_id'])
def do_tenant_list(kc, args): """List all tenants.""" tenants = kc.tenants.list() utils.print_list(tenants, ['id', 'name', 'enabled'], order_by='name')
#!/usr/bin/python from keystoneclient.v2_0 import client from keystoneclient import utils keystone = client.Client(username="******", password="******", tenant_name="admin", auth_url="http://<controller_ip>:5000/v2.0" ) roles = keystone.roles.list() utils.print_list(roles, ['id', 'name'], order_by='name')
def do_user_list(kc, args): """List users""" users = kc.users.list(tenant_id=args.tenant) utils.print_list(users, ['id', 'enabled', 'email', 'name'])
def do_endpoint_list(kc, args): """List configured service endpoints.""" endpoints = kc.endpoints.list() utils.print_list( endpoints, ['id', 'region', 'publicurl', 'internalurl', 'adminurl', 'service_id'])
def do_user_quota_list(kc, args): """List quotas.""" quotas = kc.quotas.list_user_quotas(user_id=args.user_id) utils.print_list(quotas, ['id', 'name', 'limit'], order_by='name')
def do_domain_list(kc, args): """List domains""" domains = kc.domains.list() utils.print_list(domains, ['id', 'name', 'enabled', 'description'], order_by='name')
def do_endpoint_list(kc, args): """List configured service endpoints""" endpoints = kc.endpoints.list() utils.print_list(endpoints, ['id', 'region', 'interface', 'url', 'service_id'])
#!/usr/bin/python from keystoneclient.v2_0 import client from keystoneclient import utils keystone = client.Client(username="******", password="******", tenant_name="admin", auth_url="http://<controller_ip>:5000/v2.0" ) users = keystone.users.list() utils.print_list(users, ['id', 'name', 'enabled','email'], order_by='name')
def do_tenant_list(kc, args): """List all tenants.""" tenants = kc.tenants.list() utils.print_list(tenants, ["id", "name", "enabled"], order_by="name")
def do_user_list(kc, args): users = kc.users.list(tenant_id=args.tenant) utils.print_list(users, ['id', 'enabled', 'email', 'name', 'tenantId'])
def do_tenant_list(kc, args): """List all tenants""" tenants = kc.projects.list() utils.print_list(tenants, ['id', 'name', 'enabled', 'description'], order_by='name')