Example #1
0
def build_request_spec(ctxt, image, instances, instance_type=None):
    """Build a request_spec for the scheduler.

    The request_spec assumes that all instances to be scheduled are the same
    type.
    """
    instance = instances[0]
    if isinstance(instance, instance_obj.Instance):
        instance = obj_base.obj_to_primitive(instance)

    if instance_type is None:
        instance_type = flavors.extract_flavor(instance)
    # NOTE(comstud): This is a bit ugly, but will get cleaned up when
    # we're passing an InstanceType internal object.
    extra_specs = db.flavor_extra_specs_get(ctxt, instance_type['flavorid'])
    instance_type['extra_specs'] = extra_specs
    request_spec = {
        'image': image or {},
        'instance_properties': instance,
        'instance_type': instance_type,
        'num_instances': len(instances),
        # NOTE(alaski): This should be removed as logic moves from the
        # scheduler to conductor.  Provides backwards compatibility now.
        'instance_uuids': [inst['uuid'] for inst in instances]}
    return jsonutils.to_primitive(request_spec)
Example #2
0
def service_get_all_by_host(context, host):
    session = get_session()
    service_refs = service_model_query(context, models.Service,
                                       session=session,
                                       read_deleted="no").\
        filter_by(host=host).\
        all()

    return jsonutils.to_primitive(service_refs)
Example #3
0
File: api.py Project: yanyuge/rack
def service_get_all(context, disabled=None):
    session = get_session()
    query = service_model_query(context, models.Service, session=session)

    if disabled is not None:
        query = query.filter_by(disabled=disabled)

    service_refs = query.all()
    return jsonutils.to_primitive(service_refs)
Example #4
0
File: api.py Project: yanyuge/rack
def service_get_all_by_host(context, host):
    session = get_session()
    service_refs = service_model_query(context, models.Service,
                                       session=session,
                                       read_deleted="no").\
        filter_by(host=host).\
        all()

    return jsonutils.to_primitive(service_refs)
Example #5
0
File: api.py Project: yanyuge/rack
def service_get_all_by_topic(context, topic):
    session = get_session()
    service_refs = service_model_query(context, models.Service,
                                       session=session,
                                       read_deleted="no").\
        filter_by(disabled=False).\
        filter_by(topic=topic).\
        all()

    return jsonutils.to_primitive(service_refs)
Example #6
0
    def select_destinations(self, context, request_spec, filter_properties):
        """Returns destinations(s) best suited for this request_spec and
        filter_properties.

        The result should be a list of dicts with 'host', 'nodename' and
        'limits' as keys.
        """
        dests = self.driver.select_destinations(context, request_spec,
                                                filter_properties)
        return jsonutils.to_primitive(dests)
Example #7
0
def service_get_all(context, disabled=None):
    session = get_session()
    query = service_model_query(context, models.Service,
                                session=session)

    if disabled is not None:
        query = query.filter_by(disabled=disabled)

    service_refs = query.all()
    return jsonutils.to_primitive(service_refs)
Example #8
0
def service_get_all_by_topic(context, topic):
    session = get_session()
    service_refs = service_model_query(context, models.Service,
                                       session=session,
                                       read_deleted="no").\
        filter_by(disabled=False).\
        filter_by(topic=topic).\
        all()

    return jsonutils.to_primitive(service_refs)
Example #9
0
def service_get(context, service_id):
    session = get_session()
    service_ref = service_model_query(context, models.Service,
                                      session=session).\
        filter_by(id=service_id).\
        first()

    if not service_ref:
        raise exception.ServiceNotFound(service_id=service_id)

    return jsonutils.to_primitive(service_ref)
Example #10
0
File: api.py Project: yanyuge/rack
def service_get_by_host_and_topic(context, host, topic):
    session = get_session()
    service_ref = service_model_query(context, models.Service,
                                      session=session,
                                      read_deleted="no").\
        filter_by(disabled=False).\
        filter_by(host=host).\
        filter_by(topic=topic).\
        first()

    return jsonutils.to_primitive(service_ref)
Example #11
0
def service_get_by_host_and_topic(context, host, topic):
    session = get_session()
    service_ref = service_model_query(context, models.Service,
                                      session=session,
                                      read_deleted="no").\
        filter_by(disabled=False).\
        filter_by(host=host).\
        filter_by(topic=topic).\
        first()

    return jsonutils.to_primitive(service_ref)
Example #12
0
File: api.py Project: yanyuge/rack
def service_get(context, service_id):
    session = get_session()
    service_ref = service_model_query(context, models.Service,
                                      session=session).\
        filter_by(id=service_id).\
        first()

    if not service_ref:
        raise exception.ServiceNotFound(service_id=service_id)

    return jsonutils.to_primitive(service_ref)
Example #13
0
def service_get_by_args(context, host, binary):
    session = get_session()
    service_ref = service_model_query(context, models.Service,
                                      session=session).\
        filter_by(host=host).\
        filter_by(binary=binary).\
        first()

    if not service_ref:
        raise exception.HostBinaryNotFound(host=host, binary=binary)

    return jsonutils.to_primitive(service_ref)
Example #14
0
File: api.py Project: yanyuge/rack
def service_get_by_args(context, host, binary):
    session = get_session()
    service_ref = service_model_query(context, models.Service,
                                      session=session).\
        filter_by(host=host).\
        filter_by(binary=binary).\
        first()

    if not service_ref:
        raise exception.HostBinaryNotFound(host=host, binary=binary)

    return jsonutils.to_primitive(service_ref)
Example #15
0
def service_update(context, service_id, values):
    session = get_session()
    with session.begin():
        service_ref = service_model_query(context, models.Service,
                                          session=session).\
            filter_by(id=service_id).\
            first()

        if not service_ref:
            raise exception.ServiceNotFound(service_id=service_id)

        service_ref.update(values)

    return jsonutils.to_primitive(service_ref)
Example #16
0
File: api.py Project: yanyuge/rack
def service_update(context, service_id, values):
    session = get_session()
    with session.begin():
        service_ref = service_model_query(context, models.Service,
                                          session=session).\
            filter_by(id=service_id).\
            first()

        if not service_ref:
            raise exception.ServiceNotFound(service_id=service_id)

        service_ref.update(values)

    return jsonutils.to_primitive(service_ref)
Example #17
0
def service_create(context, values):
    session = get_session()
    service_ref = models.Service()
    service_ref.update(values)
    if not CONF.enable_new_services:
        service_ref.disabled = True
    try:
        service_ref.save(session)
    except db_exc.DBDuplicateEntry as e:
        if 'binary' in e.columns:
            raise exception.ServiceBinaryExists(host=values.get('host'),
                                                binary=values.get('binary'))
        raise exception.ServiceTopicExists(host=values.get('host'),
                                           topic=values.get('topic'))

    return jsonutils.to_primitive(service_ref)
Example #18
0
File: api.py Project: yanyuge/rack
def service_create(context, values):
    session = get_session()
    service_ref = models.Service()
    service_ref.update(values)
    if not CONF.enable_new_services:
        service_ref.disabled = True
    try:
        service_ref.save(session)
    except db_exc.DBDuplicateEntry as e:
        if 'binary' in e.columns:
            raise exception.ServiceBinaryExists(host=values.get('host'),
                                                binary=values.get('binary'))
        raise exception.ServiceTopicExists(host=values.get('host'),
                                           topic=values.get('topic'))

    return jsonutils.to_primitive(service_ref)
Example #19
0
 def ping(self, context, arg):
     resp = {'service': self.service_name, 'arg': arg}
     return jsonutils.to_primitive(resp)
Example #20
0
 def ping(self, context, arg, timeout=None):
     arg_p = jsonutils.to_primitive(arg)
     cctxt = self.client.prepare(timeout=timeout)
     return cctxt.call(context, 'ping', arg=arg_p)
Example #21
0
 def serialize_entity(context, entity):
     return jsonutils.to_primitive(entity, convert_instances=True)