2021SC@SDUSC
nova/cmd/compute.py/main
Abstract
This function serves as the entry of the whole nova service. The main purpose of the function is to analyse arguements from command line and complete some routine works for the application, such as setting logger, ensure root privilege, etc. This function also does pre-work for the application. For example, it helps to init objects, load plugins, set up the Guru Meditation Report, guard db access, ensure rcp features, manage versions and launch services.
# ----------------------------------header(routine for all applications)------------------------------------------
config.parse_args(sys.argv)
# 解析命令行参数(sys.argv -- command line arguments)
logging.setup(CONF, 'nova')
# 为本应用设置日志
priv_context.init(root_helper=shlex.split(utils.get_root_helper()))
# 确认命令执行具有root权限(通过root_helper对sudo的检验)
# -------------------------------header end------------------------------------------
objects.register_all()
# 注册对象:When objects are registered, an attribute is set
# on this module automatically, pointing to the newest/latest version of
# the object.
gmr_opts.set_defaults(CONF)
# overwrite default options using attributes in CONF
os_vif.initialize()
# Ensure os-vif objects are registered and plugins loaded
# Loads all os_vif plugins and initializes them with a dictionary of configuration options.
# These configuration options are passed as-is to the individual VIF plugins that are loaded via stevedore.
gmr.TextGuruMeditation.setup_autorun(version, conf=CONF)
# This method sets up the Guru Meditation Report to automatically get dumped to stderr or a file in a given dir
# when the given signal is received. It can also use file modification events instead of signals
cmd_common.block_db_access('nova-compute')
# 不允许进入db??为什么拦着一道?
objects_base.NovaObject.indirection_api = conductor_rpcapi.ConductorAPI()
# seems like object management?
objects.Service.enable_min_version_cache() # 清理版本缓存
server = service.Service.create(binary='nova-compute',
topic=compute_rpcapi.RPC_TOPIC) # Instantiates class and passes back application object.
# A service takes a manager and enables rpc by listening to queues based on topic.
# It also periodically runs tasks on the manager and reports its state to the database services table.
service.serve(server) # launch a service
service.wait() # sorry, I cannot navigate to the original function…………the function seems to be substituded.
What’s interesting is that nearly all the functions used here can be navigated to …\Python\Python38\Lib\site-packages\oslo_xxxxxx, indicading a starkle significance of this module and also highlighting the special relationship between OpenStack components’ behaviors and oslo_xxxxxx. Thus, it may be a good idea to have a closer look at oslo, which may help to gain a more profound understanding on OpenStack system.
However, after knowing the exact purpose of this function, I came to realize that althought it serves as the entrence, it is not the key point of the system. What I’m looking for is the achievement of the concept design of the each service.