Move duplicated info to new v1/utils.py
This moves duplicated information to a new v1/utils.py file: - list of HTTP codes - list of boot devices - provision-related information Change-Id: I4a11627359213770dbc8aa037fcf95ed7bfd0870
This commit is contained in:
parent
464044f87d
commit
24032199ed
@ -21,6 +21,7 @@ from osc_lib import utils as oscutils
|
||||
|
||||
from ironicclient.common import utils
|
||||
from ironicclient.v1 import resource_fields as res_fields
|
||||
from ironicclient.v1 import utils as v1_utils
|
||||
|
||||
|
||||
class ListBaremetalDriver(command.Lister):
|
||||
@ -52,7 +53,6 @@ class PassthruCallBaremetalDriver(command.ShowOne):
|
||||
"""Call a vendor passthru method for a driver."""
|
||||
|
||||
log = logging.getLogger(__name__ + ".PassthruCallBaremetalDriver")
|
||||
http_methods = ['POST', 'PUT', 'GET', 'DELETE', 'PATCH']
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(PassthruCallBaremetalDriver, self).get_parser(prog_name)
|
||||
@ -77,11 +77,11 @@ class PassthruCallBaremetalDriver(command.ShowOne):
|
||||
'--http-method',
|
||||
dest='http_method',
|
||||
metavar='<http-method>',
|
||||
choices=self.http_methods,
|
||||
choices=v1_utils.HTTP_METHODS,
|
||||
default='POST',
|
||||
help="The HTTP method to use in the passthru request. One of "
|
||||
"%s. Defaults to 'POST'." %
|
||||
oscutils.format_list(self.http_methods)
|
||||
oscutils.format_list(v1_utils.HTTP_METHODS)
|
||||
)
|
||||
return parser
|
||||
|
||||
|
@ -25,6 +25,7 @@ from ironicclient.common.i18n import _
|
||||
from ironicclient.common import utils
|
||||
from ironicclient import exc
|
||||
from ironicclient.v1 import resource_fields as res_fields
|
||||
from ironicclient.v1 import utils as v1_utils
|
||||
|
||||
|
||||
class ProvisionStateBaremetalNode(command.Command):
|
||||
@ -77,8 +78,6 @@ class BootdeviceSetBaremetalNode(command.Command):
|
||||
|
||||
log = logging.getLogger(__name__ + ".BootdeviceSetBaremetalNode")
|
||||
|
||||
BOOT_DEVICES = ['pxe', 'disk', 'cdrom', 'bios', 'safe']
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(BootdeviceSetBaremetalNode, self).get_parser(prog_name)
|
||||
|
||||
@ -90,8 +89,8 @@ class BootdeviceSetBaremetalNode(command.Command):
|
||||
parser.add_argument(
|
||||
'device',
|
||||
metavar='<device>',
|
||||
choices=self.BOOT_DEVICES,
|
||||
help="One of %s" % (oscutils.format_list(self.BOOT_DEVICES))
|
||||
choices=v1_utils.BOOT_DEVICES,
|
||||
help="One of %s" % (oscutils.format_list(v1_utils.BOOT_DEVICES))
|
||||
)
|
||||
parser.add_argument(
|
||||
'--persistent',
|
||||
@ -623,8 +622,6 @@ class PassthruCallBaremetalNode(command.Command):
|
||||
|
||||
log = logging.getLogger(__name__ + ".PassthuCallBaremetalNode")
|
||||
|
||||
HTTP_METHODS = ['POST', 'PUT', 'GET', 'DELETE', 'PATCH']
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(PassthruCallBaremetalNode, self).get_parser(
|
||||
prog_name)
|
||||
@ -649,11 +646,11 @@ class PassthruCallBaremetalNode(command.Command):
|
||||
parser.add_argument(
|
||||
'--http-method',
|
||||
metavar='<http-method>',
|
||||
choices=self.HTTP_METHODS,
|
||||
choices=v1_utils.HTTP_METHODS,
|
||||
default='POST',
|
||||
help="The HTTP method to use in the passthru request. One of "
|
||||
"%s. Defaults to POST." %
|
||||
oscutils.format_list(self.HTTP_METHODS)
|
||||
oscutils.format_list(v1_utils.HTTP_METHODS)
|
||||
)
|
||||
return parser
|
||||
|
||||
|
@ -23,6 +23,7 @@ from ironicclient.common import utils as commonutils
|
||||
from ironicclient import exc
|
||||
from ironicclient.osc.v1 import baremetal_node
|
||||
from ironicclient.tests.unit.osc.v1 import fakes as baremetal_fakes
|
||||
from ironicclient.v1 import utils as v1_utils
|
||||
|
||||
|
||||
class TestBaremetal(baremetal_fakes.TestBaremetal):
|
||||
@ -118,7 +119,7 @@ class TestBootdeviceShow(TestBaremetal):
|
||||
"boot_device": "pxe", "persistent": False}
|
||||
|
||||
self.baremetal_mock.node.get_supported_boot_devices.return_value = {
|
||||
"supported_boot_devices": ["cdrom", "bios", "safe", "disk", "pxe"]}
|
||||
"supported_boot_devices": v1_utils.BOOT_DEVICES}
|
||||
|
||||
def test_bootdevice_show(self):
|
||||
arglist = ['node_uuid']
|
||||
|
@ -23,6 +23,7 @@ from ironicclient.common import utils as commonutils
|
||||
from ironicclient import exc
|
||||
from ironicclient.tests.unit import utils
|
||||
import ironicclient.v1.node_shell as n_shell
|
||||
import ironicclient.v1.utils as v1_utils
|
||||
|
||||
|
||||
class NodeShellTest(utils.BaseTestCase):
|
||||
@ -507,7 +508,7 @@ class NodeShellTest(utils.BaseTestCase):
|
||||
'node_uuid', 'active', configdrive='foo', cleansteps=None)
|
||||
client_mock.node.wait_for_provision_state.assert_called_once_with(
|
||||
'node_uuid', expected_state='active', timeout=0,
|
||||
poll_interval=n_shell._LONG_ACTION_POLL_INTERVAL)
|
||||
poll_interval=v1_utils._LONG_ACTION_POLL_INTERVAL)
|
||||
|
||||
def test_do_node_set_provision_state_deleted(self):
|
||||
client_mock = mock.MagicMock()
|
||||
|
@ -18,6 +18,7 @@ import argparse
|
||||
from ironicclient.common import cliutils
|
||||
from ironicclient.common import utils
|
||||
from ironicclient.v1 import resource_fields as res_fields
|
||||
from ironicclient.v1 import utils as v1_utils
|
||||
|
||||
|
||||
def _print_driver_show(driver, json=False):
|
||||
@ -95,10 +96,10 @@ def do_driver_raid_logical_disk_properties(cc, args):
|
||||
"Can be specified multiple times.")
|
||||
@cliutils.arg('--http-method',
|
||||
metavar='<http-method>',
|
||||
choices=['POST', 'PUT', 'GET', 'DELETE', 'PATCH'],
|
||||
help="The HTTP method to use in the request. Valid HTTP "
|
||||
"methods are: 'POST', 'PUT', 'GET', 'DELETE', and 'PATCH'. "
|
||||
"Defaults to 'POST'.")
|
||||
choices=v1_utils.HTTP_METHODS,
|
||||
help=("The HTTP method to use in the request. Valid HTTP "
|
||||
"methods are: %s. Defaults to 'POST'." %
|
||||
', '.join(v1_utils.HTTP_METHODS)))
|
||||
@cliutils.arg('--http_method',
|
||||
help=argparse.SUPPRESS)
|
||||
def do_driver_vendor_passthru(cc, args):
|
||||
|
@ -21,35 +21,7 @@ from ironicclient.common.i18n import _
|
||||
from ironicclient.common import utils
|
||||
from ironicclient import exc
|
||||
from ironicclient.v1 import resource_fields as res_fields
|
||||
|
||||
|
||||
# Polling intervals in seconds.
|
||||
_LONG_ACTION_POLL_INTERVAL = 10
|
||||
_SHORT_ACTION_POLL_INTERVAL = 2
|
||||
# This dict acts as both list of possible provision actions and arguments for
|
||||
# wait_for_provision_state invocation.
|
||||
PROVISION_ACTIONS = {
|
||||
'active': {'expected_state': 'active',
|
||||
'poll_interval': _LONG_ACTION_POLL_INTERVAL},
|
||||
'deleted': {'expected_state': 'available',
|
||||
'poll_interval': _LONG_ACTION_POLL_INTERVAL},
|
||||
'rebuild': {'expected_state': 'active',
|
||||
'poll_interval': _LONG_ACTION_POLL_INTERVAL},
|
||||
'inspect': {'expected_state': 'manageable',
|
||||
# This is suboptimal for in-band inspection, but it's probably
|
||||
# not worth making people wait 10 seconds for OOB inspection
|
||||
'poll_interval': _SHORT_ACTION_POLL_INTERVAL},
|
||||
'provide': {'expected_state': 'available',
|
||||
# This assumes cleaning is in place
|
||||
'poll_interval': _LONG_ACTION_POLL_INTERVAL},
|
||||
'manage': {'expected_state': 'manageable',
|
||||
'poll_interval': _SHORT_ACTION_POLL_INTERVAL},
|
||||
'clean': {'expected_state': 'manageable',
|
||||
'poll_interval': _LONG_ACTION_POLL_INTERVAL},
|
||||
'adopt': {'expected_state': 'active',
|
||||
'poll_interval': _SHORT_ACTION_POLL_INTERVAL},
|
||||
'abort': None, # no support for --wait in abort
|
||||
}
|
||||
from ironicclient.v1 import utils as v1_utils
|
||||
|
||||
|
||||
def _print_node_show(node, fields=None, json=False):
|
||||
@ -323,10 +295,10 @@ def do_node_update(cc, args):
|
||||
"be specified multiple times."))
|
||||
@cliutils.arg('--http-method',
|
||||
metavar='<http-method>',
|
||||
choices=['POST', 'PUT', 'GET', 'DELETE', 'PATCH'],
|
||||
help="The HTTP method to use in the request. Valid HTTP "
|
||||
"methods are: 'POST', 'PUT', 'GET', 'DELETE', and 'PATCH'. "
|
||||
"Defaults to 'POST'.")
|
||||
choices=v1_utils.HTTP_METHODS,
|
||||
help=("The HTTP method to use in the request. Valid HTTP "
|
||||
"methods are: %s. Defaults to 'POST'." %
|
||||
', '.join(v1_utils.HTTP_METHODS)))
|
||||
@cliutils.arg('--http_method',
|
||||
help=argparse.SUPPRESS)
|
||||
def do_node_vendor_passthru(cc, args):
|
||||
@ -468,9 +440,8 @@ def do_node_set_target_raid_config(cc, args):
|
||||
@cliutils.arg(
|
||||
'provision_state',
|
||||
metavar='<provision-state>',
|
||||
choices=list(PROVISION_ACTIONS),
|
||||
help="Supported states: %s." % ', '.join("'%s'" % state
|
||||
for state in PROVISION_ACTIONS))
|
||||
choices=v1_utils.PROVISION_STATES,
|
||||
help="Supported states: %s." % ', '.join(v1_utils.PROVISION_STATES))
|
||||
@cliutils.arg(
|
||||
'--config-drive',
|
||||
metavar='<config-drive>',
|
||||
@ -516,7 +487,7 @@ def do_node_set_provision_state(cc, args):
|
||||
'setting provision state to "clean"'))
|
||||
|
||||
if args.wait_timeout is not None:
|
||||
wait_args = PROVISION_ACTIONS.get(args.provision_state)
|
||||
wait_args = v1_utils.PROVISION_ACTIONS.get(args.provision_state)
|
||||
if wait_args is None:
|
||||
raise exceptions.CommandError(
|
||||
_("--wait is not supported for provision state '%s'")
|
||||
@ -574,8 +545,8 @@ def do_node_set_console_mode(cc, args):
|
||||
@cliutils.arg(
|
||||
'device',
|
||||
metavar='<boot-device>',
|
||||
choices=['pxe', 'disk', 'cdrom', 'bios', 'safe'],
|
||||
help="'pxe', 'disk', 'cdrom', 'bios', or 'safe'.")
|
||||
choices=v1_utils.BOOT_DEVICES,
|
||||
help="One of %s." % ', '.join(v1_utils.BOOT_DEVICES))
|
||||
@cliutils.arg(
|
||||
'--persistent',
|
||||
dest='persistent',
|
||||
|
48
ironicclient/v1/utils.py
Normal file
48
ironicclient/v1/utils.py
Normal file
@ -0,0 +1,48 @@
|
||||
# Copyright 2016 Intel Corporation
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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.
|
||||
|
||||
HTTP_METHODS = ['POST', 'PUT', 'GET', 'DELETE', 'PATCH']
|
||||
|
||||
BOOT_DEVICES = ['pxe', 'disk', 'cdrom', 'bios', 'safe']
|
||||
|
||||
# Polling intervals in seconds.
|
||||
_LONG_ACTION_POLL_INTERVAL = 10
|
||||
_SHORT_ACTION_POLL_INTERVAL = 2
|
||||
# This dict acts as both list of possible provision actions and arguments for
|
||||
# wait_for_provision_state invocation.
|
||||
PROVISION_ACTIONS = {
|
||||
'active': {'expected_state': 'active',
|
||||
'poll_interval': _LONG_ACTION_POLL_INTERVAL},
|
||||
'deleted': {'expected_state': 'available',
|
||||
'poll_interval': _LONG_ACTION_POLL_INTERVAL},
|
||||
'rebuild': {'expected_state': 'active',
|
||||
'poll_interval': _LONG_ACTION_POLL_INTERVAL},
|
||||
'inspect': {'expected_state': 'manageable',
|
||||
# This is suboptimal for in-band inspection, but it's probably
|
||||
# not worth making people wait 10 seconds for OOB inspection
|
||||
'poll_interval': _SHORT_ACTION_POLL_INTERVAL},
|
||||
'provide': {'expected_state': 'available',
|
||||
# This assumes cleaning is in place
|
||||
'poll_interval': _LONG_ACTION_POLL_INTERVAL},
|
||||
'manage': {'expected_state': 'manageable',
|
||||
'poll_interval': _SHORT_ACTION_POLL_INTERVAL},
|
||||
'clean': {'expected_state': 'manageable',
|
||||
'poll_interval': _LONG_ACTION_POLL_INTERVAL},
|
||||
'adopt': {'expected_state': 'active',
|
||||
'poll_interval': _SHORT_ACTION_POLL_INTERVAL},
|
||||
'abort': None, # no support for --wait in abort
|
||||
}
|
||||
|
||||
PROVISION_STATES = list(PROVISION_ACTIONS)
|
Loading…
x
Reference in New Issue
Block a user