Skip to content

Commit 91eeacd

Browse files
committed
Devref: Document OSC interfaces available to plugins
This devref documents the OSC interfaces are officially available for plugins to implement commands and related unit tests. It also covers requirements for plugins. Change-Id: I68caa188e389e400fa9f5fd38f32c76cdd3e0986
1 parent 9447a0e commit 91eeacd

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
@@ -45,6 +45,9 @@ python-zaqarclient using OpenStackClient
4545
Implementation
4646
==============
4747

48+
Client module
49+
-------------
50+
4851
Plugins are discovered by enumerating the entry points
4952
found under :py:mod:`openstack.cli.extension` and initializing the specified
5053
client module.
@@ -60,7 +63,9 @@ The client module must define the following top-level variables:
6063
* ``API_NAME`` - A string containing the plugin API name; this is
6164
the name of the entry point declaring the plugin client module
6265
(``oscplugin = ...`` in the example above) and the group name for
63-
the plugin commands (``openstack.oscplugin.v1 =`` in the example below)
66+
the plugin commands (``openstack.oscplugin.v1 =`` in the example below).
67+
OSC reserves the following API names: ``compute``, ``identity``,
68+
``image``, ``network``, ``object_store`` and ``volume``.
6469
* ``API_VERSION_OPTION`` (optional) - If set, the name of the API
6570
version attribute; this must be a valid Python identifier and
6671
match the destination set in ``build_option_parser()``.
@@ -85,6 +90,9 @@ so the version should not contain the leading 'v' character.
8590

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

0 commit comments

Comments
 (0)