summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2019-05-04 14:30:42 +0000
committerGerrit Code Review <review@openstack.org>2019-05-04 14:30:42 +0000
commit053243445c42a0b8c28295cb80b6c4886208aa07 (patch)
tree0ff4245fc21a064ced1ee2c8a301fced77216975
parent31abb90a513a095c4b5b1f468ed48054fbe21fca (diff)
parentbab155673527f88fa6efe50274257fb674ed77b1 (diff)
downloadoslo-config-053243445c42a0b8c28295cb80b6c4886208aa07.tar.gz
Merge "Add a Quick Start tutorial"
-rw-r--r--doc/source/configuration/index.rst1
-rw-r--r--doc/source/configuration/quickstart.rst78
2 files changed, 79 insertions, 0 deletions
diff --git a/doc/source/configuration/index.rst b/doc/source/configuration/index.rst
index 4858bd5..7dfa30e 100644
--- a/doc/source/configuration/index.rst
+++ b/doc/source/configuration/index.rst
@@ -5,6 +5,7 @@
.. toctree::
:maxdepth: 2
+ quickstart
format
mutable
options
diff --git a/doc/source/configuration/quickstart.rst b/doc/source/configuration/quickstart.rst
new file mode 100644
index 0000000..21fc722
--- /dev/null
+++ b/doc/source/configuration/quickstart.rst
@@ -0,0 +1,78 @@
+==========================
+ oslo.config Quick Start!
+==========================
+
+Are you brand new to oslo.config? This brief tutorial will get you started
+understanding some of the fundamentals.
+
+Prerequisites
+-------------
+* A plain text editor or Python-enabled IDE
+* A Python interpreter
+* A command shell from which the interpreter can be invoked
+* The oslo_config library in your Python path.
+
+Test Script
+-----------
+Put this in a file called ``oslocfgtest.py``.
+
+.. code:: python
+
+ # The sys module lets you get at the command line arguments.
+ import sys
+
+ # Load up the cfg module, which contains all the classes and methods
+ # you'll need.
+ from oslo_config import cfg
+
+ # Define an option group
+ grp = cfg.OptGroup('mygroup')
+
+ # Define a couple of options
+ opts = [cfg.StrOpt('option1'),
+ cfg.IntOpt('option2', default=42)]
+
+ # Register your config group
+ cfg.CONF.register_group(grp)
+
+ # Register your options within the config group
+ cfg.CONF.register_opts(opts, group=grp)
+
+ # Process command line arguments. The arguments tell CONF where to
+ # find your config file, which it loads and parses to populate itself.
+ cfg.CONF(sys.argv[1:])
+
+ # Now you can access the values from the config file as
+ # CONF.<group>.<opt>
+ print("The value of option1 is %s" % cfg.CONF.mygroup.option1)
+ print("The value of option2 is %d" % cfg.CONF.mygroup.option2)
+
+Conf File
+---------
+Put this in a file called ``oslocfgtest.conf`` in the same directory as
+``oslocfgtest.py``.
+
+.. code:: ini
+
+ [mygroup]
+ option1 = foo
+ # Comment out option2 to test the default value
+ # option2 = 123
+
+Run It!
+-------
+From your command shell, in the same directory as your script and conf, invoke:
+
+.. code:: shell
+
+ python oslocfgtest.py --config-file oslocfgtest.conf
+
+Revel in the output being exactly as expected. If you've done everything
+right, you should see:
+
+.. code:: shell
+
+ The value of option1 is foo
+ The value of option2 is 42
+
+Now go play with some more advanced option settings!