Exemple #1
0
    def switch(self, license_group=None, return_to=None, **unused):

        template_args = {
            'is_success': False,
            'return_to': util.make_url_internal(return_to),
            'available_groups': [],
            'license_group': None,
            'license_map': {}
        }

        active_group = None

        # get all data
        licenses = License.all()
        groups = Group.all()

        # get the active group and all licenses associated with it
        for group in groups:

            template_args['available_groups'].append(group.name)
            if group.is_active:
                active_group = group.name

            template_args['license_map'][group.name] = []
            for license in licenses:
                if license.stack_name in group.stack_names and license.status == 'VALID':
                    template_args['license_map'][group.name].append(
                        license.label)

        if cherrypy.request.method == 'POST':

            # redirect user to add license if newly activated group
            # does not have any licenses
            if len(template_args['license_map'].get(license_group, '')) == 0:
                logger.info(
                    '0 licenses found; redirecting user to "add license" page')
                self.redirect_to_url(
                    ['manager', 'system', 'licensing', 'licenses', 'new'],
                    _qs={
                        'return_to':
                        util.make_url_internal(return_to)
                        or cherrypy.request.relative_uri,
                        'prompt_restart':
                        1
                    })

            try:
                for group in groups:
                    if license_group == group.name:
                        group.is_active = True
                        group.save()
                        template_args['is_success'] = True
                        active_group = group.name
                        break
                else:
                    raise Exception, 'cannot activate unknown license group: %s' % license_group

            except Exception, e:
                template_args['controller_exception'] = e
    def switch(self, license_group=None, return_to=None, **unused):

        template_args = {
            'is_success': False,
            'return_to': util.make_url_internal(return_to),
            'available_groups': [],
            'license_group': None,
            'license_map': {}
        }

        active_group = None

        # get all data
        licenses = License.all()
        groups = Group.all()

        # get the active group and all licenses associated with it
        for group in groups:
        
            template_args['available_groups'].append(group.name)
            if group.is_active:
                active_group = group.name

            template_args['license_map'][group.name] = []
            for license in licenses:
                if license.stack_name in group.stack_names and license.status == 'VALID':
                    template_args['license_map'][group.name].append(license.label)


        if cherrypy.request.method == 'POST':

            # redirect user to add license if newly activated group
            # does not have any licenses
            if len(template_args['license_map'].get(license_group, '')) == 0:
                logger.info('0 licenses found; redirecting user to "add license" page')
                self.redirect_to_url(
                    ['manager','system','licensing','licenses','new'], 
                    _qs={
                        'return_to': util.make_url_internal(return_to) or cherrypy.request.relative_uri,
                        'prompt_restart': 1
                    }
                )
            
            try:
                for group in groups:
                    if license_group == group.name:
                        group.is_active = True
                        group.save()
                        template_args['is_success'] = True
                        active_group = group.name
                        break
                else:
                    raise Exception, 'cannot activate unknown license group: %s' % license_group

            except Exception, e:
                template_args['controller_exception'] = e
 def expired(self, formset_mode=None, return_to=None, **unused):
     
     template_args = {
         'can_change_license': False,
         'return_to': util.make_url_internal(return_to) or self.make_url(['manager','system','licensing'])
     }
     
     free_group = None
     try:
         free_group = Group.get(Group.build_id(
             'Free',
             namespace=None,
             owner=None
         ))
         template_args['can_change_license'] = True
     except splunk.AuthorizationFailed:
         pass
     except Exception, e:
         logger.exception(e)
         template_args['controller_exception'] = e
Exemple #4
0
    def expired(self, formset_mode=None, return_to=None, **unused):

        template_args = {
            'can_change_license':
            False,
            'return_to':
            util.make_url_internal(return_to)
            or self.make_url(['manager', 'system', 'licensing'])
        }

        free_group = None
        try:
            free_group = Group.get(
                Group.build_id('Free', namespace=None, owner=None))
            template_args['can_change_license'] = True
        except splunk.AuthorizationFailed:
            pass
        except Exception, e:
            logger.exception(e)
            template_args['controller_exception'] = e
    def show_summary(self, **unused):
        '''
        Renders the new license summary page
        '''

        #
        # retrieve data
        #

        # get local slave info; unauthorized access is simply
        # booted to manager TOC
        try:
            self_config = SelfConfig.get()
        except splunk.AuthorizationFailed:
            return self.redirect_to_url(['manager'])


        local_master_uri = None 
        if self_config.master_uri.lower() not in ['', 'self']:
            return self.show_slave_summary()

        # get all slaves, and find the local one in the mix
        slave_label_map = {}
        slaves = Slave.all(count_per_req=10000)
        local_slave = None
        for slave in slaves:
            slave_label_map[slave.name] = slave.label
            if slave.name == self_config.slave_name:
                local_slave = slave
        if not local_slave:
            raise Exception, 'Could not retrieve slave information for slave name: %s' % self_config.slave_name
        slave_count = len(slaves)
    
        # get active group
        active_group = Group.all().filter(is_active=True)
        if len(active_group) == 0:
            logger.warn('no active license groups found; redirecting user to "add license" page')
            self.redirect_to_url(['manager','system','licensing','licenses','new'], _qs={'return_to': cherrypy.request.relative_uri})

        active_group = active_group[0]

        # get associated stacks
        stack_query = Stack.all()
        stacks = []
        for stack in stack_query:
            if stack.name in active_group.stack_names:
                stacks.append(stack)

        # get associated pools
        pool_query = Pool.all()
        pools = []
        catchall_pool_names = []
        for pool in pool_query:
            if pool.stack_name in [s.name for s in stacks]:
                pools.append(pool)
                if pool.slaves == CATCHALL_SLAVE_LIST:
                    catchall_pool_names.append(pool.name)

        licenses = License.all()
        messages = Message.all()


        #
        # generate output info
        #

        stack_table = []
        for stack in stacks:
            #if not stack.quota_bytes:
            #    remaining_perc = None
            #else:
            #    remaining_perc = stack.remaining_bytes / stack.quota_bytes
            stack_table.append({
                'name': stack.name,
                'quota_bytes': stack.quota_bytes,
                'label': stack.label
                #'remaining_bytes': stack.remaining_bytes,
                #'remaining_perc': remaining_perc
            })

        # compile a summary list of messages by category
        hard_messages = {}
        soft_messages = {}
        for message in messages:
            if message.category == 'license_window':
                message_type = hard_messages
            else: 
                message_type = soft_messages   

            message_type.setdefault(message.category, {
                'severity': message.severity.lower(),
                'count': 0, 
                'latest_time': datetime.datetime.fromtimestamp(0, splunk.util.localTZ), 
                'slaves': set()}
            )
            message_type[message.category]['count'] += 1
            message_type[message.category]['latest_time'] = max(
                message.create_time,
                message_type[message.category]['latest_time']
            )
            message_type[message.category]['slaves'].add(slave_label_map.get(message.slave_name, message.slave_name))




        # loop over the per-slave data embedded in each pool descriptor
        pool_table = []
        slave_table = []
        local_used_bytes = 0.0
        for pool in pools:

            effective_global_quota = pool.quota_bytes['byte_value']
            if pool.quota_bytes['value_mode'] == 'MAX':
                for stack in stacks:
                    if pool.stack_name == stack.name:
                        effective_global_quota = stack.quota_bytes
                        break
                
            pool_table.append({
                'name': pool.name,
                'stack_name': pool.stack_name,
                'used_bytes': pool.used_bytes,
                'quota_bytes': effective_global_quota,
                'quota_mode': pool.quota_bytes['value_mode']
            })

            for slave in sorted(pool.slaves_usage_bytes):
                tmp_slave_bytes = float(pool.slaves_usage_bytes[slave])
                
                # accum the usage for the local slave
                if slave == self_config.slave_name:
                    local_used_bytes += tmp_slave_bytes
                
                if not effective_global_quota:
                    used_perc = None
                else:
                    used_perc = tmp_slave_bytes / effective_global_quota

                slave_table.append({
                    'pool_name': pool.name,
                    'name': slave_label_map.get(slave, slave),
                    'used_bytes': tmp_slave_bytes,
                    'used_perc': used_perc
                })

        license_table = []
        for license in licenses:
            license_table.append({
                'name': license.name,
                'label': license.label,
                'type': license.type,
                'stack_name': license.stack_name,
                'quota_bytes': license.quota_bytes,
                'expiration_time': license.expiration_time,
                'status': license.status.upper(),
                'can_remove': license.metadata.can_remove
            })
        license_table.sort(key=operator.itemgetter('expiration_time'))


        # the UI will only support managing pools within the enterprise stack
        if active_group.name in POOLABLE_GROUPS:
            can_edit_pools = True
        else:
            can_edit_pools = False
        

        # assemble into mako dict
        template_args = {
            'local_slave_name': local_slave.label,
            'local_used_bytes': local_used_bytes,
            'local_warning_count': local_slave.warning_count,
            'local_master_uri': local_master_uri,
            'active_group_name': active_group.name,
            'default_stack_name': DEFAULT_STACK_NAME,
            'slave_count': slave_count,
            'pool_table': pool_table,
            'stack_table': stack_table,
            'slave_table': slave_table,
            'license_table': license_table,
            'hard_messages': hard_messages,
            'soft_messages': soft_messages,
            'can_edit_pools': can_edit_pools,
            'catchall_pool_names': catchall_pool_names,
            'can_be_remote_master': self_config.features.get('CanBeRemoteMaster') == 'ENABLED',
            'showLicenseUsage': (cherrypy.config['product_type'] != 'hunk')
        }

        return self.render_template('/licensing/overview.html', template_args)
        try:
            licenses = License.all()
            for license in licenses:
                license_table.append({
                    'type': license.type,
                    'label': license.label
                })
        except Exception, e:
            logger.exception(e)
            template_args['controller_exception'] = e

        template_args['license_table'] = license_table

        # get current active group
        group = Group.all().filter(is_active=True)
        if group:
            template_args['current_group'] = group[0].name

        # handle uploads via cherrypy's built in file handling facilities
        if cherrypy.request.method == 'POST':
        
            license_object = None

            # process uploaded file first; if not there, then check for inline
            # XML being pasted in
            if isinstance(licenseFile, cgi.FieldStorage) and licenseFile.filename:

                logger.info('processing incoming license to add: %s' % licenseFile.filename)

                # pull license into stringbuffer
Exemple #7
0
class LicensingController(BaseController):
    """
    Handle licensing messaging and modifications
    """

    #
    # attach common template args
    #

    def render_template(self, template_path, template_args={}):
        template_args['appList'] = self.get_app_manifest()
        return super(LicensingController,
                     self).render_template(template_path, template_args)

    def get_app_manifest(self):
        '''
        Returns a dict of all available apps to current user
        '''

        output = cached.getEntities('apps/local',
                                    search=['disabled=false', 'visible=true'],
                                    count=-1)

        return output

    #
    # trial -> free switching
    #

    @expose_page(methods=['GET', 'POST'])
    def expired(self, formset_mode=None, return_to=None, **unused):

        template_args = {
            'can_change_license':
            False,
            'return_to':
            util.make_url_internal(return_to)
            or self.make_url(['manager', 'system', 'licensing'])
        }

        free_group = None
        try:
            free_group = Group.get(
                Group.build_id('Free', namespace=None, owner=None))
            template_args['can_change_license'] = True
        except splunk.AuthorizationFailed:
            pass
        except Exception, e:
            logger.exception(e)
            template_args['controller_exception'] = e

        if cherrypy.request.method == 'POST' and free_group:

            if formset_mode == 'free':
                try:
                    free_group = Group.get(
                        Group.build_id('Free', namespace=None, owner=None))
                    free_group.is_active = True
                    free_group.save()

                    template_args['is_success'] = True

                except Exception, e:
                    logger.exception(e)
                    template_args['controller_exception'] = e

            elif formset_mode == 'add_license':

                return self.redirect_to_url(
                    ['manager', 'system', 'licensing', 'licenses', 'new'],
                    _qs={
                        'return_to':
                        self.make_url(['manager', 'system', 'licensing'])
                    })
Exemple #8
0
    def show_summary(self, **unused):
        '''
        Renders the new license summary page
        '''

        #
        # retrieve data
        #

        # get local slave info; unauthorized access is simply
        # booted to manager TOC
        try:
            self_config = SelfConfig.get()
        except splunk.AuthorizationFailed:
            return self.redirect_to_url(['manager'])

        local_master_uri = None
        if self_config.master_uri.lower() not in ['', 'self']:
            return self.show_slave_summary()

        # get all slaves, and find the local one in the mix
        slave_label_map = {}
        slaves = Slave.all()
        local_slave = None
        for slave in slaves:
            slave_label_map[slave.name] = slave.label
            if slave.name == self_config.slave_name:
                local_slave = slave
        if not local_slave:
            raise Exception, 'Could not retrieve slave information for slave name: %s' % self_config.slave_name
        slave_count = len(slaves)

        # get active group
        active_group = Group.all().filter(is_active=True)
        if len(active_group) == 0:
            logger.warn(
                'no active license groups found; redirecting user to "add license" page'
            )
            self.redirect_to_url(
                ['manager', 'system', 'licensing', 'licenses', 'new'],
                _qs={'return_to': cherrypy.request.relative_uri})

        active_group = active_group[0]

        # get associated stacks
        stack_query = Stack.all()
        stacks = []
        for stack in stack_query:
            if stack.name in active_group.stack_names:
                stacks.append(stack)

        # get associated pools
        pool_query = Pool.all()
        pools = []
        catchall_pool_names = []
        for pool in pool_query:
            if pool.stack_name in [s.name for s in stacks]:
                pools.append(pool)
                if pool.slaves == CATCHALL_SLAVE_LIST:
                    catchall_pool_names.append(pool.name)

        licenses = License.all()
        messages = Message.all()

        #
        # generate output info
        #

        stack_table = []
        for stack in stacks:
            #if not stack.quota_bytes:
            #    remaining_perc = None
            #else:
            #    remaining_perc = stack.remaining_bytes / stack.quota_bytes
            stack_table.append({
                'name': stack.name,
                'quota_bytes': stack.quota_bytes,
                'label': stack.label
                #'remaining_bytes': stack.remaining_bytes,
                #'remaining_perc': remaining_perc
            })

        # compile a summary list of messages by category
        hard_messages = {}
        soft_messages = {}
        for message in messages:
            if message.category == 'license_window':
                message_type = hard_messages
            else:
                message_type = soft_messages

            message_type.setdefault(
                message.category, {
                    'severity':
                    message.severity.lower(),
                    'count':
                    0,
                    'latest_time':
                    datetime.datetime.fromtimestamp(0, splunk.util.localTZ),
                    'slaves':
                    set()
                })
            message_type[message.category]['count'] += 1
            message_type[message.category]['latest_time'] = max(
                message.create_time,
                message_type[message.category]['latest_time'])
            message_type[message.category]['slaves'].add(
                slave_label_map.get(message.slave_name, message.slave_name))

        # loop over the per-slave data embedded in each pool descriptor
        pool_table = []
        slave_table = []
        local_used_bytes = 0.0
        for pool in pools:

            effective_global_quota = pool.quota_bytes['byte_value']
            if pool.quota_bytes['value_mode'] == 'MAX':
                for stack in stacks:
                    if pool.stack_name == stack.name:
                        effective_global_quota = stack.quota_bytes
                        break

            pool_table.append({
                'name': pool.name,
                'stack_name': pool.stack_name,
                'used_bytes': pool.used_bytes,
                'quota_bytes': effective_global_quota,
                'quota_mode': pool.quota_bytes['value_mode']
            })

            for slave in sorted(pool.slaves_usage_bytes):
                tmp_slave_bytes = float(pool.slaves_usage_bytes[slave])

                # accum the usage for the local slave
                if slave == self_config.slave_name:
                    local_used_bytes += tmp_slave_bytes

                if not effective_global_quota:
                    used_perc = None
                else:
                    used_perc = tmp_slave_bytes / effective_global_quota

                slave_table.append({
                    'pool_name': pool.name,
                    'name': slave_label_map.get(slave, slave),
                    'used_bytes': tmp_slave_bytes,
                    'used_perc': used_perc
                })

        license_table = []
        for license in licenses:
            license_table.append({
                'name': license.name,
                'label': license.label,
                'type': license.type,
                'stack_name': license.stack_name,
                'quota_bytes': license.quota_bytes,
                'expiration_time': license.expiration_time,
                'status': license.status.upper(),
                'can_remove': license.metadata.can_remove
            })
        license_table.sort(key=operator.itemgetter('expiration_time'))

        # the UI will only support managing pools within the enterprise stack
        if active_group.name in POOLABLE_GROUPS:
            can_edit_pools = True
        else:
            can_edit_pools = False

        # assemble into mako dict
        template_args = {
            'local_slave_name':
            local_slave.label,
            'local_used_bytes':
            local_used_bytes,
            'local_warning_count':
            local_slave.warning_count,
            'local_master_uri':
            local_master_uri,
            'active_group_name':
            active_group.name,
            'default_stack_name':
            DEFAULT_STACK_NAME,
            'slave_count':
            slave_count,
            'pool_table':
            pool_table,
            'stack_table':
            stack_table,
            'slave_table':
            slave_table,
            'license_table':
            license_table,
            'hard_messages':
            hard_messages,
            'soft_messages':
            soft_messages,
            'can_edit_pools':
            can_edit_pools,
            'catchall_pool_names':
            catchall_pool_names,
            'can_be_remote_master':
            self_config.features.get('CanBeRemoteMaster') == 'ENABLED'
        }

        return self.render_template('/licensing/overview.html', template_args)
Exemple #9
0
        try:
            licenses = License.all()
            for license in licenses:
                license_table.append({
                    'type': license.type,
                    'label': license.label
                })
        except Exception, e:
            logger.exception(e)
            template_args['controller_exception'] = e

        template_args['license_table'] = license_table

        # get current active group
        group = Group.all().filter(is_active=True)
        if group:
            template_args['current_group'] = group[0].name

        # handle uploads via cherrypy's built in file handling facilities
        if cherrypy.request.method == 'POST':

            license_object = None

            # process uploaded file first; if not there, then check for inline
            # XML being pasted in
            if isinstance(licenseFile,
                          cgi.FieldStorage) and licenseFile.filename:

                logger.info('processing incoming license to add: %s' %
                            licenseFile.filename)