Beispiel #1
0
def is_valid_node_name(name):
    """Determine if the provided name is a valid node name.

    Check to see that the provided node name is valid, and isn't a UUID.

    :param: name: the node name to check.
    :returns: True if the name is valid, False otherwise.
    """
    return utils.is_hostname_safe(name) and (not uuidutils.is_uuid_like(name))
Beispiel #2
0
def _get_rpc_node(node_ident):
    """Get the RPC node from the node uuid or logical name.

    :param node_ident: the UUID or logical name of a node.

    :returns: The RPC Node.
    :raises: InvalidUuidOrName if the name or uuid provided is not valid.
    :raises: NodeNotFound if the node is not found.

    """
    # Check to see if the node_ident is a valid UUID.  If it is, treat it
    # as a UUID.
    if uuidutils.is_uuid_like(node_ident):
        return objects.Node.get_by_uuid(pecan.request.context, node_ident)

    # If it was not UUID-like, but it is name-like, and we allow names,
    # check for nodes by that name
    if allow_logical_names() and utils.is_hostname_safe(node_ident):
        return objects.Node.get_by_name(pecan.request.context, node_ident)

    # It's not a valid uuid, or it's not a valid name, or we don't allow names
    raise exception.InvalidUuidOrName(name=node_ident)
Beispiel #3
0
def get_rpc_node(node_ident):
    """Get the RPC node from the node uuid or logical name.

    :param node_ident: the UUID or logical name of a node.

    :returns: The RPC Node.
    :raises: InvalidUuidOrName if the name or uuid provided is not valid.
    :raises: NodeNotFound if the node is not found.
    """
    # Check to see if the node_ident is a valid UUID.  If it is, treat it
    # as a UUID.
    if uuidutils.is_uuid_like(node_ident):
        return objects.Node.get_by_uuid(pecan.request.context, node_ident)

    # We can refer to nodes by their name, if the client supports it
    if allow_node_logical_names():
        if utils.is_hostname_safe(node_ident):
            return objects.Node.get_by_name(pecan.request.context, node_ident)
        raise exception.InvalidUuidOrName(name=node_ident)

    # Ensure we raise the same exception as we did for the Juno release
    raise exception.NodeNotFound(node=node_ident)
Beispiel #4
0
def _get_rpc_node(node_ident):
    """Get the RPC node from the node uuid or logical name.

    :param node_ident: the UUID or logical name of a node.

    :returns: The RPC Node.
    :raises: InvalidUuidOrName if the name or uuid provided is not valid.
    :raises: NodeNotFound if the node is not found.

    """
    # Check to see if the node_ident is a valid UUID.  If it is, treat it
    # as a UUID.
    if utils.is_uuid_like(node_ident):
        return objects.Node.get_by_uuid(pecan.request.context, node_ident)

    # If it was not UUID-like, but it is name-like, and we allow names,
    # check for nodes by that name
    if allow_logical_names() and utils.is_hostname_safe(node_ident):
        return objects.Node.get_by_name(pecan.request.context, node_ident)

    # It's not a valid uuid, or it's not a valid name, or we don't allow names
    raise exception.InvalidUuidOrName(name=node_ident)
Beispiel #5
0
 def validate(value):
     if not (uuidutils.is_uuid_like(value)
             or utils.is_hostname_safe(value)):
         raise exception.InvalidUuidOrName(name=value)
     return value
Beispiel #6
0
 def test_is_hostname_safe(self):
     self.assertTrue(utils.is_hostname_safe('spam'))
     self.assertFalse(utils.is_hostname_safe('spAm'))
     self.assertFalse(utils.is_hostname_safe('SPAM'))
     self.assertFalse(utils.is_hostname_safe('-spam'))
     self.assertFalse(utils.is_hostname_safe('spam-'))
     self.assertTrue(utils.is_hostname_safe('spam-eggs'))
     self.assertFalse(utils.is_hostname_safe('spam_eggs'))
     self.assertFalse(utils.is_hostname_safe('spam eggs'))
     self.assertTrue(utils.is_hostname_safe('spam.eggs'))
     self.assertTrue(utils.is_hostname_safe('9spam'))
     self.assertTrue(utils.is_hostname_safe('spam7'))
     self.assertTrue(utils.is_hostname_safe('br34kf4st'))
     self.assertFalse(utils.is_hostname_safe('$pam'))
     self.assertFalse(utils.is_hostname_safe('egg$'))
     self.assertFalse(utils.is_hostname_safe('spam#eggs'))
     self.assertFalse(utils.is_hostname_safe(' eggs'))
     self.assertFalse(utils.is_hostname_safe('spam '))
     self.assertTrue(utils.is_hostname_safe('s'))
     self.assertTrue(utils.is_hostname_safe('s' * 63))
     self.assertFalse(utils.is_hostname_safe('s' * 64))
     self.assertFalse(utils.is_hostname_safe(''))
     self.assertFalse(utils.is_hostname_safe(None))
     # Need to ensure a binary response for success or fail
     self.assertIsNotNone(utils.is_hostname_safe('spam'))
     self.assertIsNotNone(utils.is_hostname_safe('-spam'))
     self.assertTrue(utils.is_hostname_safe('www.rackspace.com'))
     self.assertTrue(utils.is_hostname_safe('www.rackspace.com.'))
     self.assertTrue(utils.is_hostname_safe('http._sctp.www.example.com'))
     self.assertTrue(utils.is_hostname_safe('mail.pets_r_us.net'))
     self.assertTrue(utils.is_hostname_safe('mail-server-15.my_host.org'))
     self.assertFalse(utils.is_hostname_safe('www.nothere.com_'))
     self.assertFalse(utils.is_hostname_safe('www.nothere_.com'))
     self.assertFalse(utils.is_hostname_safe('www..nothere.com'))
     long_str = 'a' * 63 + '.' + 'b' * 63 + '.' + 'c' * 63 + '.' + 'd' * 63
     self.assertTrue(utils.is_hostname_safe(long_str))
     self.assertFalse(utils.is_hostname_safe(long_str + '.'))
     self.assertFalse(utils.is_hostname_safe('a' * 255))
Beispiel #7
0
def is_valid_logical_name(name):
    """Determine if the provided name is a valid hostname."""
    if pecan.request.version.minor < versions.MINOR_10_UNRESTRICTED_NODE_NAME:
        return utils.is_hostname_safe(name)
    else:
        return utils.is_valid_logical_name(name)
Beispiel #8
0
 def test_is_hostname_safe(self):
     self.assertTrue(utils.is_hostname_safe('spam'))
     self.assertFalse(utils.is_hostname_safe('spAm'))
     self.assertFalse(utils.is_hostname_safe('SPAM'))
     self.assertFalse(utils.is_hostname_safe('-spam'))
     self.assertFalse(utils.is_hostname_safe('spam-'))
     self.assertTrue(utils.is_hostname_safe('spam-eggs'))
     self.assertFalse(utils.is_hostname_safe('spam_eggs'))
     self.assertFalse(utils.is_hostname_safe('spam eggs'))
     self.assertTrue(utils.is_hostname_safe('spam.eggs'))
     self.assertTrue(utils.is_hostname_safe('9spam'))
     self.assertTrue(utils.is_hostname_safe('spam7'))
     self.assertTrue(utils.is_hostname_safe('br34kf4st'))
     self.assertFalse(utils.is_hostname_safe('$pam'))
     self.assertFalse(utils.is_hostname_safe('egg$'))
     self.assertFalse(utils.is_hostname_safe('spam#eggs'))
     self.assertFalse(utils.is_hostname_safe(' eggs'))
     self.assertFalse(utils.is_hostname_safe('spam '))
     self.assertTrue(utils.is_hostname_safe('s'))
     self.assertTrue(utils.is_hostname_safe('s' * 63))
     self.assertFalse(utils.is_hostname_safe('s' * 64))
     self.assertFalse(utils.is_hostname_safe(''))
     self.assertFalse(utils.is_hostname_safe(None))
     # Need to ensure a binary response for success or fail
     self.assertIsNotNone(utils.is_hostname_safe('spam'))
     self.assertIsNotNone(utils.is_hostname_safe('-spam'))
     self.assertTrue(utils.is_hostname_safe('www.rackspace.com'))
     self.assertTrue(utils.is_hostname_safe('www.rackspace.com.'))
     self.assertTrue(utils.is_hostname_safe('http._sctp.www.example.com'))
     self.assertTrue(utils.is_hostname_safe('mail.pets_r_us.net'))
     self.assertTrue(utils.is_hostname_safe('mail-server-15.my_host.org'))
     self.assertFalse(utils.is_hostname_safe('www.nothere.com_'))
     self.assertFalse(utils.is_hostname_safe('www.nothere_.com'))
     self.assertFalse(utils.is_hostname_safe('www..nothere.com'))
     long_str = 'a' * 63 + '.' + 'b' * 63 + '.' + 'c' * 63 + '.' + 'd' * 63
     self.assertTrue(utils.is_hostname_safe(long_str))
     self.assertFalse(utils.is_hostname_safe(long_str + '.'))
     self.assertFalse(utils.is_hostname_safe('a' * 255))
Beispiel #9
0
def is_valid_logical_name(name):
    """Determine if the provided name is a valid hostname."""
    if pecan.request.version.minor < 10:
        return utils.is_hostname_safe(name)
    else:
        return utils.is_valid_logical_name(name)
Beispiel #10
0
 def test_is_hostname_safe(self):
     self.assertTrue(utils.is_hostname_safe("spam"))
     self.assertFalse(utils.is_hostname_safe("spAm"))
     self.assertFalse(utils.is_hostname_safe("SPAM"))
     self.assertFalse(utils.is_hostname_safe("-spam"))
     self.assertFalse(utils.is_hostname_safe("spam-"))
     self.assertTrue(utils.is_hostname_safe("spam-eggs"))
     self.assertFalse(utils.is_hostname_safe("spam_eggs"))
     self.assertFalse(utils.is_hostname_safe("spam eggs"))
     self.assertTrue(utils.is_hostname_safe("spam.eggs"))
     self.assertTrue(utils.is_hostname_safe("9spam"))
     self.assertTrue(utils.is_hostname_safe("spam7"))
     self.assertTrue(utils.is_hostname_safe("br34kf4st"))
     self.assertFalse(utils.is_hostname_safe("$pam"))
     self.assertFalse(utils.is_hostname_safe("egg$"))
     self.assertFalse(utils.is_hostname_safe("spam#eggs"))
     self.assertFalse(utils.is_hostname_safe(" eggs"))
     self.assertFalse(utils.is_hostname_safe("spam "))
     self.assertTrue(utils.is_hostname_safe("s"))
     self.assertTrue(utils.is_hostname_safe("s" * 63))
     self.assertFalse(utils.is_hostname_safe("s" * 64))
     self.assertFalse(utils.is_hostname_safe(""))
     self.assertFalse(utils.is_hostname_safe(None))
     # Need to ensure a binary response for success or fail
     self.assertIsNotNone(utils.is_hostname_safe("spam"))
     self.assertIsNotNone(utils.is_hostname_safe("-spam"))
     self.assertTrue(utils.is_hostname_safe("www.rackspace.com"))
     self.assertTrue(utils.is_hostname_safe("www.rackspace.com."))
     self.assertTrue(utils.is_hostname_safe("http._sctp.www.example.com"))
     self.assertTrue(utils.is_hostname_safe("mail.pets_r_us.net"))
     self.assertTrue(utils.is_hostname_safe("mail-server-15.my_host.org"))
     self.assertFalse(utils.is_hostname_safe("www.nothere.com_"))
     self.assertFalse(utils.is_hostname_safe("www.nothere_.com"))
     self.assertFalse(utils.is_hostname_safe("www..nothere.com"))
     long_str = "a" * 63 + "." + "b" * 63 + "." + "c" * 63 + "." + "d" * 63
     self.assertTrue(utils.is_hostname_safe(long_str))
     self.assertFalse(utils.is_hostname_safe(long_str + "."))
     self.assertFalse(utils.is_hostname_safe("a" * 255))
Beispiel #11
0
 def test_is_hostname_safe(self):
     self.assertTrue(utils.is_hostname_safe('spam'))
     self.assertFalse(utils.is_hostname_safe('spAm'))
     self.assertFalse(utils.is_hostname_safe('SPAM'))
     self.assertFalse(utils.is_hostname_safe('-spam'))
     self.assertFalse(utils.is_hostname_safe('spam-'))
     self.assertTrue(utils.is_hostname_safe('spam-eggs'))
     self.assertFalse(utils.is_hostname_safe('spam eggs'))
     self.assertTrue(utils.is_hostname_safe('9spam'))
     self.assertTrue(utils.is_hostname_safe('spam7'))
     self.assertTrue(utils.is_hostname_safe('br34kf4st'))
     self.assertFalse(utils.is_hostname_safe('$pam'))
     self.assertFalse(utils.is_hostname_safe('egg$'))
     self.assertFalse(utils.is_hostname_safe('spam#eggs'))
     self.assertFalse(utils.is_hostname_safe(' eggs'))
     self.assertFalse(utils.is_hostname_safe('spam '))
     self.assertTrue(utils.is_hostname_safe('s'))
     self.assertTrue(utils.is_hostname_safe('s' * 63))
     self.assertFalse(utils.is_hostname_safe('s' * 64))
     self.assertFalse(utils.is_hostname_safe(''))
     self.assertFalse(utils.is_hostname_safe(None))
     # Need to ensure a binary response for success or fail
     self.assertIsNotNone(utils.is_hostname_safe('spam'))
     self.assertIsNotNone(utils.is_hostname_safe('-spam'))
Beispiel #12
0
 def test_is_hostname_safe(self):
     self.assertTrue(utils.is_hostname_safe('spam'))
     self.assertFalse(utils.is_hostname_safe('spAm'))
     self.assertFalse(utils.is_hostname_safe('SPAM'))
     self.assertFalse(utils.is_hostname_safe('-spam'))
     self.assertFalse(utils.is_hostname_safe('spam-'))
     self.assertTrue(utils.is_hostname_safe('spam-eggs'))
     self.assertFalse(utils.is_hostname_safe('spam eggs'))
     self.assertTrue(utils.is_hostname_safe('9spam'))
     self.assertTrue(utils.is_hostname_safe('spam7'))
     self.assertTrue(utils.is_hostname_safe('br34kf4st'))
     self.assertFalse(utils.is_hostname_safe('$pam'))
     self.assertFalse(utils.is_hostname_safe('egg$'))
     self.assertFalse(utils.is_hostname_safe('spam#eggs'))
     self.assertFalse(utils.is_hostname_safe(' eggs'))
     self.assertFalse(utils.is_hostname_safe('spam '))
     self.assertTrue(utils.is_hostname_safe('s'))
     self.assertTrue(utils.is_hostname_safe('s' * 63))
     self.assertFalse(utils.is_hostname_safe('s' * 64))
     self.assertFalse(utils.is_hostname_safe(''))
     self.assertFalse(utils.is_hostname_safe(None))
     # Need to ensure a binary response for success or fail
     self.assertIsNotNone(utils.is_hostname_safe('spam'))
     self.assertIsNotNone(utils.is_hostname_safe('-spam'))
Beispiel #13
0
def is_valid_name(name):
    return utils.is_hostname_safe(name) and (not uuidutils.is_uuid_like(name))
Beispiel #14
0
 def validate(value):
     if not utils.is_hostname_safe(value):
         raise exception.InvalidName(name=value)
     return value
Beispiel #15
0
def is_valid_logical_name(name):
    """Determine if the provided name is a valid hostname."""
    if pecan.request.version.minor < 10:
        return utils.is_hostname_safe(name)
    else:
        return utils.is_valid_logical_name(name)
Beispiel #16
0
def is_valid_logical_name(name):
    """Determine if the provided name is a valid hostname."""
    if pecan.request.version.minor < versions.MINOR_10_UNRESTRICTED_NODE_NAME:
        return utils.is_hostname_safe(name)
    else:
        return utils.is_valid_logical_name(name)
Beispiel #17
0
def is_valid_name(name):
    return utils.is_hostname_safe(name) and (not utils.is_uuid_like(name))