Beispiel #1
0
    def ListVolumes(self, req, context):
        list_response = csi_pb2.ListVolumesResponse()

        # FIXME(jdg): This is a train wreck down here,
        # I can't figure out how the heck to get the
        # volume elements added to the response.entries
        c_vols = self.volume_api.get_all(self.cctxt)
        # For now we're just returning nada
        return list_response
Beispiel #2
0
    def ListVolumes(self, req, context):
        cc = self._get_client_session()
        vols = cc.volumes.list()
        list_response = csi_pb2.ListVolumesResponse()
        volumes = []

        # FIXME(jdg): This is a train wreck down here,
        # I can't figure out how the heck to get the
        # volume elements added to the response.entries
        elements = []
        for v in vols:
            vol = csi_pb2.Volume()
            vol.capacity_bytes = v.size
            vol.id = v.id
            volumes.append(vol)

        # For now we're just returning nada
        return list_response
Beispiel #3
0
    def ListVolumes(self, request, context):
        """Returns list of all PVCs with sizes existing in Kadalu Storage"""

        logging.debug(logf("ListVolumes request received", request=request))
        global GEN
        # Need to check for no hostvol creation only once
        if GEN is None:
            # Handle no hostvol creation, with ~10s timeout
            volumes = get_pv_hosting_volumes(iteration=3)
            if not volumes:
                errmsg = "No PV hosting volume is created yet"
                logging.error(errmsg)
                context.set_details(errmsg)
                context.set_code(grpc.StatusCode.ABORTED)
                return csi_pb2.ListVolumesResponse()

        starting_token = request.starting_token or '0'
        try:
            starting_token = int(starting_token)
        except ValueError as errmsg:
            # We are using tokens which can be converted to integer's
            errmsg = "Invalid starting token supplied"
            logging.error(errmsg)
            context.set_details(errmsg)
            context.set_code(grpc.StatusCode.ABORTED)
            return csi_pb2.ListVolumesResponse()

        if not request.starting_token:
            # This is the first call and so start the generator
            max_entries = request.max_entries or 0
            if not max_entries:
                # In worst case limit ourselves with custom max_entries and
                # set next_token
                max_entries = LIMIT
            GEN = yield_list_of_pvcs(max_entries)

        # Run and wait for 'send'
        try:
            next(GEN)
        except StopIteration as errmsg:
            # Handle no PVC created from a storage volume yet
            logging.error(errmsg)
            context.set_details(errmsg)
            context.set_code(grpc.StatusCode.ABORTED)
            return csi_pb2.ListVolumesResponse()

        try:
            # Get list of PVCs limited at max_entries by suppling the token
            pvcs, next_token = GEN.send(starting_token)
        except StopIteration as errmsg:
            logging.error(errmsg)
            context.set_details(errmsg)
            context.set_code(grpc.StatusCode.ABORTED)
            return csi_pb2.ListVolumesResponse()

        entries = [{
            "volume": {
                "volume_id": value.get("name"),
                "capacity_bytes": value.get("size"),
            }
        } for value in pvcs if value is not None]

        return csi_pb2.ListVolumesResponse(entries=entries,
                                           next_token=next_token)