def item_as_dict(self, item): # if item does not have an associated service, hide it (the case, for example, for a removed service) # Access from dict will raise an exception, and item will be skipped val = { 'id': item.uuid, 'name': item.name, 'parent': item.service.name, 'parent_type': item.service.data_type, 'comments': item.comments, 'state': item.state if item.service.provider.maintenance_mode is False else State.MAINTENANCE, 'thumb': item.image.thumb64 if item.image is not None else DEFAULT_THUMB_BASE64, 'service_id': item.service.uuid, 'provider_id': item.service.provider.uuid, 'image_id': item.image.uuid if item.image is not None else None, 'initial_srvs': item.initial_srvs, 'cache_l1_srvs': item.cache_l1_srvs, 'cache_l2_srvs': item.cache_l2_srvs, 'max_srvs': item.max_srvs, 'user_services_count': item.userServices.count(), 'restrained': item.isRestrained(), 'show_transports': item.show_transports, 'permission': permissions.getEffectivePermission(self._user, item), 'info': Services.serviceInfo(item.service), } if item.osmanager is not None: val['osmanager_id'] = item.osmanager.uuid return val
def item_as_dict(self, provider): type_ = provider.getType() # Icon can have a lot of data (1-2 Kbytes), but it's not expected to have a lot of services providers, and even so, this will work fine offers = [{ 'name': ugettext(t.name()), 'type': t.type(), 'description': ugettext(t.description()), 'icon': t.icon().replace('\n', '') } for t in type_.getServicesTypes()] return { 'id': provider.uuid, 'name': provider.name, 'tags': [tag.vtag for tag in provider.tags.all()], 'services_count': provider.services.count(), 'user_services_count': UserService.objects.filter( deployed_service__service__provider=provider).exclude( state__in=(State.REMOVED, State.ERROR)).count(), 'maintenance_mode': provider.maintenance_mode, 'offers': offers, 'type': type_.type(), 'comments': provider.comments, 'permission': permissions.getEffectivePermission(self._user, provider) }
def item_as_dict(self, item: Transport) -> typing.Dict[str, typing.Any]: type_ = item.getType() return { 'id': item.uuid, 'name': item.name, 'tags': [tag.tag for tag in item.tags.all()], 'comments': item.comments, 'priority': item.priority, 'nets_positive': item.nets_positive, 'networks': [{ 'id': n.uuid } for n in item.networks.all()], 'allowed_oss': [{ 'id': x } for x in item.allowed_oss.split(',')] if item.allowed_oss != '' else [], 'pools': [{ 'id': x.uuid } for x in item.deployedServices.all()], 'deployed_count': item.deployedServices.count(), 'type': type_.type(), 'type_name': type_.name(), 'protocol': type_.protocol, 'permission': permissions.getEffectivePermission(self._user, item) }
def ensureAccess(self, obj: models.Model, permission: int, root: bool = False) -> int: perm = permissions.getEffectivePermission(self._user, obj, root) if perm < permission: raise self.accessDenied() return perm
def item_as_dict(self, calendar): return { 'id': calendar.uuid, 'name': calendar.name, 'comments': calendar.comments, 'modified': calendar.modified, 'permission': permissions.getEffectivePermission(self._user, calendar) }
def item_as_dict(self, item): return { 'id': item.uuid, 'name': item.name, 'net_string': item.net_string, 'networks_count': item.transports.count(), 'permission': permissions.getEffectivePermission(self._user, item) }
def item_as_dict(self, item): return { "id": item.uuid, "name": item.name, "net_string": item.net_string, "networks_count": item.transports.count(), "permission": permissions.getEffectivePermission(self._user, item), }
def item_as_dict(self, item: Calendar) -> typing.Dict[str, typing.Any]: return { 'id': item.uuid, 'name': item.name, 'tags': [tag.tag for tag in item.tags.all()], 'comments': item.comments, 'modified': item.modified, 'permission': permissions.getEffectivePermission(self._user, item) }
def item_as_dict(self, item: Account): return { 'id': item.uuid, 'name': item.name, 'tags': [tag.tag for tag in item.tags.all()], 'comments': item.comments, 'time_mark': item.time_mark, 'permission': permissions.getEffectivePermission(self._user, item) }
def item_as_dict(self, item): return { 'id': item.uuid, 'name': item.name, 'tags': [tag.tag for tag in item.tags.all()], 'net_string': item.net_string, 'networks_count': item.transports.count(), 'permission': permissions.getEffectivePermission(self._user, item) }
def item_as_dict(self, item: Network) -> typing.Dict[str, typing.Any]: return { 'id': item.uuid, 'name': item.name, 'tags': [tag.tag for tag in item.tags.all()], 'net_string': item.net_string, 'networks_count': item.transports.count(), 'permission': permissions.getEffectivePermission(self._user, item) }
def item_as_dict(self, account): return { 'id': account.uuid, 'name': account.name, 'tags': [tag.tag for tag in account.tags.all()], 'comments': account.comments, 'time_mark': account.time_mark, 'permission': permissions.getEffectivePermission(self._user, account) }
def item_as_dict(self, calendar): return { 'id': calendar.uuid, 'name': calendar.name, 'tags': [tag.tag for tag in calendar.tags.all()], 'comments': calendar.comments, 'modified': calendar.modified, 'permission': permissions.getEffectivePermission(self._user, calendar) }
def item_as_dict(self, item): # if item does not have an associated service, hide it (the case, for example, for a removed service) # Access from dict will raise an exception, and item will be skipped poolGroupId = None poolGroupName = _('Default') poolGroupThumb = DEFAULT_THUMB_BASE64 if item.servicesPoolGroup is not None: poolGroupId = item.servicesPoolGroup.uuid poolGroupName = item.servicesPoolGroup.name if item.servicesPoolGroup.image is not None: poolGroupThumb = item.servicesPoolGroup.image.thumb64 state = item.state if item.isInMaintenance(): state = State.MAINTENANCE elif userServiceManager().canInitiateServiceFromDeployedService(item) is False: state = State.SLOWED_DOWN val = { 'id': item.uuid, 'name': item.name, 'short_name': item.short_name, 'tags': [tag.tag for tag in item.tags.all()], 'parent': item.service.name, 'parent_type': item.service.data_type, 'comments': item.comments, 'state': state, 'thumb': item.image.thumb64 if item.image is not None else DEFAULT_THUMB_BASE64, 'account': item.account.name if item.account is not None else '', 'service_id': item.service.uuid, 'provider_id': item.service.provider.uuid, 'image_id': item.image.uuid if item.image is not None else None, 'servicesPoolGroup_id': poolGroupId, 'account_id': item.account.uuid if item.account is not None else None, 'pool_group_name': poolGroupName, 'pool_group_thumb': poolGroupThumb, 'initial_srvs': item.initial_srvs, 'cache_l1_srvs': item.cache_l1_srvs, 'cache_l2_srvs': item.cache_l2_srvs, 'max_srvs': item.max_srvs, 'user_services_count': item.userServices.exclude(state__in=State.INFO_STATES).count(), 'user_services_in_preparation': item.userServices.filter(state=State.PREPARING).count(), 'restrained': item.isRestrained(), 'show_transports': item.show_transports, 'visible': item.visible, 'allow_users_remove': item.allow_users_remove, 'ignores_unused': item.ignores_unused, 'fallbackAccess': item.fallbackAccess, 'permission': permissions.getEffectivePermission(self._user, item), 'info': Services.serviceInfo(item.service), } if item.osmanager is not None: val['osmanager_id'] = item.osmanager.uuid return val
def osmToDict(self, osm): type_ = osm.getType() return { 'id': osm.uuid, 'name': osm.name, 'deployed_count': osm.deployedServices.count(), 'type': type_.type(), 'comments': osm.comments, 'permission': permissions.getEffectivePermission(self._user, osm) }
def allservices(self): ''' Custom method that returns "all existing services", no mater who's his daddy :) ''' for s in Service.objects.all(): try: perm = permissions.getEffectivePermission(self._user, s) if perm >= permissions.PERMISSION_READ: yield DetailServices.serviceToDict(s, perm, True) except Exception: logger.exception('Passed service cause type is unknown')
def allservices(self): """ Custom method that returns "all existing services", no mater who's his daddy :) """ for s in Service.objects.all(): try: perm = permissions.getEffectivePermission(self._user, s) if perm >= permissions.PERMISSION_READ: yield DetailServices.serviceToDict(s, perm, True) except Exception: logger.exception('Passed service cause type is unknown')
def getItems(self, parent, item): # Check what kind of access do we have to parent provider perm = permissions.getEffectivePermission(self._user, parent) try: if item is None: return [CalendarRules.ruleToDict(k, perm) for k in parent.rules.all()] else: k = parent.rules.get(uuid=processUuid(item)) return CalendarRules.ruleToDict(k, perm) except Exception: logger.exception('itemId {}'.format(item)) self.invalidItemException()
def getItems(self, parent: 'Provider', item: typing.Optional[str]): # Check what kind of access do we have to parent provider perm = permissions.getEffectivePermission(self._user, parent) try: if item is None: return [Services.serviceToDict(k, perm) for k in parent.services.all()] k = parent.services.get(uuid=processUuid(item)) val = Services.serviceToDict(k, perm, full=True) return self.fillIntanceFields(k, val) except Exception: logger.exception('itemId %s', item) raise self.invalidItemException()
def item_as_dict(self, item): # if item does not have an associated service, hide it (the case, for example, for a removed service) # Access from dict will raise an exception, and item will be skipped poolGroupId = None poolGroupName = _('Default') poolGroupThumb = DEFAULT_THUMB_BASE64 if item.servicesPoolGroup is not None: poolGroupId = item.servicesPoolGroup.uuid poolGroupName = item.servicesPoolGroup.name if item.servicesPoolGroup.image is not None: poolGroupThumb = item.servicesPoolGroup.image.thumb64 state = item.state if item.isInMaintenance(): state = State.MAINTENANCE elif userServiceManager().canInitiateServiceFromDeployedService(item) is False: state = State.SLOWED_DOWN val = { 'id': item.uuid, 'name': item.name, 'tags': [tag.tag for tag in item.tags.all()], 'parent': item.service.name, 'parent_type': item.service.data_type, 'comments': item.comments, 'state': state, 'thumb': item.image.thumb64 if item.image is not None else DEFAULT_THUMB_BASE64, 'account': item.account.name if item.account is not None else '', 'service_id': item.service.uuid, 'provider_id': item.service.provider.uuid, 'image_id': item.image.uuid if item.image is not None else None, 'servicesPoolGroup_id': poolGroupId, 'account_id': item.account.uuid if item.account is not None else None, 'pool_group_name': poolGroupName, 'pool_group_thumb': poolGroupThumb, 'initial_srvs': item.initial_srvs, 'cache_l1_srvs': item.cache_l1_srvs, 'cache_l2_srvs': item.cache_l2_srvs, 'max_srvs': item.max_srvs, 'user_services_count': item.userServices.count(), 'user_services_in_preparation': item.userServices.filter(state=State.PREPARING).count(), 'restrained': item.isRestrained(), 'show_transports': item.show_transports, 'visible': item.visible, 'fallbackAccess': item.fallbackAccess, 'permission': permissions.getEffectivePermission(self._user, item), 'info': Services.serviceInfo(item.service), } if item.osmanager is not None: val['osmanager_id'] = item.osmanager.uuid return val
def item_as_dict(self, auth): type_ = auth.getType() return { 'id': auth.uuid, 'name': auth.name, 'comments': auth.comments, 'priority': auth.priority, 'small_name': auth.small_name, 'users_count': auth.users.count(), 'type': type_.type(), 'permission': permissions.getEffectivePermission(self._user, auth) }
def osmToDict(self, osm): type_ = osm.getType() return { 'id': osm.uuid, 'name': osm.name, 'tags': [tag.tag for tag in osm.tags.all()], 'deployed_count': osm.deployedServices.count(), 'type': type_.type(), 'type_name': type_.name(), 'servicesTypes': type_.servicesType, 'comments': osm.comments, 'permission': permissions.getEffectivePermission(self._user, osm) }
def getItems(self, parent, item): # Check what kind of access do we have to parent provider perm = permissions.getEffectivePermission(self._user, parent) try: if item is None: return [Services.serviceToDict(k, perm) for k in parent.services.all()] else: k = parent.services.get(uuid=processUuid(item)) val = Services.serviceToDict(k, perm, full=True) return self.fillIntanceFields(k, val) except Exception: logger.exception('itemId {}'.format(item)) self.invalidItemException()
def item_as_dict(self, item): type_ = item.getType() return { 'id': item.uuid, 'name': item.name, 'comments': item.comments, 'priority': item.priority, 'nets_positive': item.nets_positive, 'networks': [{'id': n.id} for n in item.networks.all()], 'deployed_count': item.deployedServices.count(), 'type': type_.type(), 'permission': permissions.getEffectivePermission(self._user, item) }
def item_as_dict(self, proxy): return { 'id': proxy.uuid, 'name': proxy.name, 'tags': [tag.tag for tag in proxy.tags.all()], 'comments': proxy.comments, 'url': proxy.url, 'host': proxy.host, 'port': proxy.port, 'ssl': proxy.ssl, 'check_cert': proxy.check_cert, 'permission': permissions.getEffectivePermission(self._user, proxy) }
def item_as_dict(self, item: Proxy) -> typing.Dict[str, typing.Any]: return { 'id': item.uuid, 'name': item.name, 'tags': [tag.tag for tag in item.tags.all()], 'comments': item.comments, 'url': item.url, 'host': item.host, 'port': item.port, 'ssl': item.ssl, 'check_cert': item.check_cert, 'permission': permissions.getEffectivePermission(self._user, item) }
def getItems(self, parent: 'Account', item: typing.Optional[str]): # Check what kind of access do we have to parent provider perm = permissions.getEffectivePermission(self._user, parent) try: if not item: return [ AccountsUsage.usageToDict(k, perm) for k in parent.usages.all() ] k = parent.usages.get(uuid=processUuid(item)) return AccountsUsage.usageToDict(k, perm) except Exception: logger.exception('itemId %s', item) raise self.invalidItemException()
def item_as_dict(self, auth): type_ = auth.getType() return { 'numeric_id': auth.id, 'id': auth.uuid, 'name': auth.name, 'tags': [tag.tag for tag in auth.tags.all()], 'comments': auth.comments, 'priority': auth.priority, 'small_name': auth.small_name, 'users_count': auth.users.count(), 'type': type_.type(), 'permission': permissions.getEffectivePermission(self._user, auth) }
def item_as_dict(self, item): type_ = item.getType() return { 'id': item.uuid, 'name': item.name, 'comments': item.comments, 'priority': item.priority, 'nets_positive': item.nets_positive, 'networks': [{ 'id': n.id } for n in item.networks.all()], 'deployed_count': item.deployedServices.count(), 'type': type_.type(), 'permission': permissions.getEffectivePermission(self._user, item) }
def getItems(self, parent, item): # Check what kind of access do we have to parent provider perm = permissions.getEffectivePermission(self._user, parent) try: if item is None: return [ AccountsUsage.usageToDict(k, perm) for k in parent.usages.all() ] else: k = parent.usages.get(uuid=processUuid(item)) return AccountsUsage.usageToDict(k, perm) except Exception: logger.exception('itemId %s', item) self.invalidItemException()
def item_as_dict(self, auth): type_ = auth.getType() return { 'numeric_id': auth.id, 'id': auth.uuid, 'name': auth.name, 'tags': [tag.tag for tag in auth.tags.all()], 'comments': auth.comments, 'priority': auth.priority, 'small_name': auth.small_name, 'users_count': auth.users.count(), 'type': type_.type(), 'type_info': self.typeInfo(type_), 'permission': permissions.getEffectivePermission(self._user, auth) }
def item_as_dict(self, item): # if item does not have an associated service, hide it (the case, for example, for a removed service) # Access from dict will raise an exception, and item will be skipped val = { 'id': item.uuid, 'name': item.name, 'parent': item.service.name, 'comments': item.comments, 'state': item.state if item.service.provider.maintenance_mode is False else State.MAINTENANCE, 'thumb': item.image.thumb64 if item.image is not None else DEFAULT_THUMB_BASE64, 'service_id': item.service.uuid, 'provider_id': item.service.provider.uuid, 'image_id': item.image.uuid if item.image is not None else None, 'initial_srvs': item.initial_srvs, 'cache_l1_srvs': item.cache_l1_srvs, 'cache_l2_srvs': item.cache_l2_srvs, 'max_srvs': item.max_srvs, 'user_services_count': item.userServices.count(), 'restrained': item.isRestrained(), 'show_transports': item.show_transports, 'permission': permissions.getEffectivePermission(self._user, item), 'info': Services.serviceInfo(item.service) } if item.osmanager is not None: val['osmanager_id'] = item.osmanager.uuid return val
def item_as_dict(self, item): type_ = item.getType() return { 'id': item.uuid, 'name': item.name, 'tags': [tag.tag for tag in item.tags.all()], 'comments': item.comments, 'priority': item.priority, 'nets_positive': item.nets_positive, 'networks': [{'id': n.id} for n in item.networks.all()], 'allowed_oss': [{'id': x} for x in item.allowed_oss.split(',')] if item.allowed_oss != '' else [], 'deployed_count': item.deployedServices.count(), 'type': type_.type(), 'protocol': type_.protocol, 'permission': permissions.getEffectivePermission(self._user, item) }
def getItems(self, parent, item): # Check what kind of access do we have to parent provider perm = permissions.getEffectivePermission(self._user, parent) try: if item is None: return [ Services.serviceToDict(k, perm) for k in parent.services.all() ] else: k = parent.services.get(uuid=item) val = Services.serviceToDict(k, perm, full=True) return self.fillIntanceFields(k, val) except Exception: logger.exception('itemId {}'.format(item)) self.invalidItemException()
def item_as_dict(self, item: Authenticator) -> typing.Dict[str, typing.Any]: type_ = item.getType() return { 'numeric_id': item.id, 'id': item.uuid, 'name': item.name, 'tags': [tag.tag for tag in item.tags.all()], 'comments': item.comments, 'priority': item.priority, 'small_name': item.small_name, 'users_count': item.users.count(), 'type': type_.type(), 'type_name': type_.name(), 'type_info': self.typeInfo(type_), 'permission': permissions.getEffectivePermission(self._user, item) }
def item_as_dict(self, item: MetaPool) -> typing.Dict[str, typing.Any]: # if item does not have an associated service, hide it (the case, for example, for a removed service) # Access from dict will raise an exception, and item will be skipped poolGroupId = None poolGroupName = _('Default') poolGroupThumb = DEFAULT_THUMB_BASE64 if item.servicesPoolGroup is not None: poolGroupId = item.servicesPoolGroup.uuid poolGroupName = item.servicesPoolGroup.name if item.servicesPoolGroup.image is not None: poolGroupThumb = item.servicesPoolGroup.image.thumb64 allPools = item.members.all() userServicesCount = sum( (i.pool.userServices.exclude(state__in=State.INFO_STATES).count() for i in allPools)) userServicesInPreparation = sum( (i.pool.userServices.filter(state=State.PREPARING).count()) for i in allPools) val = { 'id': item.uuid, 'name': item.name, 'short_name': item.short_name, 'tags': [tag.tag for tag in item.tags.all()], 'comments': item.comments, 'thumb': item.image.thumb64 if item.image is not None else DEFAULT_THUMB_BASE64, 'image_id': item.image.uuid if item.image is not None else None, 'servicesPoolGroup_id': poolGroupId, 'pool_group_name': poolGroupName, 'pool_group_thumb': poolGroupThumb, 'user_services_count': userServicesCount, 'user_services_in_preparation': userServicesInPreparation, 'visible': item.visible, 'policy': item.policy, 'fallbackAccess': item.fallbackAccess, 'permission': permissions.getEffectivePermission(self._user, item), 'calendar_message': item.calendar_message, 'transport_grouping': item.transport_grouping } return val
def item_as_dict(self, provider): type_ = provider.getType() # Icon can have a lot of data (1-2 Kbytes), but it's not expected to have a lot of services providers, and even so, this will work fine offers = [{ 'name': ugettext(t.name()), 'type': t.type(), 'description': ugettext(t.description()), 'icon': t.icon().replace('\n', '')} for t in type_.getServicesTypes()] return { 'id': provider.uuid, 'name': provider.name, 'services_count': provider.services.count(), 'user_services_count': UserService.objects.filter(deployed_service__service__provider=provider).count(), 'maintenance_mode': provider.maintenance_mode, 'offers': offers, 'type': type_.type(), 'comments': provider.comments, 'permission': permissions.getEffectivePermission(self._user, provider) }
def item_as_dict(self, item: MetaPool): # if item does not have an associated service, hide it (the case, for example, for a removed service) # Access from dict will raise an exception, and item will be skipped poolGroupId = None poolGroupName = _('Default') poolGroupThumb = DEFAULT_THUMB_BASE64 if item.servicesPoolGroup is not None: poolGroupId = item.servicesPoolGroup.uuid poolGroupName = item.servicesPoolGroup.name if item.servicesPoolGroup.image is not None: poolGroupThumb = item.servicesPoolGroup.image.thumb64 allPools = item.pools.all() userServicesCount = sum((i.userServices.exclude(state__in=State.INFO_STATES).count() for i in allPools)) userServicesInPreparation = sum((i.userServices.filter(state=State.PREPARING).count()) for i in allPools) val = { 'id': item.uuid, 'name': item.name, 'short_name': item.short_name, 'tags': [tag.tag for tag in item.tags.all()], 'comments': item.comments, 'thumb': item.image.thumb64 if item.image is not None else DEFAULT_THUMB_BASE64, 'image_id': item.image.uuid if item.image is not None else None, 'servicesPoolGroup_id': poolGroupId, 'pool_group_name': poolGroupName, 'pool_group_thumb': poolGroupThumb, 'user_services_count': userServicesCount, 'user_services_in_preparation': userServicesInPreparation, 'visible': item.visible, 'policy': item.policy, 'fallbackAccess': item.fallbackAccess, 'permission': permissions.getEffectivePermission(self._user, item), } return val
def item_as_dict(self, item): summary = 'summarize' in self._params # if item does not have an associated service, hide it (the case, for example, for a removed service) # Access from dict will raise an exception, and item will be skipped poolGroupId = None poolGroupName = _('Default') poolGroupThumb = DEFAULT_THUMB_BASE64 if item.servicesPoolGroup is not None: poolGroupId = item.servicesPoolGroup.uuid poolGroupName = item.servicesPoolGroup.name if item.servicesPoolGroup.image is not None: poolGroupThumb = item.servicesPoolGroup.image.thumb64 state = item.state if item.isInMaintenance(): state = State.MAINTENANCE elif userServiceManager().canInitiateServiceFromDeployedService( item) is False: state = State.SLOWED_DOWN val = { 'id': item.uuid, 'name': item.name, 'short_name': item.short_name, 'tags': [tag.tag for tag in item.tags.all()], 'parent': item.service.name, 'parent_type': item.service.data_type, 'comments': item.comments, 'state': state, 'thumb': item.image.thumb64 if item.image is not None else DEFAULT_THUMB_BASE64, 'account': item.account.name if item.account is not None else '', 'account_id': item.account.uuid if item.account is not None else None, 'service_id': item.service.uuid, 'provider_id': item.service.provider.uuid, 'image_id': item.image.uuid if item.image is not None else None, 'initial_srvs': item.initial_srvs, 'cache_l1_srvs': item.cache_l1_srvs, 'cache_l2_srvs': item.cache_l2_srvs, 'max_srvs': item.max_srvs, 'show_transports': item.show_transports, 'visible': item.visible, 'allow_users_remove': item.allow_users_remove, 'allow_users_reset': item.allow_users_reset, 'ignores_unused': item.ignores_unused, 'fallbackAccess': item.fallbackAccess, 'meta_member': [{ 'id': i.uuid, 'name': i.name } for i in item.meta.all()], } # Extended info if not summary: state = item.state if item.isInMaintenance(): state = State.MAINTENANCE elif userServiceManager().canInitiateServiceFromDeployedService( item) is False: state = State.SLOWED_DOWN poolGroupId = None poolGroupName = _('Default') poolGroupThumb = DEFAULT_THUMB_BASE64 if item.servicesPoolGroup is not None: poolGroupId = item.servicesPoolGroup.uuid poolGroupName = item.servicesPoolGroup.name if item.servicesPoolGroup.image is not None: poolGroupThumb = item.servicesPoolGroup.image.thumb64 val['state'] = state val['thumb'] = item.image.thumb64 if item.image is not None else DEFAULT_THUMB_BASE64 val['user_services_count'] = item.userServices.exclude( state__in=State.INFO_STATES).count() val['user_services_in_preparation'] = item.userServices.filter( state=State.PREPARING).count() val['tags'] = [tag.tag for tag in item.tags.all()] val['restrained'] = item.isRestrained() val['permission'] = permissions.getEffectivePermission( self._user, item) val['info'] = Services.serviceInfo(item.service) val['pool_group_id'] = poolGroupId val['pool_group_name'] = poolGroupName val['pool_group_thumb'] = poolGroupThumb val['usage'] = item.usage() if item.osmanager is not None: val['osmanager_id'] = item.osmanager.uuid return val
def item_as_dict(self, item: ServicePool) -> typing.Dict[str, typing.Any]: summary = 'summarize' in self._params # if item does not have an associated service, hide it (the case, for example, for a removed service) # Access from dict will raise an exception, and item will be skipped poolGroupId: typing.Optional[str] = None poolGroupName: str = _('Default') poolGroupThumb: str = DEFAULT_THUMB_BASE64 if item.servicesPoolGroup: poolGroupId = item.servicesPoolGroup.uuid poolGroupName = item.servicesPoolGroup.name if item.servicesPoolGroup.image: poolGroupThumb = item.servicesPoolGroup.image.thumb64 state = item.state if item.isInMaintenance(): state = State.MAINTENANCE # This needs a lot of queries, and really does not shows anything important i think... # elif userServiceManager().canInitiateServiceFromDeployedService(item) is False: # state = State.SLOWED_DOWN val = { 'id': item.uuid, 'name': item.name, 'short_name': item.short_name, 'tags': [tag.tag for tag in item.tags.all()], 'parent': item.service.name, 'parent_type': item.service.data_type, 'comments': item.comments, 'state': state, 'thumb': item.image.thumb64 if item.image is not None else DEFAULT_THUMB_BASE64, 'account': item.account.name if item.account is not None else '', 'account_id': item.account.uuid if item.account is not None else None, 'service_id': item.service.uuid, 'provider_id': item.service.provider.uuid, 'image_id': item.image.uuid if item.image is not None else None, 'initial_srvs': item.initial_srvs, 'cache_l1_srvs': item.cache_l1_srvs, 'cache_l2_srvs': item.cache_l2_srvs, 'max_srvs': item.max_srvs, 'show_transports': item.show_transports, 'visible': item.visible, 'allow_users_remove': item.allow_users_remove, 'allow_users_reset': item.allow_users_reset, 'ignores_unused': item.ignores_unused, 'fallbackAccess': item.fallbackAccess, 'meta_member': [{ 'id': i.uuid, 'name': i.name } for i in item.meta.all()], 'calendar_message': item.calendar_message, } # Extended info if not summary: if hasattr(item, 'valid_count'): valid_count = item.valid_count preparing_count = item.preparing_count restrained = item.error_count > GlobalConfig.RESTRAINT_COUNT.getInt( ) usage_count = item.usage_count else: valid_count = item.userServices.exclude( state__in=State.INFO_STATES).count() preparing_count = item.userServices.filter( state=State.PREPARING).count() restrained = item.isRestrained() usage_count = -1 poolGroupId = None poolGroupName = _('Default') poolGroupThumb = DEFAULT_THUMB_BASE64 if item.servicesPoolGroup is not None: poolGroupId = item.servicesPoolGroup.uuid poolGroupName = item.servicesPoolGroup.name if item.servicesPoolGroup.image is not None: poolGroupThumb = item.servicesPoolGroup.image.thumb64 val['state'] = state val['thumb'] = item.image.thumb64 if item.image is not None else DEFAULT_THUMB_BASE64 val['user_services_count'] = valid_count val['user_services_in_preparation'] = preparing_count val['tags'] = [tag.tag for tag in item.tags.all()] val['restrained'] = restrained val['permission'] = permissions.getEffectivePermission( self._user, item) val['info'] = Services.serviceInfo(item.service) val['pool_group_id'] = poolGroupId val['pool_group_name'] = poolGroupName val['pool_group_thumb'] = poolGroupThumb val['usage'] = str(item.usage(usage_count)) + '%' if item.osmanager: val['osmanager_id'] = item.osmanager.uuid return val
def ensureAccess(self, obj, permission, root=False): perm = permissions.getEffectivePermission(self._user, obj, root) if perm < permission: self.accessDenied() return perm