Exemplo n.º 1
0
    def service_get_all(self, context, filters=None, set_zones=False):
        if filters is None:
            filters = {}
        if 'availability_zone' in filters:
            zone_filter = filters.pop('availability_zone')
            set_zones = True
        else:
            zone_filter = None
        services = self.cells_rpcapi.service_get_all(context,
                                                     filters=filters)
        if set_zones:
            services = availability_zones.set_availability_zones(context,
                                                                 services)
            if zone_filter is not None:
                services = [s for s in services
                            if s['availability_zone'] == zone_filter]
        # NOTE(johannes): Cells adds the cell path as a prefix to the id
        # to uniquely identify the service amongst all cells. Unfortunately
        # the object model makes the id an integer. Use a proxy here to
        # work around this particular problem.

        # Split out the cell path first
        cell_paths = []
        for service in services:
            cell_path, id = cells_utils.split_cell_and_item(service['id'])
            service['id'] = id
            cell_paths.append(cell_path)

        # NOTE(danms): Currently cells does not support objects as
        # return values, so just convert the db-formatted service objects
        # to new-world objects here
        services = obj_base.obj_make_list(context,
                                          service_obj.ServiceList(),
                                          service_obj.Service,
                                          services)

        # Now wrap it in the proxy with the original cell_path
        services = [ServiceProxy(s, c) for s, c in zip(services, cell_paths)]
        return services
Exemplo n.º 2
0
 def service_get_all(self, context, filters=None, set_zones=False):
     if filters is None:
         filters = {}
     if 'availability_zone' in filters:
         zone_filter = filters.pop('availability_zone')
         set_zones = True
     else:
         zone_filter = None
     services = self.cells_rpcapi.service_get_all(context, filters=filters)
     if set_zones:
         services = availability_zones.set_availability_zones(
             context, services)
         if zone_filter is not None:
             services = [
                 s for s in services
                 if s['availability_zone'] == zone_filter
             ]
     # NOTE(danms): Currently cells does not support objects as
     # return values, so just convert the db-formatted service objects
     # to new-world objects here
     return obj_base.obj_make_list(context, service_obj.ServiceList(),
                                   service_obj.Service, services)