Ejemplo n.º 1
0
 def getGui(self, type_):
     try:
         return self.addDefaultFields(
             services.factory().lookup(type_).guiDescription(),
             ['name', 'comments', 'tags'])
     except Exception:
         raise NotFound('type not found')
Ejemplo n.º 2
0
    def getDeployedServicesForGroups(groups):
        """
        Return deployed services with publications for the groups requested.

        Args:
            groups: List of groups to check

        Returns:
            List of accesible deployed services
        """
        from uds.core import services
        # Get services that HAS publications
        list1 = DeployedService.objects.filter(
            assignedGroups__in=groups,
            assignedGroups__state=states.group.ACTIVE,
            state=states.servicePool.ACTIVE,
            visible=True).distinct().annotate(
                cuenta=models.Count('publications')).exclude(cuenta=0)
        # Now get deployed services that DO NOT NEED publication
        doNotNeedPublishing = [
            t.type()
            for t in services.factory().servicesThatDoNotNeedPublication()
        ]
        list2 = DeployedService.objects.filter(
            assignedGroups__in=groups,
            assignedGroups__state=states.group.ACTIVE,
            service__data_type__in=doNotNeedPublishing,
            state=states.servicePool.ACTIVE,
            visible=True)
        # And generate a single list without duplicates
        return list(set([r for r in list1] + [r for r in list2]))
Ejemplo n.º 3
0
def __init__():
    """
    This imports all packages that are descendant of this package, and, after that,
    it register all subclases of service provider as
    """
    from uds.core import services

    # Dinamycally import children of this package. The __init__.py files must register, if needed, inside ServiceProviderFactory
    pkgpath = os.path.dirname(sys.modules[__name__].__file__)
    for _, name, _ in pkgutil.iter_modules([pkgpath]):
        # __import__('uds.services.' + name, globals(), locals(), [])
        importlib.import_module('.' + name, __name__)  # import module

    importlib.invalidate_caches()

    for p in [services.ServiceProvider]:
        # This is marked as error in IDE, but it's not (__subclasses__)
        for cls in p.__subclasses__():
            # Skip ClusteredServiceProvider
            services.factory().insert(cls)
Ejemplo n.º 4
0
    def getType(self):
        from uds.core import services
        '''
        Get the type of the object this record represents.

        The type is Python type, it obtains this type from ServiceProviderFactory and associated record field.

        Returns:
            The python type for this record object
        '''
        return services.factory().lookup(self.data_type)
Ejemplo n.º 5
0
    def getType(self):
        from uds.core import services
        '''
        Get the type of the object this record represents.

        The type is Python type, it obtains this type from ServiceProviderFactory and associated record field.

        Returns:
            The python type for this record object
        '''
        return services.factory().lookup(self.data_type)
Ejemplo n.º 6
0
def __init__():
    """
    This imports all packages that are descendant of this package, and, after that,
    it register all subclases of service provider as
    """
    import os.path
    import pkgutil
    import sys
    from uds.core import services

    # Dinamycally import children of this package. The __init__.py files must register, if needed, inside ServiceProviderFactory
    pkgpath = os.path.dirname(sys.modules[__name__].__file__)
    for _, name, _ in pkgutil.iter_modules([pkgpath]):
        __import__('uds.services.' + name, globals(), locals(), [])

    for p in [services.ServiceProvider, services.ClusteredServiceProvider]:
        # This is marked as error in IDE, but it's not (__subclasses__)
        for cls in p.__subclasses__():
            # Skip ClusteredServiceProvider
            if cls is services.ClusteredServiceProvider:
                continue
            services.factory().insert(cls)
Ejemplo n.º 7
0
    def getDeployedServicesForGroups(groups: typing.Iterable['Group'], user: typing.Optional['User'] = None) -> typing.List['ServicePool']:
        """ 
        Return deployed services with publications for the groups requested.

        Args:
            groups: List of groups to check

        Returns:
            List of accesible deployed services
        """
        from uds.core import services
        servicesNotNeedingPub = [t.type() for t in services.factory().servicesThatDoNotNeedPublication()]
        # Get services that HAS publications
        query = (
            ServicePool.objects.filter(
            assignedGroups__in=groups,
            assignedGroups__state=states.group.ACTIVE,
            state=states.servicePool.ACTIVE,
            visible=True
            )
            .annotate(pubs_active=models.Count('publications', filter=models.Q(publications__state=states.publication.USABLE)))
            .annotate(usage_count=models.Count('userServices', filter=models.Q(userServices__state__in=states.userService.VALID_STATES, userServices__cache_level=0)))
            .prefetch_related(
                'transports',
                'transports__networks',
                'memberOfMeta',
                'osmanager',
                'publications',
                'servicesPoolGroup',
                'servicesPoolGroup__image',
                'service',
                'service__provider',
                'calendarAccess',
                'calendarAccess__calendar',
                'calendarAccess__calendar__rules',
                'image'
            )
        )

        if user:  # Optimize loading if there is some assgned service..
            query = query.annotate(
                number_in_use=models.Count(
                    'userServices', filter=models.Q(
                        userServices__user=user,
                        userServices__in_use=True,
                        userServices__state__in=states.userService.USABLE
                    )
                )
            )
        servicePool: 'ServicePool'
        return [servicePool for servicePool in query if servicePool.pubs_active or servicePool.service.data_type in servicesNotNeedingPub]
Ejemplo n.º 8
0
    def getType(self) -> typing.Type['services.ServiceProvider']:
        '''
        Get the type of the object this record represents.

        The type is Python type, it obtains this type from ServiceProviderFactory and associated record field.

        Returns:
            The python type for this record object
        '''
        from uds.core import services  # pylint: disable=redefined-outer-name
        type_ = services.factory().lookup(self.data_type)
        if type_:
            return type_
        return services.ServiceProvider  # Basic Service implementation. Will fail if we try to use it, but will be ok to reference it
Ejemplo n.º 9
0
    def test(self, type_):
        from uds.core.Environment import Environment

        logger.debug('Type: {}'.format(type_))
        spType = services.factory().lookup(type_)

        self.ensureAccess(spType, permissions.PERMISSION_MANAGEMENT, root=True)

        logger.debug('spType: {}'.format(spType))
        res = spType.test(Environment.getTempEnv(), self._params)
        if res[0]:
            return 'ok'
        else:
            return res[1]
Ejemplo n.º 10
0
    def test(self, type_):
        from uds.core.Environment import Environment

        logger.debug('Type: %s', type_)
        spType = services.factory().lookup(type_)

        self.ensureAccess(spType, permissions.PERMISSION_MANAGEMENT, root=True)

        logger.debug('spType: %s', spType)

        dct = self._params.copy()
        dct['_request'] = self._request
        res = spType.test(Environment.getTempEnv(), dct)
        if res[0]:
            return 'ok'
        else:
            return res[1]
Ejemplo n.º 11
0
    def getDeployedServicesForGroups(groups):
        '''
        Return deployed services with publications for the groups requested.

        Args:
            groups: List of groups to check

        Returns:
            List of accesible deployed services
        '''
        from uds.core import services
        # Get services that HAS publications
        list1 = DeployedService.objects.filter(assignedGroups__in=groups, assignedGroups__state=states.group.ACTIVE,
                                               state=states.servicePool.ACTIVE, visible=True).distinct().annotate(cuenta=models.Count('publications')).exclude(cuenta=0)
        # Now get deployed services that DO NOT NEED publication
        doNotNeedPublishing = [t.type() for t in services.factory().servicesThatDoNotNeedPublication()]
        list2 = DeployedService.objects.filter(assignedGroups__in=groups, assignedGroups__state=states.group.ACTIVE, service__data_type__in=doNotNeedPublishing, state=states.servicePool.ACTIVE, visible=True)
        # And generate a single list without duplicates
        return list(set([r for r in list1] + [r for r in list2]))
Ejemplo n.º 12
0
    def test(self, type_: str):
        from uds.core.environment import Environment

        logger.debug('Type: %s', type_)
        spType = services.factory().lookup(type_)

        if not spType:
            raise NotFound('Type not found!')

        tmpEnvironment = Environment.getTempEnv()
        logger.debug('spType: %s', spType)

        dct = self._params.copy()
        dct['_request'] = self._request
        res = spType.test(tmpEnvironment, dct)
        if res[0]:
            return 'ok'

        return res[1]
Ejemplo n.º 13
0
 def enum_types(self):
     return services.factory().providers().values()
Ejemplo n.º 14
0
 def enum_types(self):
     return services.factory().providers().values()
Ejemplo n.º 15
0
 def getGui(self, type_):
     try:
         return self.addDefaultFields(services.factory().lookup(type_).guiDescription(), ['name', 'comments'])
     except Exception:
         raise NotFound('type not found')
Ejemplo n.º 16
0
 def getGui(self, type_: str) -> typing.List[typing.Any]:
     clsType = services.factory().lookup(type_)
     if clsType:
         return self.addDefaultFields(clsType.guiDescription(),
                                      ['name', 'comments', 'tags'])
     raise NotFound('Type not found!')
Ejemplo n.º 17
0
 def enum_types(
         self) -> typing.Iterable[typing.Type[services.ServiceProvider]]:
     return services.factory().providers().values()