ironic-inspector/ironic_inspector/shell.py
Dmitry Tantsur d6404d2f99 Rename discoverd -> inspector
As agreed on the summit I'm renaming the python modules
and doing some adjustments:
* This is a breaking change, so version is bumped to 2.0.0
* Used this chance to split conf options over proper sections
* RELEASES.rst is gone; it's too hard to keep it up-to-date;
  anyway git does better job at doing history
* Dropped deprecated option ports_for_inactive_interfaces
* Dropped old /v1/discover endpoint and associated client call
* No longer set on_discovery and newly_discovered in Node.extra
  (deprecated since 1.0.0, superseded by the get status API)
* Default firewall chain name is "ironic-inspector" and
  is configurable

Notes:
* Some links will be updated after real move.
* Stable branches will probably use the old name.
* Some usage of discovery word is left in context of
  "discovered data"
* DIB element will probably be deprecated, so leaving it
  alone for now.
* Some usages of word "discovery" in the README will be updated
  later to make this patch a bit smaller
* Ramdisk code will be moved to IPA, so not touching it too much

Change-Id: I59f1f5bfb1248ab69973dab845aa028df493054e
2015-05-29 09:06:56 +02:00

97 lines
3.6 KiB
Python

# 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-inspector."""
from __future__ import print_function
import logging
from cliff import command
from cliff import show
from openstackclient.common import utils
from ironic_inspector import client
LOG = logging.getLogger('ironic_inspector.shell')
API_NAME = 'baremetal-introspection'
API_VERSION_OPTION = 'inspector_api_version'
DEFAULT_VERSION = '1'
API_VERSIONS = {
"1": "ironic_inspector.shell",
}
def build_option_parser(parser):
parser.add_argument('--inspector-api-version',
default=utils.env('INSPECTOR_VERSION',
default=DEFAULT_VERSION),
help='inspector API version, only 1 is supported now '
'(env: INSPECTOR_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-inspector* will update IPMI '
'user name to this value')
parser.add_argument('--new-ipmi-password',
default=None,
help='if set, *ironic-inspector* 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.inspector_url,
auth_token=auth_token,
new_ipmi_username=parsed_args.new_ipmi_username,
new_ipmi_password=parsed_args.new_ipmi_password)
if parsed_args.new_ipmi_password:
print('Setting IPMI credentials requested, please power on '
'the machine manually')
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.inspector_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('--inspector-url',
default=utils.env('INSPECTOR_URL', default=None),
help='inspector URL, defaults to localhost '
'(env: INSPECTOR_URL).')