Beispiel #1
0
def start():
    """
    Use the run_server.py script in ./src
    """
    try:
        parser = argparse.ArgumentParser('Ludit client')
        parser.add_argument('--newcfg',
                            action='store_true',
                            dest='newcfg',
                            help='dump template configuration file to stdout')
        parser.add_argument('--cfg',
                            dest='cfg',
                            help='configuration file to use')
        parser.add_argument('--verbose',
                            action='store_true',
                            help='enable more logging')

        args = parser.parse_args()

        util.get_pid_lock('ludit_server')

        if args.verbose:
            log.setLevel(logging.DEBUG)

        if args.newcfg:
            config = json.dumps(generate_config(), indent=4, sort_keys=True)
            print(config)
            exit(0)

        def ctrl_c_handler(_, __):
            try:
                print(' ctrl-c handler')
                if _server:
                    log.info('terminating by user')
                    _server.terminate()
                    log.debug('terminate done, waiting..')
                    _server.join()
                sys.exit(1)
            except Exception as e:
                log.critical('ctrl-c handler got ' + str(e))

        def ignore(_, __):
            pass

        signal.signal(signal.SIGINT, ctrl_c_handler)
        signal.signal(signal.SIGPIPE, ignore)

        _server = None
        _server = Server(args.cfg)
        _server.join()
        log.info('server exiting')

    except Exception as e:
        if args.verbose:
            print(traceback.format_exc())
        util.die('server exception: %s' % str(e))
Beispiel #2
0
See the License for the specific language governing permissions and limitations under the License.
"""

from common.mymako import render_mako_context, render_json
from blueking.component.shortcuts import get_client_by_request
from conf.default import APP_ID, APP_TOKEN
from common.log import logger
import logging
import sys

formatter = logging.Formatter(
    '%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s')
console_handler = logging.StreamHandler(sys.stdout)
console_handler.formatter = formatter
logger.addHandler(console_handler)
logger.setLevel(logging.DEBUG)


def home(request):
    """
    首页
    """
    client = get_client_by_request(request)
    inner_host_info = get_inner_host_info(request)
    new_host_list = []
    exist_host_list = []
    update_host_list = []
    for host in inner_host_info:
        ip = host['ip']
        os_type = host['os_type']
        hostname = host['hostname']
Beispiel #3
0
def start():
    """
    Use the run_client.py script in ./src
    """
    try:
        parser = argparse.ArgumentParser('Ludit client')
        parser.add_argument(
            '--id',
            action='store',
            dest='id',
            help='required identifier in the form groupname:devicename')
        parser.add_argument('--newcfg',
                            action='store_true',
                            dest='newcfg',
                            help='dump template configuration file to stdout')
        parser.add_argument(
            '--cfg',
            dest='cfg',
            help='configuration file to use (only required for stereo clients)'
        )
        parser.add_argument('--verbose',
                            action='store_true',
                            help='enable more logging')
        parser.add_argument('--nocheck',
                            action='store_true',
                            help='don\'t check for multiple client instances')

        results = parser.parse_args()

        if results.newcfg:
            configuration = generate_config(template=True)
            config = json.dumps(configuration, indent=4, sort_keys=True)
            print(config)
            exit(0)

        if not results.nocheck:
            util.get_pid_lock('ludit_client')

        if results.verbose:
            log.setLevel(logging.DEBUG)

        try:
            configuration = load_configuration(results.cfg)
        except:
            configuration = generate_config(template=False)

        try:
            groupname, devicename = results.id.split(':')
            configuration['group'] = groupname
            configuration['device'] = devicename
        except:
            if not configuration.get('group'):
                raise Exception(
                    'need a group:device name from --id argument or configuration file'
                )

        def ctrl_c_handler(_, __):
            try:
                print(' ctrl-c handler')
                if _client:
                    log.info('terminating by user')
                    _client.terminate()
                    _client.join()
                sys.exit(1)
            except Exception as e:
                log.critical('ctrl-c handler got ' + str(e))

        signal.signal(signal.SIGINT, ctrl_c_handler)

        _client = None
        _client = Client(configuration)
        _client.join()

        log.info('client exiting')

    except Exception as e:
        log.critical('client exception: %s' % str(e))
Beispiel #4
0
 def on_finish(self):
     if self.Genernal.debug:
         logger.setLevel(logger.DEBUG)