def test_detail_by_node_name_not_supported(self, mock_get_rpc_node): # GET /v1/ports/detail specifying node_name - name not supported mock_get_rpc_node.side_effect = ( exception.InvalidUuidOrName(name=self.node.uuid)) obj_utils.create_test_port(self.context, node_id=self.node.id) data = self.get_json('/ports/detail?node=%s' % 'test-node', expect_errors=True) self.assertEqual(0, mock_get_rpc_node.call_count) self.assertEqual(http_client.NOT_ACCEPTABLE, data.status_int)
def test_get_all_by_node_name_not_supported(self, mock_get_rpc_node): # GET /v1/ports specifying node_name - name not supported mock_get_rpc_node.side_effect = ( exception.InvalidUuidOrName(name=self.node.uuid)) for i in range(3): obj_utils.create_test_port(self.context, node_id=self.node.id, uuid=uuidutils.generate_uuid(), address='52:54:00:cf:2d:3%s' % i) data = self.get_json("/ports?node=%s" % 'test-node', expect_errors=True) self.assertEqual(0, mock_get_rpc_node.call_count) self.assertEqual(http_client.NOT_ACCEPTABLE, data.status_int)
def get_rpc_portgroup(portgroup_ident): """Get the RPC portgroup from the portgroup UUID or logical name. :param portgroup_ident: the UUID or logical name of a portgroup. :returns: The RPC portgroup. :raises: InvalidUuidOrName if the name or uuid provided is not valid. :raises: PortgroupNotFound if the portgroup is not found. """ # Check to see if the portgroup_ident is a valid UUID. If it is, treat it # as a UUID. if uuidutils.is_uuid_like(portgroup_ident): return objects.Portgroup.get_by_uuid(pecan.request.context, portgroup_ident) # We can refer to portgroups by their name if utils.is_valid_logical_name(portgroup_ident): return objects.Portgroup.get_by_name(pecan.request.context, portgroup_ident) raise exception.InvalidUuidOrName(name=portgroup_ident)
def get_rpc_allocation(allocation_ident): """Get the RPC allocation from the allocation UUID or logical name. :param allocation_ident: the UUID or logical name of an allocation. :returns: The RPC allocation. :raises: InvalidUuidOrName if the name or uuid provided is not valid. :raises: AllocationNotFound if the allocation is not found. """ # Check to see if the allocation_ident is a valid UUID. If it is, treat it # as a UUID. if uuidutils.is_uuid_like(allocation_ident): return objects.Allocation.get_by_uuid(pecan.request.context, allocation_ident) # We can refer to allocations by their name if utils.is_valid_logical_name(allocation_ident): return objects.Allocation.get_by_name(pecan.request.context, allocation_ident) raise exception.InvalidUuidOrName(name=allocation_ident)
def get_rpc_deploy_template(template_ident): """Get the RPC deploy template from the UUID or logical name. :param template_ident: the UUID or logical name of a deploy template. :returns: The RPC deploy template. :raises: InvalidUuidOrName if the name or uuid provided is not valid. :raises: DeployTemplateNotFound if the deploy template is not found. """ # Check to see if the template_ident is a valid UUID. If it is, treat it # as a UUID. if uuidutils.is_uuid_like(template_ident): return objects.DeployTemplate.get_by_uuid(api.request.context, template_ident) # We can refer to templates by their name if utils.is_valid_logical_name(template_ident): return objects.DeployTemplate.get_by_name(api.request.context, template_ident) raise exception.InvalidUuidOrName(name=template_ident)
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 is_valid_logical_name(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)
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)
def validate(value): if not (uuidutils.is_uuid_like(value) or v1_utils.is_valid_logical_name(value)): raise exception.InvalidUuidOrName(name=value) return value