From 489979757d868aadbc7b547c2efbbc948b51ef33 Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Mon, 16 Feb 2015 17:14:12 +0100 Subject: [PATCH] Add python-openstackclient plugin for ironic-discoverd $ openstack baremetal introspection {start, status} UUID Closes-Bug: #1410180 Closes-Bug: #1429148 Change-Id: Ie009a8430e9e7d7529ac1a492d31896c3405d3de --- README.rst | 49 ++++++++++++---------- ironic_discoverd/shell.py | 88 +++++++++++++++++++++++++++++++++++++++ requirements.txt | 2 + setup.py | 9 +++- 4 files changed, 125 insertions(+), 23 deletions(-) create mode 100644 ironic_discoverd/shell.py diff --git a/README.rst b/README.rst index 04e08618c..1cc3c34c6 100644 --- a/README.rst +++ b/README.rst @@ -193,30 +193,37 @@ in Fedora `_. + :: + + $ 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/`` 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. `_ 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 diff --git a/ironic_discoverd/shell.py b/ironic_discoverd/shell.py new file mode 100644 index 000000000..fb60b903c --- /dev/null +++ b/ironic_discoverd/shell.py @@ -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).') diff --git a/requirements.txt b/requirements.txt index 96abd163f..537fba9da 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/setup.py b/setup.py index b8b59bbf7..3f3230a75 100644 --- a/setup.py +++ b/setup.py @@ -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',