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


Python LabController.user方法代码示例

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


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

示例1: _create_labcontroller_helper

# 需要导入模块: from bkr.server.model import LabController [as 别名]
# 或者: from bkr.server.model.LabController import user [as 别名]
def _create_labcontroller_helper(data):
    with convert_internal_errors():
        if LabController.query.filter_by(fqdn=data['fqdn']).count():
            raise Conflict409('Lab Controller %s already exists' % data['fqdn'])

        user = find_user_or_create(data['user_name'])
        user = update_user(
            user=user,
            display_name=data['fqdn'],
            email_address=data.get('email_address', user.email_address),
            password=data.get('password', user.password)
        )
        labcontroller = LabController(fqdn=data['fqdn'], disabled=False)
        labcontroller.record_activity(
            user=identity.current.user, service=u'HTTP',
            action=u'Changed', field=u'FQDN', old=u'', new=data['fqdn'])

        labcontroller.user = user
        labcontroller.record_activity(
            user=identity.current.user, service=u'HTTP',
            action=u'Changed', field=u'User', old=u'', new=user.user_name)

        # For backwards compatibility
        labcontroller.record_activity(
            user=identity.current.user, service=u'HTTP',
            action=u'Changed', field=u'Disabled', old=u'', new=unicode(labcontroller.disabled))

        session.add(labcontroller)
        # flush it so we return an id, otherwise we'll end up back in here from
        # the edit form
        session.flush()

    response = jsonify(labcontroller.__json__())
    response.status_code = 201
    return response
开发者ID:,项目名称:,代码行数:37,代码来源:

示例2: create_labcontroller

# 需要导入模块: from bkr.server.model import LabController [as 别名]
# 或者: from bkr.server.model.LabController import user [as 别名]
def create_labcontroller(fqdn=None, user=None):
    if fqdn is None:
        fqdn = unique_name(u'lab%s.testdata.invalid')
    try:
        lc = LabController.by_name(fqdn)  
    except NoResultFound:
        if user is None:
            user = User(user_name='host/%s' % fqdn)
        lc = LabController(fqdn=fqdn)
        lc.user = user
        user.groups.append(Group.by_name(u'lab_controller'))
        return lc
    log.debug('labcontroller %s already exists' % fqdn)
    return lc
开发者ID:sibiaoluo,项目名称:beaker,代码行数:16,代码来源:data_setup.py

示例3: save

# 需要导入模块: from bkr.server.model import LabController [as 别名]
# 或者: from bkr.server.model.LabController import user [as 别名]
    def save(self, **kw):
        if kw.get('id'):
            labcontroller = LabController.by_id(kw['id'])
        else:
            labcontroller =  LabController()
            session.add(labcontroller)
        if labcontroller.fqdn != kw['fqdn']:
            activity = LabControllerActivity(identity.current.user,
                'WEBUI', 'Changed', 'FQDN', labcontroller.fqdn, kw['fqdn'])
            labcontroller.fqdn = kw['fqdn']
            labcontroller.write_activity.append(activity)

        # labcontroller.user is used by the lab controller to login here
        try:
            # pick up an existing user if it exists.
            luser = User.query.filter_by(user_name=kw['lusername']).one()
        except InvalidRequestError:
            # Nope, create from scratch
            luser = User()
        if labcontroller.user != luser:
            if labcontroller.user is None:
                old_user_name = None
            else:
                old_user_name = labcontroller.user.user_name
            activity = LabControllerActivity(identity.current.user, 'WEBUI',
                'Changed', 'User', old_user_name, unicode(kw['lusername']))
            labcontroller.user = luser
            labcontroller.write_activity.append(activity)

        # Make sure user is a member of lab_controller group
        group = Group.by_name(u'lab_controller')
        if group not in luser.groups:
            luser.groups.append(group)
        luser.display_name = kw['fqdn']
        luser.email_address = kw['email']
        luser.user_name = kw['lusername']

        if kw['lpassword']:
            luser.password = kw['lpassword']
        if labcontroller.disabled != kw['disabled']:
            activity = LabControllerActivity(identity.current.user, 'WEBUI',
                'Changed', 'Disabled', unicode(labcontroller.disabled), 
                unicode(kw['disabled']))
            labcontroller.disabled = kw['disabled']
            labcontroller.write_activity.append(activity)

        flash( _(u"%s saved" % labcontroller.fqdn) )
        redirect(".")
开发者ID:ShaolongHu,项目名称:beaker,代码行数:50,代码来源:labcontroller.py

示例4: create_labcontroller

# 需要导入模块: from bkr.server.model import LabController [as 别名]
# 或者: from bkr.server.model.LabController import user [as 别名]
def create_labcontroller(fqdn=None, user=None):
    if fqdn is None:
        fqdn = unique_name(u'lab%s.testdata.invalid')
    try:
        lc = LabController.by_name(fqdn)  
    except NoResultFound:
        if user is None:
            user = User(user_name=u'host/%s' % fqdn,
                    email_address=u'[email protected]%s' % fqdn)
        lc = LabController(fqdn=fqdn)
        lc.user = user
        session.add(lc)
        user.groups.append(Group.by_name(u'lab_controller'))
        # Need to ensure it is inserted now, since we aren't using lazy_create 
        # here so a subsequent call to create_labcontroller could try and 
        # create the same LC again.
        session.flush()
        return lc
    log.debug('labcontroller %s already exists' % fqdn)
    return lc
开发者ID:sujithshankar,项目名称:beaker,代码行数:22,代码来源:data_setup.py


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