Esempio n. 1
0
def getServicesPoolsCounters(servicePool, counter_type):
    # pylint: disable=no-value-for-parameter
    try:
        cacheKey = (servicePool and servicePool.id or 'all') + str(counter_type) + str(POINTS) + str(SINCE)
        to = getSqlDatetime()
        since = to - timedelta(days=SINCE)
        val = cache.get(cacheKey)
        if val is None:
            if servicePool is None:
                us = ServicePool()
                complete = True  # Get all deployed services stats
            else:
                us = servicePool
                complete = False
            val = []
            for x in counters.getCounters(us, counter_type, since=since, to=to, limit=POINTS, use_max=USE_MAX, all=complete):
                val.append({'stamp': x[0], 'value': int(x[1])})
            if len(val) > 2:
                cache.put(cacheKey, encoders.encode(pickle.dumps(val), 'zip') , 600)
            else:
                val = [{'stamp': since, 'value': 0}, {'stamp': to, 'value': 0}]
        else:
            val = pickle.loads(encoders.decode(val, 'zip'))

        return val
    except:
        logger.exception('exception')
        raise ResponseError('can\'t create stats for objects!!!')
Esempio n. 2
0
    def cancel(self, parent, uuid):
        """
        Invoked to cancel a running publication
        Double invocation (this means, invoking cancel twice) will mean that is a "forced cancelation"
        :param parent: Parent service pool
        :param uuid: uuid of the publication
        """
        if permissions.checkPermissions(
                self._user, parent,
                permissions.PERMISSION_MANAGEMENT) is False:
            logger.debug('Management Permission failed for user {}'.format(
                self._user))
            self.accessDenied()

        try:
            ds = DeployedServicePublication.objects.get(uuid=processUuid(uuid))
            ds.cancel()
        except Exception as e:
            raise ResponseError("{}".format(e))

        log.doLog(
            parent, log.INFO, "Canceled publication v{} by {}".format(
                parent.current_pub_revision, self._user.pretty_name),
            log.ADMIN)

        return self.success()
Esempio n. 3
0
    def getGui(self, parent: 'Provider',
               forType: str) -> typing.Iterable[typing.Any]:
        try:
            logger.debug('getGui parameters: %s, %s', parent, forType)
            parentInstance = parent.getInstance()
            serviceType = parentInstance.getServiceByType(forType)
            if not serviceType:
                raise self.invalidItemException(
                    'Gui for {} not found'.format(forType))

            service = serviceType(
                Environment.getTempEnv(), parentInstance
            )  # Instantiate it so it has the opportunity to alter gui description based on parent
            localGui = self.addDefaultFields(service.guiDescription(service),
                                             ['name', 'comments', 'tags'])
            if GlobalConfig.EXPERIMENTAL_FEATURES.getBool():
                self.addField(
                    localGui,
                    {
                        'name':
                        'proxy_id',
                        'values':
                        [gui.choiceItem(-1, '')] + gui.sortedChoices([
                            gui.choiceItem(v.uuid, v.name)
                            for v in models.Proxy.objects.all()
                        ]),
                        'label':
                        _('Proxy'),
                        'tooltip':
                        _('Proxy for services behind a firewall'),
                        'type':
                        gui.InputField.CHOICE_TYPE,
                        'tab':
                        _('Advanced'),
                        'order':
                        132,
                    },
                )
            else:
                self.addField(
                    localGui,
                    {
                        'name': 'proxy_id',
                        'value': '-1',
                        'type': gui.InputField.HIDDEN_TYPE,
                    },
                )

            return localGui

        except Exception as e:
            logger.exception('getGui')
            raise ResponseError(str(e))
Esempio n. 4
0
 def getGui(self, parent, forType):
     try:
         logger.debug('getGui parameters: {0}, {1}'.format(parent, forType))
         parentInstance = parent.getInstance()
         serviceType = parentInstance.getServiceByType(forType)
         service = serviceType(
             Environment.getTempEnv(), parentInstance
         )  # Instantiate it so it has the opportunity to alter gui description based on parent
         return self.addDefaultFields(service.guiDescription(service),
                                      ['name', 'comments'])
     except Exception as e:
         logger.exception('getGui')
         raise ResponseError(unicode(e))
Esempio n. 5
0
def getServicesPoolsCounters(
        servicePool: typing.Optional[models.ServicePool],
        counter_type: int) -> typing.List[typing.Mapping[str, typing.Any]]:
    try:
        cacheKey = ((servicePool and str(servicePool.id) or 'all') +
                    str(counter_type) + str(POINTS) + str(SINCE))
        to = models.getSqlDatetime()
        since: datetime.datetime = to - datetime.timedelta(days=SINCE)

        cachedValue: typing.Optional[bytes] = cache.get(cacheKey)
        if not cachedValue:
            if not servicePool:
                us = models.ServicePool()
                complete = True  # Get all deployed services stats
            else:
                us = servicePool
                complete = False
            val: typing.List[typing.Mapping[str, typing.Any]] = []
            for x in counters.getCounters(
                    us,
                    counter_type,
                    since=since,
                    to=to,
                    max_intervals=POINTS,
                    use_max=USE_MAX,
                    all=complete,
            ):
                val.append({'stamp': x[0], 'value': int(x[1])})
            if len(val) > 2:
                cache.put(cacheKey, codecs.encode(pickle.dumps(val), 'zip'),
                          600)
            else:
                val = [{'stamp': since, 'value': 0}, {'stamp': to, 'value': 0}]
        else:
            val = pickle.loads(codecs.decode(cachedValue, 'zip'))

        # return [{'stamp': since + datetime.timedelta(hours=i*10), 'value': i*i} for i in range(300)]
        return val
    except:
        logger.exception('exception')
        raise ResponseError('can\'t create stats for objects!!!')
Esempio n. 6
0
    def cancel(self, parent, uuid):
        """
        Invoked to cancel a running publication
        Double invocation (this means, invoking cancel twice) will mean that is a "forced cancelation"
        :param parent: Parent service pool
        :param uuid: uuid of the publication
        """
        if permissions.checkPermissions(
                self._user, parent,
                permissions.PERMISSION_MANAGEMENT) is False:
            logger.debug('Management Permission failed for user {}'.format(
                self._user))
            self.accessDenied()

        try:
            ds = DeployedServicePublication.objects.get(uuid=processUuid(uuid))
            ds.cancel()
        except Exception as e:
            raise ResponseError(six.text_type(e))

        return self.success()
Esempio n. 7
0
def getServicesPoolsCounters(
        servicePool: typing.Optional[models.ServicePool],
        counter_type: int) -> typing.List[typing.Dict[str, typing.Any]]:
    # pylint: disable=no-value-for-parameter
    try:
        cacheKey = (servicePool and servicePool.id
                    or 'all') + str(counter_type) + str(POINTS) + str(SINCE)
        to = models.getSqlDatetime()
        since: datetime.datetime = to - datetime.timedelta(days=SINCE)

        val: typing.Any = cache.get(cacheKey)
        if not val:
            if not servicePool:
                us = models.ServicePool()
                complete = True  # Get all deployed services stats
            else:
                us = servicePool
                complete = False
            val = []
            for x in counters.getCounters(us,
                                          counter_type,
                                          since=since,
                                          to=to,
                                          max_intervals=POINTS,
                                          use_max=USE_MAX,
                                          all=complete):
                val.append({'stamp': x[0], 'value': int(x[1])})
            if len(val) > 2:
                cache.put(cacheKey, encoders.encode(pickle.dumps(val), 'zip'),
                          600)
            else:
                val = [{'stamp': since, 'value': 0}, {'stamp': to, 'value': 0}]
        else:
            val = pickle.loads(typing.cast(bytes, encoders.decode(val, 'zip')))

        return val
    except:
        logger.exception('exception')
        raise ResponseError('can\'t create stats for objects!!!')
Esempio n. 8
0
    def getGui(self, parent, forType):
        try:
            logger.debug('getGui parameters: {0}, {1}'.format(parent, forType))
            parentInstance = parent.getInstance()
            serviceType = parentInstance.getServiceByType(forType)
            service = serviceType(
                Environment.getTempEnv(), parentInstance
            )  # Instantiate it so it has the opportunity to alter gui description based on parent
            g = self.addDefaultFields(service.guiDescription(service),
                                      ['name', 'comments', 'tags'])
            for f in [
                {
                    'name':
                    'proxy_id',
                    'values': [gui.choiceItem(-1, '')] + gui.sortedChoices([
                        gui.choiceItem(v.uuid, v.name)
                        for v in Proxy.objects.all()
                    ]),
                    'label':
                    _('Proxy'),
                    'tooltip':
                    _('Proxy for services behind a firewall'),
                    'type':
                    gui.InputField.CHOICE_TYPE,
                    'tab':
                    _('Advanced'),
                    'order':
                    132,
                },
            ]:
                self.addField(g, f)

            return g

        except Exception as e:
            logger.exception('getGui')
            raise ResponseError(six.text_type(e))
Esempio n. 9
0
    def getGui(self, type_):
        if OSManager.objects.count() < 1:  # No os managers, can't create db
            raise ResponseError(
                ugettext(
                    'Create at least one OS Manager before creating a new service pool'
                ))
        if Service.objects.count() < 1:
            raise ResponseError(
                ugettext(
                    'Create at least a service before creating a new service pool'
                ))

        g = self.addDefaultFields([],
                                  ['name', 'short_name', 'comments', 'tags'])

        for f in [
            {
                'name':
                'service_id',
                'values': [gui.choiceItem('', '')] + gui.sortedChoices([
                    gui.choiceItem(v.uuid, v.provider.name + '\\' + v.name)
                    for v in Service.objects.all()
                ]),
                'label':
                ugettext('Base service'),
                'tooltip':
                ugettext('Service used as base of this service pool'),
                'type':
                gui.InputField.CHOICE_TYPE,
                'rdonly':
                True,
                'order':
                100,  # Ensueres is At end
            },
            {
                'name':
                'osmanager_id',
                'values': [gui.choiceItem(-1, '')] + gui.sortedChoices([
                    gui.choiceItem(v.uuid, v.name)
                    for v in OSManager.objects.all()
                ]),
                'label':
                ugettext('OS Manager'),
                'tooltip':
                ugettext('OS Manager used as base of this service pool'),
                'type':
                gui.InputField.CHOICE_TYPE,
                'rdonly':
                True,
                'order':
                101,
            },
            {
                'name':
                'show_transports',
                'value':
                True,
                'label':
                ugettext('Show transports'),
                'tooltip':
                ugettext(
                    'If active, alternative transports for user will be shown'
                ),
                'type':
                gui.InputField.CHECKBOX_TYPE,
                'order':
                110,
                'tab':
                ugettext('Advanced'),
            },
            {
                'name':
                'allow_users_remove',
                'value':
                False,
                'label':
                ugettext('Allow removal by users'),
                'tooltip':
                ugettext(
                    'If active, the user will be allowed to remove the service "manually". Be careful with this, because the user will have the "power" to delete it\'s own service'
                ),
                'type':
                gui.InputField.CHECKBOX_TYPE,
                'order':
                111,
                'tab':
                ugettext('Advanced'),
            },
            {
                'name':
                'allow_users_reset',
                'value':
                False,
                'label':
                ugettext('Allow reset by users'),
                'tooltip':
                ugettext(
                    'If active, the user will be allowed to reset the service'
                ),
                'type':
                gui.InputField.CHECKBOX_TYPE,
                'order':
                112,
                'tab':
                ugettext('Advanced'),
            },
            {
                'name':
                'ignores_unused',
                'value':
                False,
                'label':
                ugettext('Ignores unused'),
                'tooltip':
                ugettext(
                    'If the option is enabled, UDS will not attempt to detect and remove the user services assigned but not in use.'
                ),
                'type':
                gui.InputField.CHECKBOX_TYPE,
                'order':
                113,
                'tab':
                ugettext('Advanced'),
            },
            {
                'name':
                'image_id',
                'values':
                [gui.choiceImage(-1, '--------', DEFAULT_THUMB_BASE64)] +
                gui.sortedChoices([
                    gui.choiceImage(v.uuid, v.name, v.thumb64)
                    for v in Image.objects.all()
                ]),
                'label':
                ugettext('Associated Image'),
                'tooltip':
                ugettext('Image assocciated with this service'),
                'type':
                gui.InputField.IMAGECHOICE_TYPE,
                'order':
                120,
                'tab':
                ugettext('Display'),
            },
            {
                'name':
                'servicesPoolGroup_id',
                'values':
                [gui.choiceImage(-1, _('Default'), DEFAULT_THUMB_BASE64)] +
                gui.sortedChoices([
                    gui.choiceImage(v.uuid, v.name, v.thumb64)
                    for v in ServicesPoolGroup.objects.all()
                ]),
                'label':
                ugettext('Pool group'),
                'tooltip':
                ugettext(
                    'Pool group for this pool (for pool classify on display)'),
                'type':
                gui.InputField.IMAGECHOICE_TYPE,
                'order':
                121,
                'tab':
                ugettext('Display'),
            },
            {
                'name':
                'visible',
                'value':
                True,
                'label':
                ugettext('Visible'),
                'tooltip':
                ugettext('If active, transport will be visible for users'),
                'type':
                gui.InputField.CHECKBOX_TYPE,
                'order':
                107,
                'tab':
                ugettext('Display'),
            },
            {
                'name':
                'initial_srvs',
                'value':
                '0',
                'minValue':
                '0',
                'label':
                ugettext('Initial available services'),
                'tooltip':
                ugettext('Services created initially for this service pool'),
                'type':
                gui.InputField.NUMERIC_TYPE,
                'order':
                130,
                'tab':
                ugettext('Availability'),
            },
            {
                'name':
                'cache_l1_srvs',
                'value':
                '0',
                'minValue':
                '0',
                'label':
                ugettext('Services to keep in cache'),
                'tooltip':
                ugettext(
                    'Services kept in cache for improved user service assignation'
                ),
                'type':
                gui.InputField.NUMERIC_TYPE,
                'order':
                131,
                'tab':
                ugettext('Availability'),
            },
            {
                'name':
                'cache_l2_srvs',
                'value':
                '0',
                'minValue':
                '0',
                'label':
                ugettext('Services to keep in L2 cache'),
                'tooltip':
                ugettext(
                    'Services kept in cache of level2 for improved service generation'
                ),
                'type':
                gui.InputField.NUMERIC_TYPE,
                'order':
                132,
                'tab':
                ugettext('Availability'),
            },
            {
                'name':
                'max_srvs',
                'value':
                '0',
                'minValue':
                '1',
                'label':
                ugettext('Maximum number of services to provide'),
                'tooltip':
                ugettext(
                    'Maximum number of service (assigned and L1 cache) that can be created for this service'
                ),
                'type':
                gui.InputField.NUMERIC_TYPE,
                'order':
                133,
                'tab':
                ugettext('Availability'),
            },
            {
                'name':
                'show_transports',
                'value':
                True,
                'label':
                ugettext('Show transports'),
                'tooltip':
                ugettext(
                    'If active, alternative transports for user will be shown'
                ),
                'type':
                gui.InputField.CHECKBOX_TYPE,
                'tab':
                ugettext('Advanced'),
                'order':
                130,
            },
            {
                'name':
                'account_id',
                'values': [gui.choiceItem(-1, '')] + gui.sortedChoices([
                    gui.choiceItem(v.uuid, v.name)
                    for v in Account.objects.all()
                ]),
                'label':
                ugettext('Accounting'),
                'tooltip':
                ugettext('Account associated to this service pool'),
                'type':
                gui.InputField.CHOICE_TYPE,
                'tab':
                ugettext('Advanced'),
                'order':
                131,
            }
        ]:
            self.addField(g, f)

        return g
Esempio n. 10
0
    def getGui(self, type_):
        if OSManager.objects.count() < 1:  # No os managers, can't create db
            raise ResponseError(
                ugettext(
                    'Create at least one OS Manager before creating a new service pool'
                ))
        if Service.objects.count() < 1:
            raise ResponseError(
                ugettext(
                    'Create at least a service before creating a new service pool'
                ))

        g = self.addDefaultFields([], ['name', 'comments'])

        for f in [
            {
                'name':
                'service_id',
                'values': [gui.choiceItem(-1, '')] + gui.sortedChoices([
                    gui.choiceItem(v.uuid, v.provider.name + '\\' + v.name)
                    for v in Service.objects.all()
                ]),
                'label':
                ugettext('Base service'),
                'tooltip':
                ugettext('Service used as base of this service pool'),
                'type':
                gui.InputField.CHOICE_TYPE,
                'rdonly':
                True,
                'order':
                100,  # Ensueres is At end
            },
            {
                'name':
                'osmanager_id',
                'values': [gui.choiceItem(-1, '')] + gui.sortedChoices([
                    gui.choiceItem(v.uuid, v.name)
                    for v in OSManager.objects.all()
                ]),
                'label':
                ugettext('OS Manager'),
                'tooltip':
                ugettext('OS Manager used as base of this service pool'),
                'type':
                gui.InputField.CHOICE_TYPE,
                'rdonly':
                True,
                'order':
                101,
            },
            {
                'name':
                'image_id',
                'values': [gui.choiceItem(-1, '')] + gui.sortedChoices([
                    gui.choiceItem(v.uuid, v.name)
                    for v in Image.objects.all()
                ]),
                'label':
                ugettext('Associated Image'),
                'tooltip':
                ugettext('Image assocciated with this service'),
                'type':
                gui.InputField.CHOICE_TYPE,
                'order':
                102,
            },
            {
                'name':
                'initial_srvs',
                'value':
                '0',
                'minValue':
                '0',
                'label':
                ugettext('Initial available services'),
                'tooltip':
                ugettext('Services created initially for this service pool'),
                'type':
                gui.InputField.NUMERIC_TYPE,
                'order':
                103,
            },
            {
                'name':
                'cache_l1_srvs',
                'value':
                '0',
                'minValue':
                '0',
                'label':
                ugettext('Services to keep in cache'),
                'tooltip':
                ugettext(
                    'Services kept in cache for improved user service assignation'
                ),
                'type':
                gui.InputField.NUMERIC_TYPE,
                'order':
                104,
            },
            {
                'name':
                'cache_l2_srvs',
                'value':
                '0',
                'minValue':
                '0',
                'label':
                ugettext('Services to keep in L2 cache'),
                'tooltip':
                ugettext(
                    'Services kept in cache of level2 for improved service generation'
                ),
                'type':
                gui.InputField.NUMERIC_TYPE,
                'order':
                105,
            },
            {
                'name':
                'max_srvs',
                'value':
                '0',
                'minValue':
                '1',
                'label':
                ugettext('Maximum number of services to provide'),
                'tooltip':
                ugettext(
                    'Maximum number of service (assigned and L1 cache) that can be created for this service'
                ),
                'type':
                gui.InputField.NUMERIC_TYPE,
                'order':
                106,
            },
            {
                'name':
                'show_transports',
                'value':
                True,
                'label':
                ugettext('Show transports'),
                'tooltip':
                ugettext(
                    'If active, alternative transports for user will be shown'
                ),
                'type':
                gui.InputField.CHECKBOX_TYPE,
                'order':
                107,
            }
        ]:
            self.addField(g, f)

        return g