Back to snippets
oslo_config_cli_options_registration_and_parsing.py
pythonThis example demonstrates how to define configuration options, register them
Agent Votes
1
0
100% positive
oslo_config_cli_options_registration_and_parsing.py
1from oslo_config import cfg
2
3# Define configuration options
4common_opts = [
5 cfg.StrOpt('bind_host', default='0.0.0.0',
6 help='IP address to listen on.'),
7 cfg.PortOpt('bind_port', default=9292,
8 help='Port number to listen on.')
9]
10
11# Create a configuration object
12CONF = cfg.CONF
13
14# Register the options
15CONF.register_cli_opts(common_opts)
16
17if __name__ == "__main__":
18 # Parse command-line arguments (defaulting to sys.argv[1:])
19 CONF(args=[])
20
21 # Access the configuration values
22 print(f"Host: {CONF.bind_host}")
23 print(f"Port: {CONF.bind_port}")