Пример #1
0
    def get(self, fs_id, object_type, object_id):
        """
        Get one object from a particular cluster.
        """

        cluster = self._fs_resolve(fs_id)
        if object_type == OSD:
            return self._osd_resolve(cluster, object_id)
        elif object_type == POOL:
            return self._pool_resolve(cluster, object_id)
        elif object_type == CRUSH_RULE:
            try:
                crush_rule = cluster.get_sync_object(OsdMap).crush_rule_by_id[object_id]
            except KeyError:
                raise NotFound(CRUSH_RULE, object_id)
            return crush_rule
        elif object_type == CRUSH_NODE:
            try:
                crush_node = cluster.get_sync_object(OsdMap).crush_node_by_id[object_id]
            except KeyError:
                raise NotFound(CRUSH_NODE, object_id)
            return crush_node
        elif object_type == CRUSH_TYPE:
            try:
                crush_type = cluster.get_sync_object(OsdMap).crush_type_by_id[object_id]
            except KeyError:
                raise NotFound(CRUSH_TYPE, object_id)
            return crush_type
        else:
            raise NotImplementedError(object_type)
Пример #2
0
    def get_sync_object(self, fs_id, object_type, path=None):
        """
        Get one of the objects that ClusterMonitor keeps a copy of from the mon, such
        as the cluster maps.

        :param fs_id: The fsid of a cluster
        :param object_type: String, one of SYNC_OBJECT_TYPES
        :param path: List, optional, a path within the object to return instead of the whole thing

        :return: the requested data, or None if it was not found (including if any element of ``path``
                 was not found)
        """

        if path:
            obj = self._fs_resolve(fs_id).get_sync_object(
                SYNC_OBJECT_STR_TYPE[object_type])
            try:
                for part in path:
                    if isinstance(obj, dict):
                        obj = obj[part]
                    else:
                        obj = getattr(obj, part)
            except (AttributeError, KeyError) as e:
                log.exception("Exception %s traversing %s: obj=%s" %
                              (e, path, obj))
                raise NotFound(object_type, path)
            return obj
        else:
            return self._fs_resolve(fs_id).get_sync_object_data(
                SYNC_OBJECT_STR_TYPE[object_type])
Пример #3
0
    def _pool_resolve(self, cluster, pool_id):
        osdmap = cluster.get_sync_object(OsdMap)

        try:
            return osdmap.pools_by_id[pool_id]
        except KeyError:
            raise NotFound(POOL, pool_id)
Пример #4
0
    def _osd_resolve(self, cluster, osd_id):
        osdmap = cluster.get_sync_object(OsdMap)

        try:
            return osdmap.osds_by_id[osd_id]
        except KeyError:
            raise NotFound(OSD, osd_id)
Пример #5
0
    def list(self, fs_id, object_type, list_filter):
        """
        Get many objects
        """

        cluster = self._fs_resolve(fs_id)
        osd_map = cluster.get_sync_object_data(OsdMap)
        if osd_map is None:
            return []
        if object_type == OSD:
            result = osd_map['osds']
            if 'id__in' in list_filter:
                result = [
                    o for o in result if o['osd'] in list_filter['id__in']
                ]
            if 'pool' in list_filter:
                try:
                    osds_in_pool = cluster.get_sync_object(
                        OsdMap).osds_by_pool[list_filter['pool']]
                except KeyError:
                    raise NotFound("Pool {0} does not exist".format(
                        list_filter['pool']))
                else:
                    result = [o for o in result if o['osd'] in osds_in_pool]

            return result
        elif object_type == POOL:
            return osd_map['pools']
        elif object_type == CRUSH_RULE:
            return osd_map['crush']['rules']
        else:
            raise NotImplementedError(object_type)
Пример #6
0
 def get_request(self, request_id):
     """
     Get a JSON representation of a UserRequest
     """
     try:
         return self._dump_request(self._manager.requests.get_by_id(request_id))
     except KeyError:
         raise NotFound('request', request_id)
Пример #7
0
    def get_request(self, fs_id, request_id):
        """
        Get a JSON representation of a UserRequest
        """
        cluster = self._fs_resolve(fs_id)
        try:
            request = cluster.get_request(request_id)
        except KeyError:
            raise NotFound('request', request_id)

        return self._dump_request(request)
Пример #8
0
    def get_valid_commands(self, fs_id, object_type, object_ids):
        """
        Determine what commands can be run on OSD object_ids
        """
        if object_type != OSD:
            raise NotImplementedError(object_type)

        cluster = self._fs_resolve(fs_id)
        try:
            valid_commands = cluster.get_valid_commands(object_type, object_ids)
        except KeyError as e:
            raise NotFound(object_type, str(e))

        return valid_commands
Пример #9
0
    def minion_get(self, minion_id):
        result = self._salt_key.name_match(minion_id, full=True)
        if not result:
            raise NotFound(SERVER, minion_id)

        if 'minions' in result:
            status = "accepted"
        elif "minions_pre" in result:
            status = "pre"
        elif "minions_rejected" in result:
            status = "rejected"
        else:
            raise ValueError(result)

        return {'id': minion_id, 'status': status}
Пример #10
0
    def auth_get(self, minion_id):
        # FIXME: I think we're supposed to use salt.wheel.Wheel.master_call
        # for this stuff to call out to the master instead of touching
        # the files directly (need to set up some auth to do that though)

        result = self._salt_key.name_match(minion_id, full=True)
        if not result:
            raise NotFound(SERVER, minion_id)

        if 'minions' in result:
            status = AUTH_ACCEPTED
        elif "minions_pre" in result:
            status = AUTH_NEW
        elif "minions_rejected" in result:
            status = AUTH_REJECTED
        else:
            raise ValueError(result)

        return {'id': minion_id, 'status': status}
Пример #11
0
 def _server_resolve(self, fqdn):
     try:
         return self._manager.servers.get_one(fqdn)
     except KeyError:
         raise NotFound(SERVER, fqdn)
Пример #12
0
 def _fs_resolve(self, fs_id):
     try:
         return self._manager.clusters[fs_id]
     except KeyError:
         raise NotFound(CLUSTER, fs_id)
Пример #13
0
 def cancel_request(self, request_id):
     try:
         self._manager.requests.cancel(request_id)
         return self.get_request(request_id)
     except KeyError:
         raise NotFound('request', request_id)