Ejemplo n.º 1
0
    def _list(self, request):
        # Get data needed for filtering
        list_filter = {}

        if 'pool' in request.GET:
            try:
                pool_id = int(request.GET['pool'])
            except ValueError:
                return Response("Pool ID must be an integer",
                                status=status.HTTP_400_BAD_REQUEST)
            list_filter['pool'] = pool_id

        if 'id__in[]' in request.GET:
            try:
                ids = request.GET.getlist("id__in[]")
                list_filter['id__in'] = [int(i) for i in ids]
            except ValueError:
                return Response("Invalid OSD ID in list",
                                status=status.HTTP_400_BAD_REQUEST)

        # Get data
        osds = self.client.list(OSD, list_filter)
        osd_to_pools = self.client.get_sync_object(OsdMap, ['osd_pools'])
        crush_nodes = self.client.get_sync_object(OsdMap,
                                                  ['osd_tree_node_by_id'])
        osd_metadata = self.client.get_sync_object(OsdMap, ['osd_metadata'])

        osd_id_to_hostname = dict([
            (int(osd_id), osd_meta["hostname"])
            for osd_id, osd_meta in osd_metadata.items()
        ])

        # Get data depending on OSD list
        osd_commands = self.client.get_valid_commands(OSD,
                                                      [x['osd'] for x in osds])

        # Build OSD data objects
        for o in osds:
            # An OSD being in the OSD map does not guarantee its presence in the CRUSH
            # map, as "osd crush rm" and "osd rm" are separate operations.
            try:
                o.update(
                    {'reweight': float(crush_nodes[o['osd']]['reweight'])})
            except KeyError:
                log.warning("No CRUSH data available for OSD {0}".format(
                    o['osd']))
                o.update({'reweight': 0.0})

            o['server'] = osd_id_to_hostname.get(o['osd'], None)

        for o in osds:
            o['pools'] = osd_to_pools[o['osd']]

        for o in osds:
            o.update(osd_commands[o['osd']])

        return Response(
            self.serializer_class([DataObject(o) for o in osds],
                                  many=True).data)
Ejemplo n.º 2
0
    def list(self, request):
        rules = self.client.list(CRUSH_RULE, {})
        osds_by_rule_id = self.client.get_sync_object(OsdMap,
                                                      ['osds_by_rule_id'])
        rulesets_data = defaultdict(list)
        for rule in rules:
            rule['osd_count'] = len(osds_by_rule_id[rule['rule_id']])
            rulesets_data[rule['ruleset']].append(rule)

        rulesets = [
            DataObject({
                'id': rd_id,
                'rules': [DataObject(r) for r in rd_rules]
            }) for (rd_id, rd_rules) in rulesets_data.items()
        ]

        return Response(CrushRuleSetSerializer(rulesets, many=True).data)
Ejemplo n.º 3
0
    def retrieve(self, request, mon_id):
        mons = self._get_mons()
        try:
            mon = [m for m in mons if m['name'] == mon_id][0]
        except IndexError:
            raise Http404("Mon '%s' not found" % mon_id)

        return Response(self.serializer_class(DataObject(mon)).data)
Ejemplo n.º 4
0
 def retrieve(self, request, key):
     ceph_config = self.client.get_sync_object(Config).data
     try:
         setting = DataObject({'key': key, 'value': ceph_config[key]})
     except KeyError:
         raise Http404("Key '%s' not found" % key)
     else:
         return Response(self.serializer_class(setting).data)
Ejemplo n.º 5
0
 def list(self, request):
     rules = self.client.list(CRUSH_RULE, {})
     osds_by_rule_id = self.client.get_sync_object(OsdMap,
                                                   ['osds_by_rule_id'])
     for rule in rules:
         rule['osd_count'] = len(osds_by_rule_id[rule['rule_id']])
     return Response(
         CrushRuleSerializer([DataObject(r) for r in rules],
                             many=True).data)
Ejemplo n.º 6
0
 def list(self, request):
     ceph_config = self.client.get_sync_object(Config).data
     settings = [
         DataObject({
             'key': k,
             'value': v
         }) for (k, v) in ceph_config.items()
     ]
     return Response(self.serializer_class(settings, many=True).data)
Ejemplo n.º 7
0
    def retrieve(self, request, osd_id):
        osd = self.client.get_sync_object(OsdMap, ['osds_by_id', int(osd_id)])
        crush_node = self.client.get_sync_object(
            OsdMap, ['osd_tree_node_by_id', int(osd_id)])
        osd['reweight'] = float(crush_node['reweight'])

        osd_metadata = self.client.get_sync_object(OsdMap, ['osd_metadata'])

        osd_id_to_hostname = dict([(int(oid), osd_meta["hostname"])
                                   for oid, osd_meta in osd_metadata.items()])

        osd['server'] = osd_id_to_hostname.get(osd['osd'], None)

        pools = self.client.get_sync_object(OsdMap, ['osd_pools', int(osd_id)])
        osd['pools'] = pools

        osd_commands = self.client.get_valid_commands(OSD, [int(osd_id)])
        osd.update(osd_commands[int(osd_id)])

        return Response(self.serializer_class(DataObject(osd)).data)
Ejemplo n.º 8
0
 def list(self, request):
     mons = self._get_mons()
     return Response(
         self.serializer_class([DataObject(m) for m in mons],
                               many=True).data)
Ejemplo n.º 9
0
 def list(self, request):
     servers = self.client.server_list()
     return Response(
         self.serializer_class([DataObject(s) for s in servers],
                               many=True).data)
Ejemplo n.º 10
0
 def retrieve(self, request, fqdn):
     return Response(
         self.serializer_class(DataObject(
             self.client.server_get(fqdn))).data)
Ejemplo n.º 11
0
 def retrieve(self, request, **kwargs):
     request_id = kwargs['request_id']
     user_request = DataObject(self.client.get_request(request_id))
     return Response(self.serializer_class(user_request).data)
Ejemplo n.º 12
0
 def cancel(self, request, request_id):
     user_request = DataObject(self.client.cancel_request(request_id))
     return Response(self.serializer_class(user_request).data)