nova-compute启动分析之一

  1. python启动脚本 bin/nova-compute
python启动脚本 bin/nova-compute

 

[html] view plaincopyprint?
  1. utils.default_flagfile()  #设置flag文件路径. 
  2. flags.FLAGS(sys.argv)   #把flag文件中的参数放到args中。 
  3. logging.setup()           #设置日志 
  4. utils.monkey_patch() 
  5. server = service.Service.create(binary='nova-compute') #创建服务 
  6. service.serve(server)  #启动服务 
  7. service.wait()             #等待请求 
    utils.default_flagfile()  #设置flag文件路径.
    flags.FLAGS(sys.argv)   #把flag文件中的参数放到args中。
    logging.setup()           #设置日志
    utils.monkey_patch()
    server = service.Service.create(binary='nova-compute') #创建服务
    service.serve(server)  #启动服务
    service.wait()             #等待请求

 

 

 

下面我讲按6大步进行讲述:

第一步:utils.default_flagfile()

[html] view plaincopyprint?
  1. if args is None: 
  2.      args = sys.argv 
  3. for arg in args: 
  4.      if arg.find('flagfile') != -1: 
  5.          break 
  6. else: 
  7.      if not os.path.isabs(filename): 
  8.          # turn relative filename into an absolute path 
  9.          script_dir = os.path.dirname(inspect.stack()[-1][1]) 
  10.          filename = os.path.abspath(os.path.join(script_dir, filename)) 
  11.      if not os.path.exists(filename): 
  12.          filename = "./nova.conf" 
  13.          if not os.path.exists(filename): 
  14.              filename = '/etc/nova/nova.conf' 
  15.      flagfile = '--flagfile=%s' % filename 
  16.      args.insert(1, flagfile) 
  17.   其实所完成的功能也就是把--flagfile=/etc/nova/nova.conf加到入参数列表中。 
   if args is None:
        args = sys.argv
    for arg in args:
        if arg.find('flagfile') != -1:
            break
    else:
        if not os.path.isabs(filename):
            # turn relative filename into an absolute path
            script_dir = os.path.dirname(inspect.stack()[-1][1])
            filename = os.path.abspath(os.path.join(script_dir, filename))
        if not os.path.exists(filename):
            filename = "./nova.conf"
            if not os.path.exists(filename):
                filename = '/etc/nova/nova.conf'
        flagfile = '--flagfile=%s' % filename
        args.insert(1, flagfile)
     其实所完成的功能也就是把--flagfile=/etc/nova/nova.conf加到入参数列表中。



第二步:flags.FLAGS(sys.argv)

  flags.py中有一句
  FLAGS = FlagValues(),那么直接查看FlagValues()这个类,这个类是继承于gflags.FlagValues.



第三步:logging.setup()

这个是对这个服务开启日志功能。




第四步:server = service.Service.create(binary='nova-compute')

这个函数位于/nova/service.py: 类Service中

[html] view plaincopyprint?
  1. class Service(object): 
  2.     """Service object for binaries running on hosts. 
  3.     A service takes a manager and enables rpc by listening to queues based 
  4.     on topic. It also periodically runs tasks on the manager and reports 
  5.     it state to the database services table.""" 
  6. 函数定义如下: 
  7.    @classmethod  
  8.     def create(cls, host=None,binary=None,topic=None,manager=None
  9.                report_interval=None,periodic_interval=None): 
  10.         """Instantiates class and passes back application object. 
  11.  
  12.         :param host: defaults to FLAGS.host 
  13.         :param binary: defaults to basename of executable 
  14.         :param topic: defaults to bin_name - 'nova-' part 
  15.         :param manager: defaults to FLAGS.<topic>_manager 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值