当前位置: 首页>>代码示例>>Python>>正文


Python UserRoleAPI.role_by_name方法代码示例

本文整理汇总了Python中katello.client.api.user_role.UserRoleAPI.role_by_name方法的典型用法代码示例。如果您正苦于以下问题:Python UserRoleAPI.role_by_name方法的具体用法?Python UserRoleAPI.role_by_name怎么用?Python UserRoleAPI.role_by_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在katello.client.api.user_role.UserRoleAPI的用法示例。


在下文中一共展示了UserRoleAPI.role_by_name方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: UserRoleAction

# 需要导入模块: from katello.client.api.user_role import UserRoleAPI [as 别名]
# 或者: from katello.client.api.user_role.UserRoleAPI import role_by_name [as 别名]
class UserRoleAction(BaseAction):

    def __init__(self):
        super(UserRoleAction, self).__init__()
        self.api = UserRoleAPI()

    def get_role(self, name):
        role = self.api.role_by_name(name)
        if role == None:
            system_exit(os.EX_DATAERR, _("Cannot find user role '%s'") % name )
        return role
开发者ID:AdamSaleh,项目名称:katello,代码行数:13,代码来源:user_role.py

示例2: AssignRole

# 需要导入模块: from katello.client.api.user_role import UserRoleAPI [as 别名]
# 或者: from katello.client.api.user_role.UserRoleAPI import role_by_name [as 别名]
class AssignRole(UserAction):

    @property
    def description(self):
        if self.__assign:
            return _('assign role to a user')
        else:
            return _('unassign role to a user')

    def assign(self):
        return self.__assign

    def __init__(self, assign = True):
        super(AssignRole, self).__init__()
        self.role_api = UserRoleAPI()

        self.__assign = assign

    def setup_parser(self):
        self.parser.add_option('--username', dest='username', help=_("user name (required)"))
        self.parser.add_option('--role', dest='role', help=_("user role (required)"))

    def check_options(self):
        self.require_option('username')
        self.require_option('role')

    def run(self):
        userName = self.get_option('username')
        roleName = self.get_option('role')

        user = get_user(userName)
        if user == None:
            return os.EX_DATAERR

        role = self.role_api.role_by_name(roleName)
        if role == None:
            print _("Role [ %s ] not found" % roleName)
            return os.EX_DATAERR

        msg = self.update_role(user['id'], role['id'])
        print msg
        return os.EX_OK

    def update_role(self, userId, roleId):
        if self.assign():
            return self.api.assign_role(userId, roleId)
        else:
            return self.api.unassign_role(userId, roleId)
开发者ID:ohadlevy,项目名称:katello,代码行数:50,代码来源:user.py

示例3: KatelloConnection

# 需要导入模块: from katello.client.api.user_role import UserRoleAPI [as 别名]
# 或者: from katello.client.api.user_role.UserRoleAPI import role_by_name [as 别名]

#.........这里部分代码省略.........
                                     keyname='spacewalk-id', value=sw_uuid)

        return consumer['uuid']

    # katello demands a name here
    def update_consumer(self, cp_uuid, name, facts=None, installed_products=None,
                       last_checkin=None, owner=None, guest_uuids=None,
                       release=None, service_level=None):
        params = {}
        params['name'] = name
        if installed_products is not None:
            params['installedProducts'] = installed_products
        if guest_uuids is not None:
            params['guestIds'] = guest_uuids
        if facts is not None:
            # this logic should be moved elsewhere
            if 'virt.is_guest' in facts:
                facts['virt.uuid'] = cp_uuid
            params['facts'] = facts
        if release is not None:
            params['releaseVer'] = release
        if service_level is not None:
            params['serviceLevel'] = service_level

        # three rest calls, just one would be better
        self.systemapi.update(cp_uuid, params)
        if last_checkin is not None:
            self.systemapi.checkin(cp_uuid, self._convert_date(last_checkin))
        self.systemapi.refresh_subscriptions(cp_uuid)

    def get_consumers(self, owner=None, with_details=True):
        # TODO: this has a lot of logic and could be refactored

        # the API wants "orgId" but they mean "label"
        org_ids = map(lambda x: x['label'], self.orgapi.organizations())
        consumer_list = []
        for org_id in org_ids:
            consumer_list.append(self.systemapi.systems_by_org(orgId=org_id))

        # flatten the list
        consumer_list = list(itertools.chain.from_iterable(consumer_list))
        # return what we have, if we don't need the detailed list
        if not with_details:
            return consumer_list

        full_consumers_list = []
        # unfortunately, we need to call again to get the "full" consumer with facts
        for consumer in consumer_list:
            full_consumer = self._get_consumer(consumer['uuid'])
            full_consumer['entitlement_status'] = self.get_subscription_status(consumer['uuid'])
            full_consumers_list.append(full_consumer)

        return full_consumers_list

    def _get_consumer(self, consumer_uuid):
        return self.systemapi.system(system_id=consumer_uuid)

    def delete_consumer(self, consumer_uuid):
        self.systemapi.unregister(consumer_uuid)
        # XXX: only for dev use
        self.systemapi.remove_consumer_deletion_record(consumer_uuid)

    def get_roles(self, user_id=None):
        if user_id:
            return self.userapi.roles(user_id=user_id)
        else:
            return self.rolesapi.roles()

    def update_role(self, name, new_name):
        role = self.rolesapi.role_by_name(name=name)
        return self.rolesapi.update(role['id'], new_name, role['description'])

    # TODO: this is using kt_org_label but is really kt_org_name
    def create_org_admin_role_permission(self, kt_org_label):
        role = self.rolesapi.create(name="Org Admin Role for %s" % kt_org_label, description="generated from spacewalk")
        self.permissionapi.create(roleId=role['id'], name="Org Admin Permission for %s" % kt_org_label,
                                  description="generated from spacewalk", type_in="organizations", verbs=None,
                                  tagIds=None, orgId=kt_org_label, all_tags=True, all_verbs=True)

    def grant_org_admin(self, kt_user, kt_org_label):
        oa_role = self.rolesapi.role_by_name(name="Org Admin Role for %s" % kt_org_label)
        if not oa_role:
            _LOG.error("could not obtain org admin role from katello for org %s!" % kt_org_label)
        self.userapi.assign_role(user_id=kt_user['id'], role_id=oa_role['id'])

    def ungrant_org_admin(self, kt_user, kt_org_label):
        oa_role = self.rolesapi.role_by_name(name="Org Admin Role for %s" % kt_org_label)
        self.userapi.unassign_role(user_id=kt_user['id'], role_id=oa_role['id'])

    def grant_full_admin(self, kt_user):
        admin_role = self.rolesapi.role_by_name(name="Administrator")
        self.userapi.assign_role(user_id=kt_user['id'], role_id=admin_role['id'])

    def ungrant_full_admin(self, kt_user, kt_org_label):
        admin_role = self.rolesapi.role_by_name(name="Administrator")
        self.userapi.unassign_role(user_id=kt_user['id'], role_id=admin_role['id'])

    def _convert_date(self, dt):
        retval = datetime.strptime(dt, "%Y-%m-%d %H:%M:%S")
        return retval
开发者ID:dparalen,项目名称:spacewalk-splice-tool,代码行数:104,代码来源:katello_connect.py

示例4: KatelloConnection

# 需要导入模块: from katello.client.api.user_role import UserRoleAPI [as 别名]
# 或者: from katello.client.api.user_role.UserRoleAPI import role_by_name [as 别名]

#.........这里部分代码省略.........
            params['serviceLevel'] = service_level
        if last_checkin is not None:
            params['lastCheckin'] = self._convert_date(last_checkin).isoformat()

        self.systemapi.update(cp_uuid, params)

    def get_consumers(self, owner=None, with_details=True):
        # TODO: this has a lot of logic and could be refactored into katello_sync
        # the API wants "orgId" but they mean "label"
        org_ids = map(lambda x: x['label'], self.orgapi.organizations())
        # some katello-specific query params for pagination
        query_params = {'paged': 'true',
                        'sort_by': 'name',
                        'offset': 0,
                        'sort_order': 'ASC'}
        consumer_list = []
        # TODO: this could be done in parallel
        for org_id in org_ids:
            # we need to grab the system list in sets of 25 so we don't time out on especially large queries
            query_params['offset'] = 0
            while True:
                _LOG.debug("retrieving systems for org %s, offset %s" % (org_id, query_params['offset']))
                system_subset = self.systemapi.systems_by_org(orgId=org_id, query=query_params)['systems']
                _LOG.debug("found %s systems" % len(system_subset))
                consumer_list.append(system_subset)
                # if we didn't get 25 results, stop here
                if len(system_subset) < 25:
                    break
                query_params['offset'] += 25

        # flatten the list
        consumer_list = list(itertools.chain.from_iterable(consumer_list))
        # return what we have, if we don't need the detailed list
        if not with_details:
            return consumer_list

        consumer_uuids = map(lambda x: x['uuid'], consumer_list)

        def _get_full_consumer_worker(uuid):
            full_consumer = self._get_consumer(uuid)
            full_consumer['entitlement_status'] = self.get_subscription_status(uuid)
            return full_consumer

        full_consumers_list = utils.queued_work(_get_full_consumer_worker,
                                                consumer_uuids,
                                                CONFIG.getint('main', 'num_threads'))

        if len(consumer_uuids) != len(full_consumers_list):
            raise Exception("unable to fetch all consumer records (expected %s, found %s), see log for more detail" %
                            (len(consumer_uuids), len(full_consumers_list)))

        return full_consumers_list

    def _get_consumer(self, consumer_uuid):
        return self.systemapi.system(system_id=consumer_uuid)

    def delete_consumer(self, consumer_uuid):
        self.systemapi.unregister(consumer_uuid)

    def get_roles(self, user_id=None):
        if user_id:
            return self.userapi.roles(user_id=user_id)
        else:
            return self.rolesapi.roles()

    def update_role(self, name, new_name):
        role = self.rolesapi.role_by_name(name=name)
        return self.rolesapi.update(role['id'], new_name, role['description'])

    # TODO: this is using kt_org_label but is really kt_org_name
    def create_org_admin_role_permission(self, kt_org_label):
        role = self.rolesapi.create(name="Org Admin Role for %s" % kt_org_label, description="generated from spacewalk")
        self.permissionapi.create(roleId=role['id'], name="Org Admin Permission for %s" % kt_org_label,
                                  description="generated from spacewalk", type_in="organizations", verbs=None,
                                  tagIds=None, orgId=kt_org_label, all_tags=True, all_verbs=True)

    def grant_org_admin(self, kt_user, kt_org_label):
        oa_role = self.rolesapi.role_by_name(name="Org Admin Role for %s" % kt_org_label)
        if not oa_role:
            _LOG.error("could not obtain org admin role from katello for org %s!" % kt_org_label)
        self.userapi.assign_role(user_id=kt_user['id'], role_id=oa_role['id'])

    def ungrant_org_admin(self, kt_user, kt_org_label):
        oa_role = self.rolesapi.role_by_name(name="Org Admin Role for %s" % kt_org_label)
        self.userapi.unassign_role(user_id=kt_user['id'], role_id=oa_role['id'])

    def grant_full_admin(self, kt_user):
        admin_role = self.rolesapi.role_by_name(name="Administrator")
        self.userapi.assign_role(user_id=kt_user['id'], role_id=admin_role['id'])

    def ungrant_full_admin(self, kt_user, kt_org_label):
        admin_role = self.rolesapi.role_by_name(name="Administrator")
        self.userapi.unassign_role(user_id=kt_user['id'], role_id=admin_role['id'])

    def get_deleted_systems(self):
        return self.systemapi.get_deleted_consumers()

    def _convert_date(self, dt):
        retval = datetime.strptime(dt, "%Y-%m-%d %H:%M:%S")
        return retval
开发者ID:beav,项目名称:spacewalk-splice-tool,代码行数:104,代码来源:katello_connect.py

示例5: get_role

# 需要导入模块: from katello.client.api.user_role import UserRoleAPI [as 别名]
# 或者: from katello.client.api.user_role.UserRoleAPI import role_by_name [as 别名]
def get_role(name):
    user_role_api = UserRoleAPI()
    role = user_role_api.role_by_name(name)
    if role == None:
        raise ApiDataError(_("Cannot find user role [ %s ]") % (name))
    return role
开发者ID:bcrochet,项目名称:katello,代码行数:8,代码来源:utils.py

示例6: get_role

# 需要导入模块: from katello.client.api.user_role import UserRoleAPI [as 别名]
# 或者: from katello.client.api.user_role.UserRoleAPI import role_by_name [as 别名]
def get_role(name):
    user_role_api = UserRoleAPI()
    role = user_role_api.role_by_name(name)
    if role == None:
        print _("Cannot find user role [ %s ]") % (name)
    return role
开发者ID:jsomara,项目名称:katello,代码行数:8,代码来源:utils.py


注:本文中的katello.client.api.user_role.UserRoleAPI.role_by_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。