예제 #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)