Add python-openstackclient plugin for ironic-discoverd

$ openstack baremetal introspection {start, status} UUID

Closes-Bug: #1410180
Closes-Bug: #1429148
Change-Id: Ie009a8430e9e7d7529ac1a492d31896c3405d3de
This commit is contained in:
Dmitry Tantsur 2015-02-16 17:14:12 +01:00
parent e38f05b9e1
commit 489979757d
4 changed files with 125 additions and 23 deletions

View File

@ -193,30 +193,37 @@ in Fedora <http://pkgs.fedoraproject.org/cgit/openstack-ironic-discoverd.git/pla
Usage
-----
**ironic-discoverd** has a simple client library bundled within it.
It provides functions:
**ironic-discoverd** has a simple client library for Python and a CLI tool
bundled with it.
* ``ironic_discoverd.client.introspect`` for starting introspection
* ``ironic_discoverd.client.get_status`` for querying introspection status
Client library is in module ``ironic_discoverd.client``, every call
accepts additional optional arguments:
both accepting:
* ``base_url`` **ironic-discoverd** API endpoint, defaults to
``127.0.0.1:5050``,
* ``auth_token`` Keystone authentication token.
``uuid``
node UUID
``base_url``
optional **ironic-discoverd** service URL (defaults to ``127.0.0.1:5050``)
``auth_token``
optional Keystone token.
CLI tool is based on OpenStackClient_ with prefix
``openstack baremetal introspection``. Accepts optional argument
``--discoverd-url`` with the **ironic-discoverd** API endpoint.
For testing purposes you can also use it from CLI::
* **Start introspection on a node**:
python -m ironic_discoverd.client --auth-token TOKEN introspect UUID
python -m ironic_discoverd.client --auth-token TOKEN get_status UUID
``introspect(uuid, new_ipmi_username=None, new_ipmi_password=None)``
.. note::
This CLI interface is not stable and may be changed without prior notice.
Proper supported CLI is `expected later
<https://bugs.launchpad.net/ironic-discoverd/+bug/1410180>`_.
::
$ openstack baremetal introspection start UUID [--new-ipmi-password=PWD [--new-ipmi-username=USER]]
* **Query introspection status**:
``get_status(uuid)``
::
$ openstack baremetal introspection status UUID
.. _OpenStackClient: http://docs.openstack.org/developer/python-openstackclient/
HTTP API
~~~~~~~~
@ -250,8 +257,6 @@ The HTTP API consist of these endpoints:
* 401, 403 - missing or invalid authentication
* 404 - node cannot be found
Client library function: ``ironic_discoverd.client.introspect``.
* ``GET /v1/introspection/<UUID>`` get hardware discovery status.
Requires X-Auth-Token header with Keystone token for authentication.
@ -268,8 +273,6 @@ The HTTP API consist of these endpoints:
* ``finished`` (boolean) whether discovery is finished
* ``error`` error string or ``null``
Client library function: ``ironic_discoverd.client.get_status``.
* ``POST /v1/continue`` internal endpoint for the discovery ramdisk to post
back discovered data. Should not be used for anything other than implementing
the ramdisk. Request body: JSON dictionary with at least these keys:
@ -406,6 +409,8 @@ See `1.1.0 release tracking page`_ for details.
<https://blueprints.launchpad.net/ironic-discoverd/+spec/setup-ipmi-credentials-take2>`_
for what changed since 1.0.0 (tl;dr: everything).
* Proper CLI tool implemented as a plugin for OpenStackClient_.
**Other Changes**
* Experimental plugin ``edeploy`` to use with

88
ironic_discoverd/shell.py Normal file
View File

@ -0,0 +1,88 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""OpenStackClient plugin for ironic-discoverd."""
import logging
from cliff import command
from cliff import show
from openstackclient.common import utils
from ironic_discoverd import client
LOG = logging.getLogger('ironic_discoverd.shell')
API_NAME = 'baremetal-introspection'
API_VERSION_OPTION = 'discoverd_api_version'
DEFAULT_VERSION = '1'
def build_option_parser(parser):
parser.add_argument('--discoverd-api-version',
default=utils.env('DISCOVERD_VERSION',
default=DEFAULT_VERSION),
help='discoverd API version, only 1 is supported now '
'(env: DISCOVERD_VERSION).')
return parser
class StartCommand(command.Command):
"""Start the introspection."""
def get_parser(self, prog_name):
parser = super(StartCommand, self).get_parser(prog_name)
_add_common_arguments(parser)
parser.add_argument('--new-ipmi-username',
default=None,
help='if set, *ironic-discoverd* will update IPMI '
'user name to this value')
parser.add_argument('--new-ipmi-password',
default=None,
help='if set, *ironic-discoverd* will update IPMI '
'password to this value')
return parser
def take_action(self, parsed_args):
auth_token = self.app.client_manager.auth_ref.auth_token
client.introspect(parsed_args.uuid, base_url=parsed_args.discoverd_url,
auth_token=auth_token,
new_ipmi_username=parsed_args.new_ipmi_username,
new_ipmi_password=parsed_args.new_ipmi_password)
class StatusCommand(show.ShowOne):
"""Get introspection status."""
def get_parser(self, prog_name):
parser = super(StatusCommand, self).get_parser(prog_name)
_add_common_arguments(parser)
return parser
def take_action(self, parsed_args):
auth_token = self.app.client_manager.auth_ref.auth_token
status = client.get_status(parsed_args.uuid,
base_url=parsed_args.discoverd_url,
auth_token=auth_token)
return zip(*sorted(status.items()))
def _add_common_arguments(parser):
"""Add commonly used arguments to a parser."""
parser.add_argument('uuid', help='baremetal node UUID')
# FIXME(dtantsur): this should be in build_option_parser, but then it won't
# be available in commands
parser.add_argument('--discoverd-url',
default=utils.env('DISCOVERD_URL', default=None),
help='discoverd URL, defaults to localhost '
'(env: DISCOVERD_URL).')

View File

@ -1,11 +1,13 @@
# The order of packages is significant, because pip processes them in the order
# of appearance. Changing the order has an impact on the overall integration
# process, which may cause wedges in the gate later.
cliff>=1.7.0 # Apache-2.0
eventlet>=0.16.1
Flask>=0.10,<1.0
keystonemiddleware>=1.0.0
python-ironicclient>=0.2.1
python-keystoneclient>=1.1.0
python-openstackclient>=1.0.0
requests>=2.2.0,!=2.4.0
oslo.i18n>=1.3.0 # Apache-2.0
oslo.utils>=1.2.0 # Apache-2.0

View File

@ -29,7 +29,7 @@ setup(
install_requires = install_requires,
entry_points = {
'console_scripts': [
"ironic-discoverd = ironic_discoverd.main:main"
"ironic-discoverd = ironic_discoverd.main:main",
],
'ironic_discoverd.hooks': [
"scheduler = ironic_discoverd.plugins.standard:SchedulerHook",
@ -39,6 +39,13 @@ setup(
"edeploy = ironic_discoverd.plugins.edeploy:eDeployHook",
"root_device_hint = ironic_discoverd.plugins.root_device_hint:RootDeviceHintHook",
],
'openstack.cli.extension': [
'baremetal-introspection = ironic_discoverd.shell',
],
'openstack.baremetal_introspection.v1': [
"baremetal_introspection_start = ironic_discoverd.shell:StartCommand",
"baremetal_introspection_status = ironic_discoverd.shell:StatusCommand",
],
},
classifiers = [
'Development Status :: 5 - Production/Stable',