当前位置: 首页>>代码示例>>Python>>正文


Python NginxConfig.collect_structure方法代码示例

本文整理汇总了Python中amplify.agent.objects.nginx.config.config.NginxConfig.collect_structure方法的典型用法代码示例。如果您正苦于以下问题:Python NginxConfig.collect_structure方法的具体用法?Python NginxConfig.collect_structure怎么用?Python NginxConfig.collect_structure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在amplify.agent.objects.nginx.config.config.NginxConfig的用法示例。


在下文中一共展示了NginxConfig.collect_structure方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: print

# 需要导入模块: from amplify.agent.objects.nginx.config.config import NginxConfig [as 别名]
# 或者: from amplify.agent.objects.nginx.config.config.NginxConfig import collect_structure [as 别名]
        print('\n\033[32mConfig index for %s\033[0m' % filename)
        print(json.dumps(cfg.index, **print_args))

        print('\n\033[32mConfig files for %s\033[0m' % filename)
        print(json.dumps(cfg.files, **print_args))

        print('\n\033[32mStub/plus status %s\033[0m' % filename)
        print(json.dumps(cfg.stub_status_urls, **print_args))
        print(json.dumps(cfg.plus_status_external_urls, **print_args))
        print(json.dumps(cfg.plus_status_internal_urls, **print_args))

        print('\n\033[32mAccess logs %s\033[0m' % filename)
        print(json.dumps(cfg.access_logs, **print_args))

        print('\n\033[32mError logs %s\033[0m' % filename)
        print(json.dumps(cfg.error_logs, **print_args))

        print('\n\033[32mLog formats %s\033[0m' % filename)
        print(json.dumps(cfg.log_formats, **print_args))

        print('\n\033[32mConfig errors for %s\033[0m' % filename)
        print(json.dumps(cfg.parser_errors, **print_args))

    else:
        print('\n\033[32mLight parse results for %s\033[0m' % filename)
        print(json.dumps(cfg.collect_structure(), **print_args))

    end_time = time.time()

    print('\n\033[32mParsed in %s seconds\033[0m' % (end_time-start_time))
开发者ID:MSmmer,项目名称:nginx-amplify-agent,代码行数:32,代码来源:cfgparser.py

示例2: collect

# 需要导入模块: from amplify.agent.objects.nginx.config.config import NginxConfig [as 别名]
# 或者: from amplify.agent.objects.nginx.config.config.NginxConfig import collect_structure [as 别名]
    def collect(self):
        try:
            config = NginxConfig(
                self.object.conf_path,
                binary=self.object.bin_path,
                prefix=self.object.prefix
            )

            # check if config is changed (changes are: new files/certs, new mtimes)
            config_files, config_dirs = config.collect_structure(include_ssl_certs=self.object.upload_ssl)
            if config_files == self.previous_files and config_dirs == self.previous_directories:
                return

            # parse config tree
            config.full_parse()

            # Send event for parsing nginx config.
            # Use config.parser.filename to account for default value defined in NginxConfigParser.
            self.object.eventd.event(
                level=INFO,
                message='nginx config parsed, read from %s' % config.filename,
            )
            for error in config.parser_errors:
                self.object.eventd.event(level=WARNING, message=error)

            # run ssl checks
            if self.object.upload_ssl:
                config.run_ssl_analysis()
            else:
                context.log.info('ssl analysis skipped due to users settings')

            # run upload
            checksum = config.checksum()
            if self.object.upload_config:
                self.upload(config, checksum)

            if self.previous_checksum:
                # config changed, so we need to restart the object
                self.object.need_restart = True
            else:
                # otherwise run test
                if self.object.run_config_test and config.total_size() < 20*1024*1024:  # 20 MB
                    run_time = config.run_test()

                    # send event for testing nginx config
                    if config.test_errors:
                        self.object.eventd.event(level=WARNING, message='nginx config test failed')
                    else:
                        self.object.eventd.event(level=INFO, message='nginx config tested ok')

                    for error in config.test_errors:
                        self.object.eventd.event(level=CRITICAL, message=error)

                    # stop -t if it took too long
                    if run_time > context.app_config['containers']['nginx']['max_test_duration']:
                        context.app_config['containers']['nginx']['run_test'] = False
                        context.app_config.mark_unchangeable('run_test')
                        self.object.eventd.event(
                            level=WARNING,
                            message='%s -t -c %s took %s seconds, disabled until agent restart' % (
                                config.binary, config.filename, run_time
                            )
                        )
                        self.object.run_config_test = False

            self.previous_checksum = checksum
            self.previous_files = copy.copy(config_files)
            self.previous_directories = copy.copy(config_dirs)
        except Exception as e:
            exception_name = e.__class__.__name__
            context.log.error('failed to collect due to %s' % exception_name)
            context.log.debug('additional info:', exc_info=True)

            self.object.eventd.event(
                level=INFO,
                message='nginx config parser failed, path %s' % self.object.conf_path,
                onetime=True
            )
开发者ID:Ferrisbane,项目名称:nginx-amplify-agent,代码行数:80,代码来源:config.py


注:本文中的amplify.agent.objects.nginx.config.config.NginxConfig.collect_structure方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。