~ubuntu-branches/ubuntu/vivid/ironic/vivid-proposed

« back to all changes in this revision

Viewing changes to ironic/api/controllers/v1/utils.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2015-04-17 09:28:31 UTC
  • mfrom: (1.2.7)
  • Revision ID: package-import@ubuntu.com-20150417092831-wu2awfbqomnzpeim
Tags: 2015.1~rc1-0ubuntu1
* New upstream milestone release:
  - d/control: Align with upstream dependencies
  - d/p/fix-requirements.patch: Dropped no longer needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
import jsonpatch
17
17
from oslo_config import cfg
 
18
from oslo_utils import uuidutils
 
19
import pecan
18
20
import wsme
19
21
 
 
22
from ironic.common import exception
20
23
from ironic.common.i18n import _
 
24
from ironic.common import utils
 
25
from ironic import objects
 
26
 
21
27
 
22
28
CONF = cfg.CONF
23
29
 
56
62
    for p in patch:
57
63
        if p['path'] == path:
58
64
            return p['value']
 
65
 
 
66
 
 
67
def allow_node_logical_names():
 
68
    # v1.5 added logical name aliases
 
69
    return pecan.request.version.minor >= 5
 
70
 
 
71
 
 
72
def get_rpc_node(node_ident):
 
73
    """Get the RPC node from the node uuid or logical name.
 
74
 
 
75
    :param node_ident: the UUID or logical name of a node.
 
76
 
 
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.
 
80
    """
 
81
    # Check to see if the node_ident is a valid UUID.  If it is, treat it
 
82
    # as a UUID.
 
83
    if uuidutils.is_uuid_like(node_ident):
 
84
        return objects.Node.get_by_uuid(pecan.request.context, node_ident)
 
85
 
 
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)
 
91
 
 
92
    # Ensure we raise the same exception as we did for the Juno release
 
93
    raise exception.NodeNotFound(node=node_ident)
 
94
 
 
95
 
 
96
def is_valid_node_name(name):
 
97
    """Determine if the provided name is a valid node name.
 
98
 
 
99
    Check to see that the provided node name is valid, and isn't a UUID.
 
100
 
 
101
    :param: name: the node name to check.
 
102
    :returns: True if the name is valid, False otherwise.
 
103
    """
 
104
    return utils.is_hostname_safe(name) and (not uuidutils.is_uuid_like(name))