Watcher utils cleanup
As some of our utils function are actually available in oslo.utils, this patchset simply gets rid of our local copy and instead references the oslo.utils one. This will help us deport the code maintenance of these to a 3rd party library. Change-Id: I3760ebab69d35c37bbe78500918d4e46b5bd9119
This commit is contained in:
@@ -16,17 +16,19 @@
|
||||
|
||||
"""Utilities and helper functions."""
|
||||
|
||||
import re
|
||||
|
||||
from jsonschema import validators
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from watcher.common import exception
|
||||
|
||||
import re
|
||||
from oslo_utils import strutils
|
||||
from oslo_utils import timeutils
|
||||
from oslo_utils import uuidutils
|
||||
import six
|
||||
import uuid
|
||||
|
||||
|
||||
from watcher._i18n import _LW
|
||||
from watcher.common import exception
|
||||
|
||||
|
||||
UTILS_OPTS = [
|
||||
cfg.StrOpt('rootwrap_config',
|
||||
@@ -66,6 +68,12 @@ class Struct(dict):
|
||||
raise AttributeError(name)
|
||||
|
||||
|
||||
generate_uuid = uuidutils.generate_uuid
|
||||
is_uuid_like = uuidutils.is_uuid_like
|
||||
is_int_like = strutils.is_int_like
|
||||
strtime = timeutils.strtime
|
||||
|
||||
|
||||
def safe_rstrip(value, chars=None):
|
||||
"""Removes trailing characters from a string if that does not make it empty
|
||||
|
||||
@@ -83,31 +91,6 @@ def safe_rstrip(value, chars=None):
|
||||
return value.rstrip(chars) or value
|
||||
|
||||
|
||||
def generate_uuid():
|
||||
return str(uuid.uuid4())
|
||||
|
||||
|
||||
def is_int_like(val):
|
||||
"""Check if a value looks like an int."""
|
||||
try:
|
||||
return str(int(val)) == str(val)
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
def is_uuid_like(val):
|
||||
"""Returns validation of a value as a UUID.
|
||||
|
||||
For our purposes, a UUID is a canonical form string:
|
||||
aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
|
||||
|
||||
"""
|
||||
try:
|
||||
return str(uuid.UUID(val)) == val
|
||||
except (TypeError, ValueError, AttributeError):
|
||||
return False
|
||||
|
||||
|
||||
def is_hostname_safe(hostname):
|
||||
"""Determine if the supplied hostname is RFC compliant.
|
||||
|
||||
@@ -133,10 +116,6 @@ def get_cls_import_path(cls):
|
||||
return module + '.' + cls.__name__
|
||||
|
||||
|
||||
def strtime(at):
|
||||
return at.strftime("%Y-%m-%dT%H:%M:%S.%f")
|
||||
|
||||
|
||||
# Default value feedback extension as jsonschema doesn't support it
|
||||
def extend_with_default(validator_class):
|
||||
validate_properties = validator_class.VALIDATORS["properties"]
|
||||
|
||||
Reference in New Issue
Block a user