Beispiel #1
0
    def ControllerPublishVolume(self, request, context):
        vol, node = self._get_vol_node(request, context)

        # The volume is already attached
        if vol.status == 'in-use':
            for conn in vol.connections:
                # TODO(geguileo): Change when we enable multi-attach
                if conn.attached_host != request.node_id:
                    context.abort(grpc.StatusCode.FAILED_PRECONDITION,
                                  'Volume published to another node')

            mode = request.volume_capability.access_mode.mode
            if ((not request.readonly and
                 mode == types.AccessModeType.SINGLE_NODE_READER_ONLY) or
                    (request.readonly and
                     mode == types.AccessModeType.SINGLE_NODE_WRITER)):  # noqa

                context.abort(grpc.StatusCode.ALREADY_EXISTS,
                              'Readonly incompatible with volume capability')

            conn = vol.connections[0]
        else:
            conn = vol.connect(node.connector_dict, attached_host=node.id)
        publish_info = {'connection_info': json.dumps(conn.connection_info)}
        return types.CtrlPublishResp(publish_info=publish_info)
Beispiel #2
0
    def ControllerPublishVolume(self, request, context):
        vol, node = self._get_vol_node(request, context)

        # The volume is already attached
        if vol.status == 'in-use':
            for conn in vol.connections:
                # TODO(geguileo): Change when we enable multi-attach
                if conn.attached_host != request.node_id:
                    context.abort(grpc.StatusCode.FAILED_PRECONDITION,
                                  'Volume published to another node')

            # TODO(geguileo): Check capabilities and readonly compatibility
            #                 and raise ALREADY_EXISTS if not compatible
            conn = vol.connections[0]
        else:
            conn = vol.connect(node.connector_dict, attached_host=node.id)
        publish_info = {'connection_info': json.dumps(conn.connection_info)}
        return types.CtrlPublishResp(publish_info=publish_info)