cpi.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:bosh-ironic-cpi-release 作者: jriguera 项目源码 文件源码
def parse_config(self, arguments=None):
        finalconfig = {}
        args = self.parser.parse_args(arguments)
        config = configparser.SafeConfigParser()
        try:
            with open(args.config) as fdconfig:
                config.readfp(fdconfig) 
        except Exception as e:
            msg = "Ignoring configuration file '%s'"
            self.logger.warn(msg % (args.config))
            for section in self.PARAMETERS.keys():
                config.add_section(section)
        else:
            self.logger.info("Read configuration file '%s'" % args.config)
        for section in self.PARAMETERS.keys():
            cfgsection = dict(config.items(section))
            for var, required in self.PARAMETERS[section].iteritems():
                try:
                    # build env variables like IRONIC_URL
                    envparameter = section.upper() + '_' + var.upper()
                    cfgsection[var] = os.environ[envparameter]
                    msg = "Reading env variable '%s'" % envparameter
                    self.logger.debug(msg)
                except:
                    pass
                if required and not var in cfgsection:
                    msg = "Variable '%s.%s' not defined and it is required!" 
                    msg = msg % (section, var)
                    self.logger.error(msg)
                    raise ValueError(msg)
            finalconfig[section] = cfgsection
        self.args = args
        return finalconfig
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号