コード例 #1
0
ファイル: licensing.py プロジェクト: linearregression/splunk
    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
コード例 #2
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
コード例 #3
0
    def delete_license(self, license_id, return_to=None, **kwargs):
        '''
        Deletes a specific license
        '''

        template_args = {
            'return_to': util.make_url_internal(return_to),
            'was_deleted': False
        }

        try:
            # first check that the license is valid
            marked_license = License.get(License.build_id(
                license_id,
                namespace=None,
                owner=None
            ))
            template_args['license'] = marked_license

            # handle delete
            if cherrypy.request.method == 'POST':
                marked_license.delete()
                template_args['was_deleted'] = True
            
        except Exception, e:
            template_args['controller_exception'] = e
コード例 #4
0
    def add_license(self, licenseFile=None, formset_pasted_license=None, return_to=None, prompt_restart=False, **kw):
        '''
        Handles the license add/edit page
        '''

        template_args = {
            'return_to': util.make_url_internal(return_to),
            'prompt_restart': splunk.util.normalizeBoolean(prompt_restart),
            'is_success': False,
            'pasted_license': formset_pasted_license or '',
            'current_group': None,
            'new_group': None
        }

        license_table = []

        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
コード例 #5
0
    def delete_pool(self, pool_name, return_to=None, **unused):

        template_args = {
            'return_to': util.make_url_internal(return_to),
            'was_deleted': False,
            'pool_name': pool_name,
            'slave_table': []
        }

        # check that desired stack exists
        try:
            pool_id = Pool.build_id(pool_name, namespace=None, owner=None)
            pool = Pool.get(pool_id)
            template_args['pool'] = pool

            # get server labels from GUID
            slave_table = []
            slaves = Slave.all(count_per_req=10000)
            for slave in pool.slaves_usage_bytes:
                for so in slaves:
                    if so.name == slave:
                        slave_table.append(so.label)
                        break

            template_args['slave_table'] = slave_table

            # handle save action
            if cherrypy.request.method == 'POST':
                
                pool.delete()
                template_args['was_deleted'] = True

        except Exception, e:
            logger.exception(e)
            template_args['controller_exception'] = e    
コード例 #6
0
ファイル: licensing.py プロジェクト: linearregression/splunk
    def add_license(self,
                    licenseFile=None,
                    formset_pasted_license=None,
                    return_to=None,
                    prompt_restart=False,
                    **kw):
        '''
        Handles the license add/edit page
        '''

        template_args = {
            'return_to': util.make_url_internal(return_to),
            'prompt_restart': splunk.util.normalizeBoolean(prompt_restart),
            'is_success': False,
            'pasted_license': formset_pasted_license or '',
            'current_group': None,
            'new_group': None
        }

        license_table = []

        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
コード例 #7
0
ファイル: licensing.py プロジェクト: linearregression/splunk
    def delete_pool(self, pool_name, return_to=None, **unused):

        template_args = {
            'return_to': util.make_url_internal(return_to),
            'was_deleted': False,
            'pool_name': pool_name,
            'slave_table': []
        }

        # check that desired stack exists
        try:
            pool_id = Pool.build_id(pool_name, namespace=None, owner=None)
            pool = Pool.get(pool_id)
            template_args['pool'] = pool

            # get server labels from GUID
            slave_table = []
            slaves = Slave.all()
            for slave in pool.slaves_usage_bytes:
                for so in slaves:
                    if so.name == slave:
                        slave_table.append(so.label)
                        break

            template_args['slave_table'] = slave_table

            # handle save action
            if cherrypy.request.method == 'POST':

                pool.delete()
                template_args['was_deleted'] = True

        except Exception, e:
            logger.exception(e)
            template_args['controller_exception'] = e
コード例 #8
0
    def list_messages(self, category=None, return_to=None, **kw):
        '''
        Handles the message listing page
        '''

        messages = Message.all()
        try:
            self_config = SelfConfig.get()
        except splunk.AuthorizationFailed:
            return self.redirect_to_url(['manager'])

        if category:
            messages = messages.filter(category=category)

        # get list of available indexers that could be assigned
        slaves = Slave.all(count_per_req=10000)
        slave_label_map = {}
        for slave in slaves:
            slave_label_map[slave.name] = slave.label

        soft_messages = []
        hard_messages = []
        all_messages = []
        for message in messages:
                       
            newMessage = {
                'text': message.description,
                'create_time': message.create_time,
                'severity': message.severity.lower(),
                'pool_name': message.pool_name,
                'slave_name': slave_label_map.get(message.slave_name, message.slave_name),
                'stack_name': message.stack_name,
                'category': message.category
            }

            all_messages.append(newMessage)

            if message.category == 'license_window':
                hard_messages.append(newMessage)
            else: 
                soft_messages.append(newMessage)

        soft_messages.sort(key=operator.itemgetter('create_time'), reverse=True)
        hard_messages.sort(key=operator.itemgetter('create_time'), reverse=True)
        all_messages.sort(key=operator.itemgetter('create_time'), reverse=True)

        template_args = {
            'category': category,
            'soft_messages': soft_messages,
            'hard_messages': hard_messages,
            'all_messages': all_messages,
            'return_to': util.make_url_internal(return_to) or self.make_url(['manager','system','licensing']),
            'server_name': self_config.slave_label
        }
        return self.render_template('/licensing/messages/list.html', template_args)
コード例 #9
0
    def list_indexers(self, return_to=None, **kw):
        '''
        Handles the indexer listing page
        '''

        slaves = Slave.all(count_per_req=10000)
        try:
            self_config = SelfConfig.get()
        except splunk.AuthorizationFailed:
            return self.redirect_to_url(['manager'])

        template_args = {
            'slaves': slaves or [],
            'return_to': util.make_url_internal(return_to) or self.make_url(['manager','system','licensing']),
            'server_name': self_config.slave_label
        }
        return self.render_template('/licensing/slaves/list.html', template_args)
コード例 #10
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
コード例 #11
0
ファイル: licensing.py プロジェクト: linearregression/splunk
    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
コード例 #12
0
ファイル: licensing.py プロジェクト: linearregression/splunk
    def list_indexers(self, return_to=None, **kw):
        '''
        Handles the indexer listing page
        '''

        slaves = Slave.all()
        try:
            self_config = SelfConfig.get()
        except splunk.AuthorizationFailed:
            return self.redirect_to_url(['manager'])

        template_args = {
            'slaves':
            slaves or [],
            'return_to':
            util.make_url_internal(return_to)
            or self.make_url(['manager', 'system', 'licensing']),
            'server_name':
            self_config.slave_label
        }
        return self.render_template('/licensing/slaves/list.html',
                                    template_args)
コード例 #13
0
ファイル: licensing.py プロジェクト: linearregression/splunk
    def delete_license(self, license_id, return_to=None, **kwargs):
        '''
        Deletes a specific license
        '''

        template_args = {
            'return_to': util.make_url_internal(return_to),
            'was_deleted': False
        }

        try:
            # first check that the license is valid
            marked_license = License.get(
                License.build_id(license_id, namespace=None, owner=None))
            template_args['license'] = marked_license

            # handle delete
            if cherrypy.request.method == 'POST':
                marked_license.delete()
                template_args['was_deleted'] = True

        except Exception, e:
            template_args['controller_exception'] = e
コード例 #14
0
ファイル: licensing.py プロジェクト: linearregression/splunk
    def edit_pool(self,
                  action,
                  stack_name=DEFAULT_STACK_NAME,
                  pool_name=None,
                  return_to=None,
                  formset_name=None,
                  formset_quota_mode=None,
                  formset_quota_value=None,
                  formset_quota_units=None,
                  formset_description=None,
                  formset_slaves=None,
                  formset_slave_mode=None,
                  **unused):
        '''
        Handles adding a new pool or editing an existing pool
        '''

        # setup mako args
        template_args = {
            'action': action,
            'return_to': util.make_url_internal(return_to),
            'stack_name': stack_name,
            'is_success': False
        }

        # check that desired stack exists
        try:
            stack_id = Stack.build_id(stack_name, namespace=None, owner=None)
            stack = Stack.get(stack_id)
            stack_label = stack.label

        except splunk.ResourceNotFound, e:
            logger.exception(e)
            raise cherrypy.HTTPError(
                400,
                'The "%s" stack was not found.  This interface only supports managing pools within that stack.'
                % DEFAULT_STACK_NAME)
コード例 #15
0
    def edit_pool(self, 
        action,
        stack_name=DEFAULT_STACK_NAME, 
        pool_name=None, 
        return_to=None,
        formset_name=None,
        formset_quota_mode=None,
        formset_quota_value=None,
        formset_quota_units=None,
        formset_description=None,
        formset_slaves=None,
        formset_slave_mode=None,
        **unused
    ):
        '''
        Handles adding a new pool or editing an existing pool
        '''

        
        # setup mako args
        template_args = {
            'action': action,
            'return_to': util.make_url_internal(return_to),
            'stack_name': stack_name,
            'is_success': False
        }

        # check that desired stack exists
        try:
            stack_id = Stack.build_id(stack_name, namespace=None, owner=None)
            stack = Stack.get(stack_id)
            stack_label = stack.label

        except splunk.ResourceNotFound, e:
            logger.exception(e)
            raise cherrypy.HTTPError(400, 'The "%s" stack was not found.  This interface only supports managing pools within that stack.' % DEFAULT_STACK_NAME)
コード例 #16
0
ファイル: licensing.py プロジェクト: linearregression/splunk
    def list_messages(self, category=None, return_to=None, **kw):
        '''
        Handles the message listing page
        '''

        messages = Message.all()
        try:
            self_config = SelfConfig.get()
        except splunk.AuthorizationFailed:
            return self.redirect_to_url(['manager'])

        if category:
            messages = messages.filter(category=category)

        # get list of available indexers that could be assigned
        slaves = Slave.all()
        slave_label_map = {}
        for slave in slaves:
            slave_label_map[slave.name] = slave.label

        soft_messages = []
        hard_messages = []
        all_messages = []
        for message in messages:

            newMessage = {
                'text':
                message.description,
                'create_time':
                message.create_time,
                'severity':
                message.severity.lower(),
                'pool_name':
                message.pool_name,
                'slave_name':
                slave_label_map.get(message.slave_name, message.slave_name),
                'stack_name':
                message.stack_name,
                'category':
                message.category
            }

            all_messages.append(newMessage)

            if message.category == 'license_window':
                hard_messages.append(newMessage)
            else:
                soft_messages.append(newMessage)

        soft_messages.sort(key=operator.itemgetter('create_time'),
                           reverse=True)
        hard_messages.sort(key=operator.itemgetter('create_time'),
                           reverse=True)
        all_messages.sort(key=operator.itemgetter('create_time'), reverse=True)

        template_args = {
            'category':
            category,
            'soft_messages':
            soft_messages,
            'hard_messages':
            hard_messages,
            'all_messages':
            all_messages,
            'return_to':
            util.make_url_internal(return_to)
            or self.make_url(['manager', 'system', 'licensing']),
            'server_name':
            self_config.slave_label
        }
        return self.render_template('/licensing/messages/list.html',
                                    template_args)
コード例 #17
0
                self_config.master_uri = OWN_MASTER_URI
            else:
                self_config.master_uri = formset_master_server_uri

            try:
                self_config.save()
                is_success = True
            except Exception, e:
                logger.exception(e)
                controller_exception = e


        # generate template args; be sure to preserve form state
        template_args = {
            'is_success' : is_success,
            'return_to': util.make_url_internal(return_to),
            'controller_exception': controller_exception,
            'local_slave_name': self_config.slave_label,
            'master_server_uri': formset_master_server_uri or master_server_uri,
            'master_server_mode': formset_master_server_mode or master_server_mode,
            'is_own_master': is_own_master,
            'requires_restart': util.check_restart_required()
        }

        return self.render_template('/licensing/self.html', template_args)





    @expose_page(methods=['GET','POST'])
コード例 #18
0
ファイル: licensing.py プロジェクト: linearregression/splunk
            if formset_master_server_mode == 'this_server' or not formset_master_server_uri:
                self_config.master_uri = OWN_MASTER_URI
            else:
                self_config.master_uri = formset_master_server_uri

            try:
                self_config.save()
                is_success = True
            except Exception, e:
                logger.exception(e)
                controller_exception = e

        # generate template args; be sure to preserve form state
        template_args = {
            'is_success': is_success,
            'return_to': util.make_url_internal(return_to),
            'controller_exception': controller_exception,
            'local_slave_name': self_config.slave_label,
            'master_server_uri': formset_master_server_uri
            or master_server_uri,
            'master_server_mode': formset_master_server_mode
            or master_server_mode,
            'is_own_master': is_own_master,
            'requires_restart': util.check_restart_required()
        }

        return self.render_template('/licensing/self.html', template_args)

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