Exemple #1
0
    def test_instance_type_get_by_flavor_id_with_extra_specs(self):
        instance_type = db.instance_type_get_by_flavor_id(self.context, 105)
        self.assertEquals(
            instance_type['extra_specs'],
            dict(cpu_arch="x86_64",
                 cpu_model="Nehalem",
                 xpu_arch="fermi",
                 xpus="2",
                 xpu_model="Tesla 2050"))

        instance_type = db.instance_type_get_by_flavor_id(self.context, 2)
        self.assertEquals(instance_type['extra_specs'], {})
    def test_instance_type_get_by_flavor_id_with_extra_specs(self):
        instance_type = db.instance_type_get_by_flavor_id(
                            self.context,
                            105)
        self.assertEquals(instance_type['extra_specs'],
                          dict(cpu_arch="x86_64",
                               cpu_model="Nehalem",
                               xpu_arch="fermi",
                               xpus="2",
                               xpu_model="Tesla 2050"))

        instance_type = db.instance_type_get_by_flavor_id(
                            self.context,
                            2)
        self.assertEquals(instance_type['extra_specs'], {})
Exemple #3
0
def get_instance_type_by_flavor_id(flavorid):
    """Retrieve instance type by flavorid."""
    ctxt = context.get_admin_context()
    try:
        return db.instance_type_get_by_flavor_id(ctxt, flavorid)
    except exception.DBError:
        raise exception.ApiError(_("Unknown instance type: %s") % flavorid)
Exemple #4
0
def get_instance_type_by_flavor_id(flavor_id):
    """Retrieve instance type by flavor_id."""
    ctxt = context.get_admin_context()
    try:
        return db.instance_type_get_by_flavor_id(ctxt, flavor_id)
    except ValueError:
        raise exception.FlavorNotFound(flavor_id=flavor_id)
Exemple #5
0
def get_instance_type_by_flavor_id(flavorid):
    """Retrieve instance type by flavorid."""
    ctxt = context.get_admin_context()
    try:
        return db.instance_type_get_by_flavor_id(ctxt, flavorid)
    except exception.DBError:
        raise exception.ApiError(_("Unknown instance type: %s") % flavorid)
Exemple #6
0
def get_instance_type_by_flavor_id(flavor_id):
    """Retrieve instance type by flavor_id."""
    ctxt = context.get_admin_context()
    try:
        return db.instance_type_get_by_flavor_id(ctxt, flavor_id)
    except ValueError:
        raise exception.FlavorNotFound(flavor_id=flavor_id)
Exemple #7
0
def get_instance_type_by_flavor_id(flavorid):
    """Retrieve instance type by flavorid.

    :raises: FlavorNotFound
    """
    ctxt = context.get_admin_context(read_deleted="yes")
    return db.instance_type_get_by_flavor_id(ctxt, flavorid)
Exemple #8
0
def get_instance_type_by_flavor_id(flavorid, read_deleted="yes"):
    """Retrieve instance type by flavorid.

    :raises: FlavorNotFound
    """
    ctxt = context.get_admin_context(read_deleted=read_deleted)
    return db.instance_type_get_by_flavor_id(ctxt, flavorid)
Exemple #9
0
    def test_update_flavor_not_found(self):
        req = webob.Request.blank(
                 '/v2/{tenant_id}/servers/{server-id}/network-qos/public')
        req.method = 'PUT'
        req.headers['content-type'] = 'application/json'
        req.environ['nova.context'] = self.context
        body = {'rate': 1, 'flavor_id': 99999999}

        #flavor_id=body.get('flavor_id',None)
        self.mox.StubOutWithMock(db, 'instance_type_get_by_flavor_id')
        db.instance_type_get_by_flavor_id(
            req.environ['nova.context'], mox.IgnoreArg()).\
            AndRaise(exception.FlavorNotFound)
        self.mox.ReplayAll()

        self.assertRaises(exc.HTTPBadRequest,
                                self.controller.update,
                                req, '123', 'public', body)
Exemple #10
0
def get_flavor_by_flavor_id(flavorid, ctxt=None, read_deleted="yes"):
    """Retrieve flavor by flavorid.

    :raises: FlavorNotFound
    """
    if ctxt is None:
        ctxt = context.get_admin_context(read_deleted=read_deleted)

    return db.instance_type_get_by_flavor_id(ctxt, flavorid, read_deleted)
Exemple #11
0
def get_flavor_by_flavor_id(flavorid, ctxt=None, read_deleted="yes"):
    """Retrieve flavor by flavorid.

    :raises: FlavorNotFound
    """
    if ctxt is None:
        ctxt = context.get_admin_context(read_deleted=read_deleted)

    return db.instance_type_get_by_flavor_id(ctxt, flavorid, read_deleted)
Exemple #12
0
def get_instance_type_by_flavor_id(flavor_id):
    """Retrieve instance type by flavor_id."""
    if flavor_id is None:
        return get_default_instance_type()
    try:
        ctxt = context.get_admin_context()
        return db.instance_type_get_by_flavor_id(ctxt, flavor_id)
    except exception.DBError, e:
        LOG.exception(_("DB error: %s") % e)
        raise exception.ApiError(_("Unknown flavor: %s") % flavor_id)
Exemple #13
0
def get_instance_type_by_flavor_id(flavor_id):
    """Retrieve instance type by flavor_id."""
    if flavor_id is None:
        return get_default_instance_type()
    try:
        ctxt = context.get_admin_context()
        return db.instance_type_get_by_flavor_id(ctxt, flavor_id)
    except exception.DBError, e:
        LOG.exception(_('DB error: %s') % e)
        raise exception.ApiError(_("Unknown flavor: %s") % flavor_id)
Exemple #14
0
    def update(self, req, server_id, id, body=None):
        """Update a network qos.

        PUT /v2/{tenant_id}/servers/{server-id}/network-qos/public
        PUT /v2/{tenant_id}/servers/{server-id}/network-qos/private
        """
        context = req.environ['nova.context']
        authorize(context, action='update')

        qos_type = id
        if qos_type not in ('private', 'public'):
            raise exc.HTTPNotFound()

        # only admin could modify private network qos settings
        if qos_type == 'private':
            if not context.is_admin:
                raise webob.exc.HTTPForbidden()

        if not body:
            raise exc.HTTPUnprocessableEntity()

        try:
            instance = self.compute_api.get(context, server_id)
        except exception.NotFound:
            raise exc.HTTPNotFound()

        spec = self._check_qos_format(body)

        flavor_id = body.get('flavor_id', None)
        if flavor_id:
            try:
                db.instance_type_get_by_flavor_id(context, flavor_id)
            except exception.FlavorNotFound:
                msg = _("flavor %s not found") % flavor_id
                raise exc.HTTPBadRequest(explanation=msg)

        try:
            self.network_api.modify_network_qos(context, instance['id'],
                                                qos_type, spec, flavor_id)
        except exception.TcInvalid, e:
            msg = e.kwargs.get('err')
            raise exc.HTTPBadRequest(explanation=str(msg))
Exemple #15
0
    def update(self, req, server_id, id, body=None):
        """Update a network qos.

        PUT /v2/{tenant_id}/servers/{server-id}/network-qos/public
        PUT /v2/{tenant_id}/servers/{server-id}/network-qos/private
        """
        context = req.environ['nova.context']
        authorize(context, action='update')

        qos_type = id
        if qos_type not in ('private', 'public'):
            raise exc.HTTPNotFound()

        # only admin could modify private network qos settings
        if qos_type == 'private':
            if not context.is_admin:
                raise webob.exc.HTTPForbidden()

        if not body:
            raise exc.HTTPUnprocessableEntity()

        try:
            instance = self.compute_api.get(context, server_id)
        except exception.NotFound:
            raise exc.HTTPNotFound()

        spec = self._check_qos_format(body)

        flavor_id = body.get('flavor_id', None)
        if flavor_id:
            try:
                db.instance_type_get_by_flavor_id(context, flavor_id)
            except exception.FlavorNotFound:
                msg = _("flavor %s not found") % flavor_id
                raise exc.HTTPBadRequest(explanation=msg)

        try:
            self.network_api.modify_network_qos(context, instance['id'],
                                                qos_type, spec, flavor_id)
        except exception.TcInvalid, e:
            msg = e.kwargs.get('err')
            raise exc.HTTPBadRequest(explanation=str(msg))
Exemple #16
0
def get_by_flavor_id(flavor_id):
    """retrieve instance type's name by flavor_id"""
    if flavor_id is None:
        return FLAGS.default_instance_type
    try:
        ctxt = context.get_admin_context()
        flavor = db.instance_type_get_by_flavor_id(ctxt, flavor_id)
        return flavor['name']
    except exception.DBError, e:
        LOG.exception(_('DB error: %s' % e))
        raise exception.ApiError(_("Unknown flavor: %s" % flavor_id))
Exemple #17
0
def get_by_flavor_id(flavor_id):
    """retrieve instance type's name by flavor_id"""
    if flavor_id is None:
        return FLAGS.default_instance_type
    try:
        ctxt = context.get_admin_context()
        flavor = db.instance_type_get_by_flavor_id(ctxt, flavor_id)
        return flavor['name']
    except exception.DBError, e:
        LOG.exception(_('DB error: %s' % e))
        raise exception.ApiError(_("Unknown flavor: %s" % flavor_id))
Exemple #18
0
    def _schedule(self, context, topic, request_spec, filter_properties,
                  instance_uuids=None):
        """Returns a list of hosts that meet the required specs,
        ordered by their fitness.
        """
        elevated = context.elevated()
        if topic != "compute":
            msg = _("Scheduler only understands Compute nodes (for now)")
            raise NotImplementedError(msg)

        instance_properties = request_spec['instance_properties']
        instance_type = request_spec.get("instance_type", None)

        # Note(gtt): Make sure "extra_specs" in instance_type dict object.
        # Since db.instance_type_get_by_flavor_id will change the type of
        # extra_specs to dict, so no matter if "instance_type" is exists,
        # update it with new from db.
        if instance_type is not None:
            try:
                instance_type = db.instance_type_get_by_flavor_id(
                    context, instance_type.get('flavorid'))
            except exception.FlavorNotFound:
                LOG.warn("flavorid not in instance_type. instance_type: %s" %
                         instance_type)
            else:
                request_spec.update({"instance_type": instance_type})

        cost_functions = self.get_cost_functions()
        config_options = self._get_configuration_options()

        # check retry policy.  Rather ugly use of instance_uuids[0]...
        # but if we've exceeded max retries... then we really only
        # have a single instance.
        properties = instance_properties.copy()
        if instance_uuids:
            properties['uuid'] = instance_uuids[0]
        self._populate_retry(filter_properties, properties)

        filter_properties.update({'context': context,
                                  'request_spec': request_spec,
                                  'config_options': config_options,
                                  'instance_type': instance_type})

        self.populate_filter_properties(request_spec,
                                        filter_properties)

        # Find our local list of acceptable hosts by repeatedly
        # filtering and weighing our options. Each time we choose a
        # host, we virtually consume resources on it so subsequent
        # selections can adjust accordingly.

        # unfiltered_hosts_dict is {host : ZoneManager.HostInfo()}
        unfiltered_hosts_dict = self.host_manager.get_all_host_states(
                elevated, topic)

        # Note: remember, we are using an iterator here. So only
        # traverse this list once. This can bite you if the hosts
        # are being scanned in a filter or weighing function.
        hosts = unfiltered_hosts_dict.itervalues()

        selected_hosts = []
        if instance_uuids:
            num_instances = len(instance_uuids)
        else:
            num_instances = request_spec.get('num_instances', 1)
        for num in xrange(num_instances):
            # Filter local hosts based on requirements ...
            if FLAGS.use_network_qos:
                if instance_uuids:
                    inst_uuid = instance_uuids[num]
                else:
                    inst_uuid = None
                qos_info = resource_tracker.get_instance_network_qos(
                                            instance_type, inst_uuid)
                instance_properties['private_network_bandwith'] =\
                                                  qos_info['private_qos']
                instance_properties['public_network_bandwith'] =\
                                                  qos_info['public_qos']
                filter_properties.update({'private_network_bandwith':
                                           qos_info['private_qos'],
                                          'public_network_bandwith':
                                           qos_info['public_qos']
                                         })

            hosts = self.host_manager.filter_hosts(hosts,
                    filter_properties)
            if not hosts:
                # Can't get any more locally.
                break

            LOG.debug(_("Filtered %(hosts)s") % locals())

            # weighted_host = WeightedHost() ... the best
            # host for the job.
            # TODO(comstud): filter_properties will also be used for
            # weighing and I plan fold weighing into the host manager
            # in a future patch.  I'll address the naming of this
            # variable at that time.
            weighted_host = least_cost.weighted_sum(cost_functions,
                    hosts, filter_properties)
            LOG.debug(_("Weighted %(weighted_host)s") % locals())
            selected_hosts.append(weighted_host)

            # Now consume the resources so the filter/weights
            # will change for the next instance.
            weighted_host.host_state.consume_from_instance(
                    instance_properties, instance_type)

        selected_hosts.sort(key=operator.attrgetter('weight'))
        return selected_hosts
Exemple #19
0
 def show(self, req, id):
     """Return data about the given flavor id."""
     ctxt = req.environ['nova.context']
     values = db.instance_type_get_by_flavor_id(ctxt, id)
     return dict(flavor=values)
     raise faults.Fault(exc.HTTPNotFound())