17
17
from oslo_config import cfg
18
from oslo_utils import uuidutils
22
from ironic.common import exception
20
23
from ironic.common.i18n import _
24
from ironic.common import utils
25
from ironic import objects
57
63
if p['path'] == path:
67
def allow_node_logical_names():
68
# v1.5 added logical name aliases
69
return pecan.request.version.minor >= 5
72
def get_rpc_node(node_ident):
73
"""Get the RPC node from the node uuid or logical name.
75
:param node_ident: the UUID or logical name of a node.
77
:returns: The RPC Node.
78
:raises: InvalidUuidOrName if the name or uuid provided is not valid.
79
:raises: NodeNotFound if the node is not found.
81
# Check to see if the node_ident is a valid UUID. If it is, treat it
83
if uuidutils.is_uuid_like(node_ident):
84
return objects.Node.get_by_uuid(pecan.request.context, node_ident)
86
# We can refer to nodes by their name, if the client supports it
87
if allow_node_logical_names():
88
if utils.is_hostname_safe(node_ident):
89
return objects.Node.get_by_name(pecan.request.context, node_ident)
90
raise exception.InvalidUuidOrName(name=node_ident)
92
# Ensure we raise the same exception as we did for the Juno release
93
raise exception.NodeNotFound(node=node_ident)
96
def is_valid_node_name(name):
97
"""Determine if the provided name is a valid node name.
99
Check to see that the provided node name is valid, and isn't a UUID.
101
:param: name: the node name to check.
102
:returns: True if the name is valid, False otherwise.
104
return utils.is_hostname_safe(name) and (not uuidutils.is_uuid_like(name))