diff --git a/doc/source/index.rst b/doc/source/index.rst index 467fb11b..20e50d07 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -11,6 +11,7 @@ Contents install/index contributor/index cli/index + user/index Indices and tables ------------------ diff --git a/doc/source/user/index.rst b/doc/source/user/index.rst new file mode 100644 index 00000000..19012772 --- /dev/null +++ b/doc/source/user/index.rst @@ -0,0 +1,7 @@ +Reference +========= + +.. toctree:: + :maxdepth: 1 + + python-api diff --git a/doc/source/user/python-api.rst b/doc/source/user/python-api.rst new file mode 100644 index 00000000..c6c62c3b --- /dev/null +++ b/doc/source/user/python-api.rst @@ -0,0 +1,52 @@ +================================ + The :mod:`zunclient` Python API +================================ + +.. module:: zunclient + :synopsis: A client for the OpenStack Zun API. + +.. currentmodule:: zunclient + +Usage +----- + +First create a client instance with your credentials:: + + >>> from zunclient import client + >>> zun = client.Client(VERSION, auth_url=AUTH_URL, username=USERNAME, + ... password=PASSWORD, project_name=PROJECT_NAME, + ... user_domain_name='default', + ... project_domain_name='default') + +Here ``VERSION`` can be a string or ``zunclient.api_versions.APIVersion`` obj. +If you prefer string value, you can use ``1`` or +``1.X`` (where X is a microversion). + +Alternatively, you can create a client instance using the keystoneauth +session API:: + + >>> from keystoneauth1 import loading + >>> from keystoneauth1 import session + >>> from zunclient import client + >>> loader = loading.get_plugin_loader('password') + >>> auth = loader.load_from_options(auth_url=AUTH_URL, + ... username=USERNAME, + ... password=PASSWORD, + ... project_name=PROJECT_NAME, + ... user_domain_name='default', + ... project_domain_name='default') + >>> sess = session.Session(auth=auth) + >>> zun = client.Client(VERSION, session=sess) + +If you have PROJECT_NAME instead of a PROJECT_ID, use the project_name +parameter. Similarly, if your cloud uses keystone v3 and you have a DOMAIN_NAME +or DOMAIN_ID, provide it as `user_domain_(name|id)` and if you are using a +PROJECT_NAME also provide the domain information as `project_domain_(name|id)`. + +Then call methods on its managers:: + + >>> zun.containers.list() + [] + + >>> zun.containers.run(name="my-container", image='nginx') +