• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python model.processUuid函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中uds.core.util.model.processUuid函数的典型用法代码示例。如果您正苦于以下问题:Python processUuid函数的具体用法?Python processUuid怎么用?Python processUuid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: beforeSave

    def beforeSave(self, fields):
        # logger.debug(self._params)
        try:
            # **** IMAGE ***
            imgId = fields['image_id']
            fields['image_id'] = None
            logger.debug('Image id: {}'.format(imgId))
            try:
                if imgId != '-1':
                    image = Image.objects.get(uuid=processUuid(imgId))
                    fields['image_id'] = image.id
            except Exception:
                logger.exception('At image recovering')

            # Servicepool Group
            spgrpId = fields['servicesPoolGroup_id']
            fields['servicesPoolGroup_id'] = None
            logger.debug('servicesPoolGroup_id: {}'.format(spgrpId))
            try:
                if spgrpId != '-1':
                    spgrp = ServicesPoolGroup.objects.get(uuid=processUuid(spgrpId))
                    fields['servicesPoolGroup_id'] = spgrp.id
            except Exception:
                logger.exception('At service pool group recovering')

        except (RequestError, ResponseError):
            raise
        except Exception as e:
            raise RequestError(str(e))

        logger.debug('Fields: {}'.format(fields))
开发者ID:dkmstr,项目名称:openuds,代码行数:31,代码来源:meta_pools.py


示例2: saveItem

    def saveItem(self, parent, item):
        # If already exists
        uuid = processUuid(item) if item is not None else None

        calendar = Calendar.objects.get(uuid=processUuid(self._params['calendarId']))
        action = self._params['action'].upper()
        eventsOffset = int(self._params['eventsOffset'])
        atStart = self._params['atStart'] not in ('false', False, '0', 0)
        params = json.dumps(self._params['params'])

        logger.debug('Got parameters: {} {} {} {} ----> {}'.format(calendar, action, eventsOffset, atStart, params))

        if uuid is not None:
            calAction = CalendarAction.objects.get(uuid=uuid)
            calAction.calendar = calendar
            calAction.service_pool = parent
            calAction.action = action
            calAction.at_start = atStart
            calAction.events_offset = eventsOffset
            calAction.params = params
            calAction.save()
        else:
            CalendarAction.objects.create(calendar=calendar, service_pool=parent, action=action, at_start=atStart, events_offset=eventsOffset, params=params)

        return self.success()
开发者ID:joaoguariglia,项目名称:openuds,代码行数:25,代码来源:services_pool_calendars.py


示例3: saveItem

    def saveItem(self, parent, item):
        # If already exists
        uuid = processUuid(item) if item is not None else None

        try:
            calendar = Calendar.objects.get(uuid=processUuid(self._params['calendarId']))
            access = self._params['access'].upper()
            if access not in ('ALLOW', 'DENY'):
                raise Exception()
        except Exception:
            self.invalidRequestException(_('Invalid parameters on request'))
        priority = int(self._params['priority'])

        if uuid is not None:
            calAccess = parent.calendarAccess.get(uuid=uuid)
            calAccess.calendar = calendar
            calAccess.service_pool = parent
            calAccess.access = access
            calAccess.priority = priority
            calAccess.save()
        else:
            parent.calendarAccess.create(calendar=calendar, access=access, priority=priority)

        log.doLog(parent, log.INFO, "Added access calendar {}/{} by {}".format(calendar.name, access, self._user.pretty_name), log.ADMIN)

        return self.success()
开发者ID:dkmstr,项目名称:openuds,代码行数:26,代码来源:op_calendars.py


示例4: getItems

 def getItems(self, parent, item):
     # Extract provider
     try:
         if item is None:
             return [AssignedService.itemToDict(k) for k in parent.assignedUserServices().all()
                     .prefetch_related('properties').prefetch_related('deployed_service').prefetch_related('publication')]
         else:
             return parent.assignedUserServices().get(processUuid(uuid=processUuid(item)))
     except Exception:
         logger.exception('getItems')
         self.invalidItemException()
开发者ID:joaoguariglia,项目名称:openuds,代码行数:11,代码来源:user_services.py


示例5: userServices

    def userServices(self, parent, item):
        uuid = processUuid(item)
        user = parent.users.get(uuid=processUuid(uuid))
        res = []
        for i in user.userServices.all():
            if i.state == State.USABLE:
                v = AssignedService.itemToDict(i)
                v['pool'] = i.deployed_service.name
                v['pool_id'] = i.deployed_service.uuid
                res.append(v)

        return res
开发者ID:glyptodon,项目名称:openuds,代码行数:12,代码来源:users_groups.py


示例6: serviceImage

def serviceImage(request, idImage):
    try:
        icon = Image.objects.get(uuid=processUuid(idImage))
        return icon.imageResponse()
    except Image.DoesNotExist:
        pass  # Tries to get image from transport

    try:
        icon = Transport.objects.get(uuid=processUuid(idImage)).getInstance().icon(False)
        return HttpResponse(icon, content_type='image/png')
    except Exception:
        return HttpResponse(DEFAULT_IMAGE, content_type='image/png')
开发者ID:joaoguariglia,项目名称:openuds,代码行数:12,代码来源:service.py


示例7: servicesPools

    def servicesPools(self, parent, item):
        uuid = processUuid(item)
        group = parent.groups.get(uuid=processUuid(uuid))
        res = []
        for i in getPoolsForGroups((group,)):
            res.append({
                'id': i.uuid,
                'name': i.name,
                'thumb': i.image.thumb64 if i.image is not None else DEFAULT_THUMB_BASE64,
                'user_services_count': i.userServices.exclude(state__in=(State.REMOVED, State.ERROR)).count(),
                'state': _('With errors') if i.isRestrained() else _('Ok'),
            })

        return res
开发者ID:glyptodon,项目名称:openuds,代码行数:14,代码来源:users_groups.py


示例8: getLogs

    def getLogs(self, parent, item):
        try:
            user = parent.users.get(uuid=processUuid(item))
        except Exception:
            self.invalidItemException()

        return log.getLogs(user)
开发者ID:joaoguariglia,项目名称:openuds,代码行数:7,代码来源:users_groups.py


示例9: getLogs

 def getLogs(self, parent, item):
     try:
         item = parent.cachedUserServices().get(uuid=processUuid(item))
         logger.debug('Getting logs for {0}'.format(item))
         return log.getLogs(item)
     except Exception:
         self.invalidItemException()
开发者ID:dkmstr,项目名称:openuds,代码行数:7,代码来源:user_services.py


示例10: saveItem

    def saveItem(self, parent, item):
        # Extract item db fields
        # We need this fields for all
        logger.debug("Saving service {0} / {1}".format(parent, item))
        fields = self.readFieldsFromParams(["name", "comments", "data_type"])
        service = None
        try:
            if item is None:  # Create new
                service = parent.services.create(**fields)
            else:
                service = parent.services.get(uuid=processUuid(item))
                service.__dict__.update(fields)

            service.data = service.getInstance(self._params).serialize()
            service.save()
        except Service.DoesNotExist:
            self.invalidItemException()
        except IntegrityError:  # Duplicate key probably
            raise RequestError(_("Element already exists (duplicate key error)"))
        except coreService.ValidationException as e:
            self._deleteIncompleteService(service)
            raise RequestError(_("Input error: {0}".format(unicode(e))))
        except Exception as e:
            self._deleteIncompleteService(service)
            logger.exception("Saving Service")
            raise RequestError("incorrect invocation to PUT: {0}".format(e))

        return self.getItems(parent, service.uuid)
开发者ID:AlexeyBychkov,项目名称:openuds,代码行数:28,代码来源:services.py


示例11: saveItem

    def saveItem(self, parent, item):
        # Extract item db fields
        # We need this fields for all
        logger.debug('Saving rule {0} / {1}'.format(parent, item))
        fields = self.readFieldsFromParams(['name', 'comments', 'frequency', 'start', 'end', 'interval', 'duration', 'duration_unit'])
        # Convert timestamps to datetimes
        fields['start'] = datetime.datetime.fromtimestamp(fields['start'])
        if fields['end'] != None:
            fields['end'] = datetime.datetime.fromtimestamp(fields['end'])

        calRule = None
        try:
            if item is None:  # Create new
                calRule = parent.rules.create(**fields)
            else:
                calRule = parent.rules.get(uuid=processUuid(item))
                calRule.__dict__.update(fields)
                calRule.save()
        except CalendarRule.DoesNotExist:
            self.invalidItemException()
        except IntegrityError:  # Duplicate key probably
            raise RequestError(_('Element already exists (duplicate key error)'))
        except Exception as e:
            logger.exception('Saving calendar')
            raise RequestError('incorrect invocation to PUT: {0}'.format(e))

        return self.getItems(parent, calRule.uuid)
开发者ID:AlexeyBychkov,项目名称:openuds,代码行数:27,代码来源:calendarrules.py


示例12: getItems

 def getItems(self, parent, item):
     try:
         multi = False
         if item is None:
             multi = True
             q = parent.groups.all().order_by('name')
         else:
             q = parent.groups.filter(uuid=processUuid(item))
         res = []
         for i in q:
             val = {
                 'id': i.uuid,
                 'name': i.name,
                 'comments': i.comments,
                 'state': i.state,
                 'type': i.is_meta and 'meta' or 'group',
                 'meta_if_any': i.meta_if_any
             }
             if i.is_meta:
                 val['groups'] = list(x.uuid for x in i.groups.all())
             res.append(val)
         if multi:
             return res
         return res[0]
     except:
         logger.exception('REST groups')
         self.invalidItemException()
开发者ID:glyptodon,项目名称:openuds,代码行数:27,代码来源:users_groups.py


示例13: deleteItem

    def deleteItem(self, parent, item):  # This is also used by CachedService, so we use "userServices" directly and is valid for both
        service = None
        try:
            service = parent.userServices.get(uuid=processUuid(item))
        except Exception:
            logger.exception('deleteItem')
            self.invalidItemException()

        if service.user:
            logStr = 'Deleted assigned service {} to user {} by {}'.format(service.friendly_name, service.user.pretty_name, self._user.pretty_name)
        else:
            logStr = 'Deleted cached service {} by {}'.format(service.friendly_name, self._user.pretty_name)

        if service.state in (State.USABLE, State.REMOVING):
            service.remove()
        elif service.state == State.PREPARING:
            service.cancel()
        elif service.state == State.REMOVABLE:
            self.invalidItemException(_('Item already being removed'))
        else:
            self.invalidItemException(_('Item is not removable'))

        log.doLog(parent, log.INFO, logStr, log.ADMIN)

        return self.success()
开发者ID:dkmstr,项目名称:openuds,代码行数:25,代码来源:user_services.py


示例14: getItems

 def getItems(self, parent, item):
     try:
         multi = False
         if item is None:
             multi = True
             q = parent.groups.all().order_by('name')
         else:
             q = parent.groups.filter(uuid=processUuid(item))
         res = []
         for i in q:
             val = {
                 'id': i.uuid,
                 'name': i.name,
                 'comments': i.comments,
                 'state': i.state,
                 'type': i.is_meta and 'meta' or 'group',
                 'meta_if_any': i.meta_if_any
             }
             if i.is_meta:
                 val['groups'] = list(x.uuid for x in i.groups.all().order_by('name'))
             res.append(val)
         if multi:
             return res
         # Add pools field if 1 item only
         res = res[0]
         if i.is_meta:
             res['pools'] = []  # Meta groups do not have "assigned "pools, they get it from groups interaction
         else:
             res['pools'] = [v.uuid for v in  i.deployedServices.all()]
         return res
     except:
         logger.exception('REST groups')
         self.invalidItemException()
开发者ID:dkmstr,项目名称:openuds,代码行数:33,代码来源:users_groups.py


示例15: saveItem

    def saveItem(self, parent, item):
        # Extract item db fields
        # We need this fields for all
        logger.debug('Saving service for {0} / {1}'.format(parent, item))
        fields = self.readFieldsFromParams(['name', 'comments', 'data_type', 'tags', 'proxy_id'])
        tags = fields['tags']
        del fields['tags']
        service = None

        proxyId = fields['proxy_id']
        fields['proxy_id'] = None
        logger.debug('Proxy id: {}'.format(proxyId))

        proxy = None
        if proxyId != '-1':
            try:
                proxy = Proxy.objects.get(uuid=processUuid(proxyId))
            except Exception:
                logger.exception('Getting proxy ID')

        try:
            if item is None:  # Create new
                service = parent.services.create(**fields)
            else:
                service = parent.services.get(uuid=processUuid(item))
                service.__dict__.update(fields)

            service.tags.set([Tag.objects.get_or_create(tag=val)[0] for val in tags])
            service.proxy = proxy

            service.data = service.getInstance(self._params).serialize()  # This may launch an validation exception (the getInstance(...) part)
            service.save()
        except Service.DoesNotExist:
            self.invalidItemException()
        except IntegrityError:  # Duplicate key probably
            raise RequestError(_('Element already exists (duplicate key error)'))
        except coreService.ValidationException as e:
            if item is None:  # Only remove partially saved element if creating new (if editing, ignore this)
                self._deleteIncompleteService(service)
            raise RequestError(_('Input error: {0}'.format(six.text_type(e))))
        except Exception as e:
            if item is None:
                self._deleteIncompleteService(service)
            logger.exception('Saving Service')
            raise RequestError('incorrect invocation to PUT: {0}'.format(e))

        return self.getItems(parent, service.uuid)
开发者ID:dkmstr,项目名称:openuds,代码行数:47,代码来源:services.py


示例16: execute

    def execute(self, parent, item):
        self.ensureAccess(item, permissions.PERMISSION_MANAGEMENT)
        logger.debug('Launching action')
        uuid = processUuid(item)
        calAction = CalendarAction.objects.get(uuid=uuid)
        calAction.execute()

        return self.success()
开发者ID:joaoguariglia,项目名称:openuds,代码行数:8,代码来源:services_pool_calendars.py


示例17: post

    def post(self):
        '''
        Processes post requests
        '''
        if len(self._args) != 2:
            raise RequestError('Invalid request')

        uuid, message = self._args[0], self._args[1]
        if self._params.get('data') is not None:
            data = self._params['data']
        else:
            data = None

        # Right now, only "message" posts
        try:
            service = UserService.objects.get(uuid=processUuid(uuid))
        except Exception:
            return Actor.result(_('User service not found'), error=ERR_USER_SERVICE_NOT_FOUND)

        if message == 'notifyComms':
            logger.debug('Setting comms url to {}'.format(data))
            service.setCommsUrl(data)
            return Actor.result('ok')
        elif message == 'ssoAvailable':
            logger.debug('Setting that SSO is available')
            service.setProperty('sso_available', 1)
            return Actor.result('ok')
        elif message == 'version':
            version = self._params.get('version', 'unknown')
            logger.debug('Got notified version {}'.format(version))
            service.setProperty('actor_version', version)

        # "Cook" some messages, common to all clients, such as "log"
        if message == 'log':
            logger.debug(self._params)
            data = '\t'.join((self._params.get('message'), six.text_type(self._params.get('level', 10000))))

        osmanager = service.getInstance().osmanager()

        try:
            if osmanager is None:
                if message in ('login', 'logout'):
                    osm = OSManager(None, None)  # Dummy os manager, just for using "logging" capability
                    if message == 'login':
                        osm.loggedIn(service)
                    else:
                        osm.loggedOut(service)
                        # Mark for removal...
                        service.release()  # Release for removal
                    return 'ok'
                raise Exception('Unknown message {} for an user service without os manager'.format(message))
            else:
                res = osmanager.process(service, message, data, options={'scramble': False})
        except Exception as e:
            logger.exception("Exception processing from OS Manager")
            return Actor.result(six.text_type(e), ERR_OSMANAGER_ERROR)

        return Actor.result(res)
开发者ID:glyptodon,项目名称:openuds,代码行数:58,代码来源:actor.py


示例18: beforeSave

    def beforeSave(self, fields):
        # logger.debug(self._params)
        try:
            try:
                service = Service.objects.get(uuid=processUuid(fields['service_id']))
                fields['service_id'] = service.id
            except:
                raise RequestError(ugettext('Base service does not exist anymore'))

            try:
                serviceType = service.getType()

                if serviceType.publicationType is None:
                    self._params['publish_on_save'] = False

                if serviceType.needsManager is True:
                    osmanager = OSManager.objects.get(uuid=processUuid(fields['osmanager_id']))
                    fields['osmanager_id'] = osmanager.id
                else:
                    del fields['osmanager_id']

                if serviceType.usesCache is False:
                    for k in ('initial_srvs', 'cache_l1_srvs', 'cache_l2_srvs', 'max_srvs'):
                        fields[k] = 0

            except Exception:
                raise RequestError(ugettext('This service requires an OS Manager'))

            # If max < initial or cache_1 or cache_l2
            fields['max_srvs'] = max((int(fields['initial_srvs']), int(fields['cache_l1_srvs']), int(fields['max_srvs'])))

            imgId = fields['image_id']
            fields['image_id'] = None
            logger.debug('Image id: {}'.format(imgId))
            try:
                if imgId != '-1':
                    image = Image.objects.get(uuid=processUuid(imgId))
                    fields['image_id'] = image.id
            except Exception:
                logger.exception('At image recovering')

        except (RequestError, ResponseError):
            raise
        except Exception as e:
            raise RequestError(str(e))
开发者ID:AlexeyBychkov,项目名称:openuds,代码行数:45,代码来源:services_pools.py


示例19: _getAssignedService

 def _getAssignedService(self, metaPool, userServiceId):
     """
     Gets an assigned service and checks that it belongs to this metapool
     If not found, raises InvalidItemException
     """
     try:
         return UserService.objects.filter(uuid=processUuid(userServiceId), cache_level=0, deployed_service__meta=metaPool)[0]
     except Exception:
         self.invalidItemException()
开发者ID:dkmstr,项目名称:openuds,代码行数:9,代码来源:meta_service_pools.py


示例20: post

    def post(self):
        '''
        This login uses parameters to generate auth token
        The alternative is to use the template tag inside "REST" that is called auth_token, that extracts an auth token from an user session
        We can use any of this forms due to the fact that the auth token is in fact a session key
        Parameters:
            mandatory:
                username:
                password:
                authId or auth or authSmallName: (must include at least one. If multiple are used, precedence is the list order)
        Result:
            on success: { 'result': 'ok', 'auth': [auth_code] }
            on error: { 'result: 'error', 'error': [error string] }

        Locale comes on "Header", as any HTTP Request (Accept-Language header)
        Calls to any method of REST that must be authenticated needs to be called with "X-Auth-Token" Header added
        '''
        try:
            if 'authId' not in self._params and 'authSmallName' not in self._params and 'auth' not in self._params:
                raise RequestError('Invalid parameters (no auth)')

            authId = self._params.get('authId', None)
            authSmallName = self._params.get('authSmallName', None)
            authName = self._params.get('auth', None)

            username, password = self._params['username'], self._params['password']
            locale = self._params.get('locale', 'en')
            if authName == 'admin' or authSmallName == 'admin':
                if GlobalConfig.SUPER_USER_LOGIN.get(True) == username and GlobalConfig.SUPER_USER_PASS.get(True) == password:
                    self.genAuthToken(-1, username, locale, True, True)
                    return{'result': 'ok', 'token': self.getAuthToken()}
                else:
                    raise Exception('Invalid credentials')
            else:
                try:
                    # Will raise an exception if no auth found
                    if authId is not None:
                        auth = Authenticator.objects.get(uuid=processUuid(authId))
                    elif authName is not None:
                        auth = Authenticator.objects.get(name=authName)
                    else:
                        auth = Authenticator.objects.get(small_name=authSmallName)

                    logger.debug('Auth obj: {0}'.format(auth))
                    user = authenticate(username, password, auth)
                    if user is None:  # invalid credentials
                        raise Exception()
                    self.genAuthToken(auth.id, user.name, locale, user.is_admin, user.staff_member)
                    return{'result': 'ok', 'token': self.getAuthToken()}
                except:
                    logger.exception('Credentials ')
                    raise Exception('Invalid Credentials (invalid authenticator)')

            raise Exception('Invalid Credentials')
        except Exception as e:
            logger.exception('exception')
            return {'result': 'error', 'error': unicode(e)}
开发者ID:AlexeyBychkov,项目名称:openuds,代码行数:57,代码来源:login_logout.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python models.getSqlDatetime函数代码示例发布时间:2022-05-27
下一篇:
Python log.doLog函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap