Remove use of oslo.utils
While a relatively small library, this is one import that we really don't need. Remove it. Change-Id: I726f3c3548cbd896588ef0613222e36c529f5bcc Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
parent
8735b862c5
commit
08551106e6
@ -32,13 +32,11 @@ from osc_lib.cli import parseractions
|
||||
from osc_lib.command import command
|
||||
from osc_lib import exceptions
|
||||
from osc_lib import utils
|
||||
from oslo_utils import strutils
|
||||
|
||||
from openstackclient.i18n import _
|
||||
from openstackclient.identity import common as identity_common
|
||||
from openstackclient.network import common as network_common
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
IMAGE_STRING_FOR_BFV = 'N/A (booted from volume)'
|
||||
@ -273,6 +271,30 @@ def _prep_server_detail(compute_client, image_client, server, refresh=True):
|
||||
return info
|
||||
|
||||
|
||||
def bool_from_str(value, strict=False):
|
||||
true_strings = ('1', 't', 'true', 'on', 'y', 'yes')
|
||||
false_strings = ('0', 'f', 'false', 'off', 'n', 'no')
|
||||
|
||||
if isinstance(value, bool):
|
||||
return value
|
||||
|
||||
lowered = value.strip().lower()
|
||||
if lowered in true_strings:
|
||||
return True
|
||||
elif lowered in false_strings or not strict:
|
||||
return False
|
||||
|
||||
msg = _(
|
||||
"Unrecognized value '%(value)s'; acceptable values are: %(valid)s"
|
||||
) % {
|
||||
'value': value,
|
||||
'valid': ', '.join(
|
||||
f"'{s}'" for s in sorted(true_strings + false_strings)
|
||||
),
|
||||
}
|
||||
raise ValueError(msg)
|
||||
|
||||
|
||||
def boolenv(*vars, default=False):
|
||||
"""Search for the first defined of possibly many bool-like env vars.
|
||||
|
||||
@ -287,7 +309,7 @@ def boolenv(*vars, default=False):
|
||||
for v in vars:
|
||||
value = os.environ.get(v, None)
|
||||
if value:
|
||||
return strutils.bool_from_string(value)
|
||||
return bool_from_str(value)
|
||||
return default
|
||||
|
||||
|
||||
@ -1713,8 +1735,9 @@ class CreateServer(command.ShowOne):
|
||||
|
||||
if 'delete_on_termination' in mapping:
|
||||
try:
|
||||
value = strutils.bool_from_string(
|
||||
mapping['delete_on_termination'], strict=True
|
||||
value = bool_from_str(
|
||||
mapping['delete_on_termination'],
|
||||
strict=True,
|
||||
)
|
||||
except ValueError:
|
||||
msg = _(
|
||||
|
@ -16,6 +16,7 @@
|
||||
"""Compute v2 Server operation event implementations"""
|
||||
|
||||
import logging
|
||||
import uuid
|
||||
|
||||
from cliff import columns
|
||||
import iso8601
|
||||
@ -24,14 +25,37 @@ from openstack import utils as sdk_utils
|
||||
from osc_lib.command import command
|
||||
from osc_lib import exceptions
|
||||
from osc_lib import utils
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
from openstackclient.i18n import _
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# TODO(stephenfin): Move this to osc_lib since it's useful elsewhere (e.g.
|
||||
# glance)
|
||||
def is_uuid_like(value) -> bool:
|
||||
"""Returns validation of a value as a UUID.
|
||||
|
||||
:param val: Value to verify
|
||||
:type val: string
|
||||
:returns: bool
|
||||
|
||||
.. versionchanged:: 1.1.1
|
||||
Support non-lowercase UUIDs.
|
||||
"""
|
||||
try:
|
||||
formatted_value = (
|
||||
value.replace('urn:', '')
|
||||
.replace('uuid:', '')
|
||||
.strip('{}')
|
||||
.replace('-', '')
|
||||
.lower()
|
||||
)
|
||||
return str(uuid.UUID(value)).replace('-', '') == formatted_value
|
||||
except (TypeError, ValueError, AttributeError):
|
||||
return False
|
||||
|
||||
|
||||
class ServerActionEventColumn(columns.FormattableColumn):
|
||||
"""Custom formatter for server action events.
|
||||
|
||||
@ -202,7 +226,7 @@ class ListServerEvent(command.Lister):
|
||||
# If we fail to find the resource, it is possible the server is
|
||||
# deleted. Try once more using the <server> arg directly if it is a
|
||||
# UUID.
|
||||
if uuidutils.is_uuid_like(parsed_args.server):
|
||||
if is_uuid_like(parsed_args.server):
|
||||
server_id = parsed_args.server
|
||||
else:
|
||||
raise
|
||||
@ -275,7 +299,7 @@ class ShowServerEvent(command.ShowOne):
|
||||
# If we fail to find the resource, it is possible the server is
|
||||
# deleted. Try once more using the <server> arg directly if it is a
|
||||
# UUID.
|
||||
if uuidutils.is_uuid_like(parsed_args.server):
|
||||
if is_uuid_like(parsed_args.server):
|
||||
server_id = parsed_args.server
|
||||
else:
|
||||
raise
|
||||
|
@ -10,7 +10,6 @@ iso8601>=0.1.11 # MIT
|
||||
openstacksdk>=1.4.0 # Apache-2.0
|
||||
osc-lib>=2.3.0 # Apache-2.0
|
||||
oslo.i18n>=3.15.3 # Apache-2.0
|
||||
oslo.utils>=3.33.0 # Apache-2.0
|
||||
python-keystoneclient>=3.22.0 # Apache-2.0
|
||||
python-novaclient>=18.1.0 # Apache-2.0
|
||||
python-cinderclient>=3.3.0 # Apache-2.0
|
||||
|
Loading…
x
Reference in New Issue
Block a user