def test_request_id(self):
     serializer = wsgi.ResponseHeadersSerializer()
     context = engine.context.get_admin_context()
     req = webob.Request.blank('/', environ={'engine.context': context})
     res = webob.Response(request=req)
     serializer.serialize(res, {}, 'foo')
     self.assertTrue(
         utils.is_uuid_like(res.headers['X-Compute-Request-Id']))
Beispiel #2
0
 def test_request_id(self):
     serializer = wsgi.ResponseHeadersSerializer()
     context = engine.context.get_admin_context()
     req = webob.Request.blank('/', environ={'engine.context': context})
     res = webob.Response(request=req)
     serializer.serialize(res, {}, 'foo')
     self.assertTrue(utils.is_uuid_like(
         res.headers['X-Compute-Request-Id']))
Beispiel #3
0
        def wrapped_f(*args, **kwargs):
            collection, context, item_id_or_uuid = self.get_collection_context_and_id(args, kwargs)

            attempt_reroute = False
            if utils.is_uuid_like(item_id_or_uuid):
                item_uuid = item_id_or_uuid
                try:
                    instance = db.instance_get_by_uuid(context, item_uuid)
                except exception.InstanceNotFound, e:
                    # NOTE(sirp): since a UUID was passed in, we can attempt
                    # to reroute to a child zone
                    attempt_reroute = True
                    LOG.debug(_("Instance %(item_uuid)s not found " "locally: '%(e)s'" % locals()))
                else:
                    # NOTE(sirp): since we're not re-routing in this case, and
                    # we we were passed a UUID, we need to replace that UUID
                    # with an integer ID in the argument list so that the
                    # zone-local code can continue to use integer IDs.
                    item_id = instance["id"]
                    args = list(args)  # needs to be mutable to replace
                    self.replace_uuid_with_id(args, kwargs, item_id)
Beispiel #4
0
    def _get_requested_networks(self, requested_networks):
        """
        Create a list of requested networks from the networks attribute
        """
        networks = []
        for network in requested_networks:
            try:
                network_uuid = network['uuid']

                if not utils.is_uuid_like(network_uuid):
                    msg = _("Bad networks format: network uuid is not in"
                            " proper format (%s)") % network_uuid
                    raise exc.HTTPBadRequest(explanation=msg)

                #fixed IP address is optional
                #if the fixed IP address is not provided then
                #it will use one of the available IP address from the network
                address = network.get('fixed_ip', None)
                if address is not None and not utils.is_valid_ipv4(address):
                    msg = _("Invalid fixed IP address (%s)") % address
                    raise exc.HTTPBadRequest(explanation=msg)
                # check if the network id is already present in the list,
                # we don't want duplicate networks to be passed
                # at the boot time
                for id, ip in networks:
                    if id == network_uuid:
                        expl = _("Duplicate networks (%s) are not allowed")\
                                % network_uuid
                        raise exc.HTTPBadRequest(explanation=expl)

                networks.append((network_uuid, address))
            except KeyError as key:
                expl = _('Bad network format: missing %s') % key
                raise exc.HTTPBadRequest(explanation=expl)
            except TypeError:
                expl = _('Bad networks format')
                raise exc.HTTPBadRequest(explanation=expl)

        return networks
Beispiel #5
0
    def _get_requested_networks(self, requested_networks):
        """
        Create a list of requested networks from the networks attribute
        """
        networks = []
        for network in requested_networks:
            try:
                network_uuid = network['uuid']

                if not utils.is_uuid_like(network_uuid):
                    msg = _("Bad networks format: network uuid is not in"
                         " proper format (%s)") % network_uuid
                    raise exc.HTTPBadRequest(explanation=msg)

                #fixed IP address is optional
                #if the fixed IP address is not provided then
                #it will use one of the available IP address from the network
                address = network.get('fixed_ip', None)
                if address is not None and not utils.is_valid_ipv4(address):
                    msg = _("Invalid fixed IP address (%s)") % address
                    raise exc.HTTPBadRequest(explanation=msg)
                # check if the network id is already present in the list,
                # we don't want duplicate networks to be passed
                # at the boot time
                for id, ip in networks:
                    if id == network_uuid:
                        expl = _("Duplicate networks (%s) are not allowed")\
                                % network_uuid
                        raise exc.HTTPBadRequest(explanation=expl)

                networks.append((network_uuid, address))
            except KeyError as key:
                expl = _('Bad network format: missing %s') % key
                raise exc.HTTPBadRequest(explanation=expl)
            except TypeError:
                expl = _('Bad networks format')
                raise exc.HTTPBadRequest(explanation=expl)

        return networks
Beispiel #6
0
        def wrapped_f(*args, **kwargs):
            collection, context, item_id_or_uuid = \
                            self.get_collection_context_and_id(args, kwargs)

            attempt_reroute = False
            if utils.is_uuid_like(item_id_or_uuid):
                item_uuid = item_id_or_uuid
                try:
                    instance = db.instance_get_by_uuid(context, item_uuid)
                except exception.InstanceNotFound, e:
                    # NOTE(sirp): since a UUID was passed in, we can attempt
                    # to reroute to a child zone
                    attempt_reroute = True
                    LOG.debug(
                        _("Instance %(item_uuid)s not found "
                          "locally: '%(e)s'" % locals()))
                else:
                    # NOTE(sirp): since we're not re-routing in this case, and
                    # we we were passed a UUID, we need to replace that UUID
                    # with an integer ID in the argument list so that the
                    # zone-local code can continue to use integer IDs.
                    item_id = instance['id']
                    args = list(args)  # needs to be mutable to replace
                    self.replace_uuid_with_id(args, kwargs, item_id)
Beispiel #7
0
 def _get_instance(self, context, instance_id):
     if utils.is_uuid_like(instance_id):
         instance = self.db.instance_get_by_uuid(context, instance_id)
     else:
         instance = self.db.instance_get(context, instance_id)
     return instance
Beispiel #8
0
 def _translate_uuid_if_necessary(self, context, instance_id):
     if utils.is_uuid_like(instance_id):
         instance = self.db.instance_get_by_uuid(context, instance_id)
         instance_id = instance['id']
     return instance_id
Beispiel #9
0
 def _get_instance(self, context, instance_id):
     if utils.is_uuid_like(instance_id):
         instance = self.db.instance_get_by_uuid(context, instance_id)
     else:
         instance = self.db.instance_get(context, instance_id)
     return instance
Beispiel #10
0
 def _translate_uuid_if_necessary(self, context, instance_id):
     if utils.is_uuid_like(instance_id):
         instance = self.db.instance_get_by_uuid(context, instance_id)
         instance_id = instance['id']
     return instance_id
 def assertUUIDLike(self, val, expected):
     result = utils.is_uuid_like(val)
     self.assertEqual(result, expected)
Beispiel #12
0
 def assertUUIDLike(self, val, expected):
     result = utils.is_uuid_like(val)
     self.assertEqual(result, expected)