Пример #1
0
 def _deleteIncompleteService(self, service: Service):  # pylint: disable=no-self-use
     """
     Deletes a service if it is needed to (that is, if it is not None) and silently catch any exception of this operation
     :param service:  Service to delete (may be None, in which case it does nothing)
     """
     if service:
         try:
             service.delete()
         except Exception:
             pass
Пример #2
0
    def serviceToDict(
        item: models.Service, perm: int, full: bool = False
    ) -> typing.Dict[str, typing.Any]:
        """
        Convert a service db item to a dict for a rest response
        :param item: Service item (db)
        :param full: If full is requested, add "extra" fields to complete information
        """
        itemType = item.getType()
        retVal = {
            'id': item.uuid,
            'name': item.name,
            'tags': [tag.tag for tag in item.tags.all()],
            'comments': item.comments,
            'type': item.data_type,
            'type_name': _(itemType.name()),
            'proxy_id': item.proxy.uuid if item.proxy is not None else '-1',
            'proxy': item.proxy.name if item.proxy is not None else '',
            'deployed_services_count': item.deployedServices.count(),
            'user_services_count': models.UserService.objects.filter(
                deployed_service__service=item
            )
            .exclude(state__in=State.INFO_STATES)
            .count(),
            'maintenance_mode': item.provider.maintenance_mode,
            'permission': perm,
        }
        if full:
            retVal['info'] = Services.serviceInfo(item)

        return retVal
Пример #3
0
    def serviceInfo(item: Service) -> typing.Dict[str, typing.Any]:
        info = item.getType()

        return {
            'icon': info.icon64().replace('\n', ''),
            'needs_publication': info.publicationType is not None,
            'max_deployed': info.maxDeployed,
            'uses_cache': info.usesCache and info.cacheConstrains is None,
            'uses_cache_l2': info.usesCache_L2,
            'cache_tooltip': _(info.cacheTooltip),
            'cache_tooltip_l2': _(info.cacheTooltip_L2),
            'needs_manager': info.needsManager,
            'allowedProtocols': info.allowedProtocols,
            'servicesTypeProvided': info.servicesTypeProvided,
            'must_assign_manually': info.mustAssignManually,
            'can_reset': info.canReset,
            'can_list_assignables': info.canAssign()
        }