Openstack configuration Parsing Library -- Oslo. config

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.