The Oslo project of openstack aims to independently develop the basic functions that can be reused in the system. config is a widely used library. The main purpose of this function is to parse the command line (CLI) or configuration file (. conf. The following describes how to use the high-level database.
To use configuration files in openstack, follow these steps,
Step 1. Correctly configure the master configuration file (. conf file) for each service.
Step2. declare the configuration items that will be used by this module (for example, 'auth _ host'...) in the module to use the configuration file '...), including the configuration item name, data type, default value, and description;
Step create an object and the class of this object acts as the Configuration Manager. this object will become the container for configuration items in the configuration file.
Step call the registration method of the newly created object to register the configuration items we need. This process will parse the configuration file and extract the actual values of the required configuration items from it, then, the names of these configuration items can be directly used as the attributes of this object.
A complete instance is as follows:
First, set the configuration file (. conf file) correctly. Here, only part of the diagram is provided.
[Default] bind_host = 0.0.0.0
Bind_port = 9292... [Rabbit] HOST = localhostport = 5672use_ssl = falseuserid = guestpassword = guest...
Write the following in the module where you want to view the configuration file information:
First load the library,
From Oslo. config import cfg
Then declare the configuration information that will be used in this module,
Opts = [cfg. stropt ('Bind _ host', default = '0. 0.0.0 '), CFG. Partition Pt ('Bind _ port', default = 9292),]
Then call the object to generate the container,
Conf = cfg. conf
Then, call the method of the object to register the target configuration item. The target configuration file will be parsed, and the required configuration item values will be extracted and stored in the called object. The attribute name is the name of the configuration item, the attribute value is the value of the corresponding configuration item in the configuration file.
Conf. register_opts (OPTs) conf (default_config_files = 'glance. conf ')
Then you can use the extracted configuration information.
Def start (server, APP): Server. Start (app, Conf. bind_port, Conf. bind_host)