Skip to content

Commit 7767e5d

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Devref: Document OSC interfaces available to plugins"
2 parents bd7e1d3 + 91eeacd commit 7767e5d

1 file changed

Lines changed: 63 additions & 1 deletion

File tree

doc/source/plugins.rst

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ The following is a list of projects that are not an OpenStackClient plugin.
5050
Implementation
5151
==============
5252

53+
Client module
54+
-------------
55+
5356
Plugins are discovered by enumerating the entry points
5457
found under :py:mod:`openstack.cli.extension` and initializing the specified
5558
client module.
@@ -65,7 +68,9 @@ The client module must define the following top-level variables:
6568
* ``API_NAME`` - A string containing the plugin API name; this is
6669
the name of the entry point declaring the plugin client module
6770
(``oscplugin = ...`` in the example above) and the group name for
68-
the plugin commands (``openstack.oscplugin.v1 =`` in the example below)
71+
the plugin commands (``openstack.oscplugin.v1 =`` in the example below).
72+
OSC reserves the following API names: ``compute``, ``identity``,
73+
``image``, ``network``, ``object_store`` and ``volume``.
6974
* ``API_VERSION_OPTION`` (optional) - If set, the name of the API
7075
version attribute; this must be a valid Python identifier and
7176
match the destination set in ``build_option_parser()``.
@@ -90,6 +95,9 @@ so the version should not contain the leading 'v' character.
9095

9196
.. code-block:: python
9297
98+
from openstackclient.common import utils
99+
100+
93101
DEFAULT_API_VERSION = '1'
94102
95103
# Required by the OSC plugin interface
@@ -135,6 +143,60 @@ so the version should not contain the leading 'v' character.
135143
' (Env: OS_OSCPLUGIN_API_VERSION)')
136144
return parser
137145
146+
Client usage of OSC interfaces
147+
------------------------------
148+
149+
OSC provides the following interfaces that may be used to implement
150+
the plugin commands:
151+
152+
.. code-block:: python
153+
154+
# OSC common interfaces available to plugins:
155+
from openstackclient.common import command
156+
from openstackclient.common import exceptions
157+
from openstackclient.common import parseractions
158+
from openstackclient.common import logs
159+
from openstackclient.common import utils
160+
161+
162+
class DeleteMypluginobject(command.Command):
163+
"""Delete mypluginobject"""
164+
165+
...
166+
167+
def take_action(self, parsed_args):
168+
# Client manager interfaces are availble to plugins.
169+
# This includes the OSC clients created.
170+
client_manager = self.app.client_manager
171+
172+
...
173+
174+
return
175+
176+
OSC provides the following interfaces that may be used to implement
177+
unit tests for the plugin commands:
178+
179+
.. code-block:: python
180+
181+
# OSC unit test interfaces available to plugins:
182+
from openstackclient.tests import fakes
183+
from openstackclient.tests import utils
184+
185+
...
186+
187+
Requirements
188+
------------
189+
190+
OSC must be included in ``requirements.txt`` or ``test-requirements.txt``
191+
for the plugin project. Update ``requirements.txt`` if the plugin project
192+
considers the CLI a required feature. Update ``test-requirements.txt`` if
193+
the plugin project can be installed as a library with the CLI being an
194+
optional feature (available when OSC is also installed).
195+
196+
.. code-block:: ini
197+
198+
python-openstackclient>=X.Y.Z # Apache-2.0
199+
138200
Checklist for adding new OpenStack plugins
139201
==========================================
140202

0 commit comments

Comments
 (0)