示例#1
0
文件: utils.py 项目: n-nishida/rack
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)
示例#2
0
文件: api.py 项目: n-nishida/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)
示例#3
0
文件: api.py 项目: 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)
示例#4
0
文件: api.py 项目: 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)
示例#5
0
文件: api.py 项目: 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)
示例#6
0
文件: manager.py 项目: n-nishida/rack
    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)
示例#7
0
文件: api.py 项目: n-nishida/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)
示例#8
0
文件: api.py 项目: n-nishida/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)
示例#9
0
文件: api.py 项目: n-nishida/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)
示例#10
0
文件: api.py 项目: 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)
示例#11
0
文件: api.py 项目: n-nishida/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)
示例#12
0
文件: api.py 项目: 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)
示例#13
0
文件: api.py 项目: n-nishida/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)
示例#14
0
文件: api.py 项目: 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)
示例#15
0
文件: api.py 项目: n-nishida/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)
示例#16
0
文件: api.py 项目: 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)
示例#17
0
文件: api.py 项目: n-nishida/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)
示例#18
0
文件: api.py 项目: 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)
示例#19
0
文件: baserpc.py 项目: n-nishida/rack
 def ping(self, context, arg):
     resp = {'service': self.service_name, 'arg': arg}
     return jsonutils.to_primitive(resp)
示例#20
0
文件: baserpc.py 项目: n-nishida/rack
 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)
示例#21
0
文件: rpc.py 项目: n-nishida/rack
 def serialize_entity(context, entity):
     return jsonutils.to_primitive(entity, convert_instances=True)