Пример #1
0
        public override async Task <NodePublishVolumeResponse> NodePublishVolume(
            NodePublishVolumeRequest request, ServerCallContext context)
        {
            var id         = request.VolumeId;
            var targetPath = request.TargetPath;

            using (var _s = logger.StepInformation("{0}, id: {1}, targetPath: {2}",
                                                   nameof(NodePublishVolume), id, targetPath))
            {
                try
                {
                    if (!request.PublishInfo.TryGetValue("lun", out var lunStr))
                    {
                        throw new Exception("No lun info");
                    }
                    var lun = int.Parse(lunStr);
                    await azureDiskAttacher.AttachAsync(targetPath, lun);
                }
                catch (Exception ex)
                {
                    logger.LogWarning(ex, "Exception in AttachAsync");
                    throw;
                }

                _s.Commit();
            }

            await Task.CompletedTask;

            return(new NodePublishVolumeResponse());
        }
Пример #2
0
        public override async Task <NodePublishVolumeResponse> NodePublishVolume(
            NodePublishVolumeRequest request, ServerCallContext context)
        {
            var id         = request.VolumeId;
            var targetPath = request.TargetPath;

            using (var _s = logger.StepInformation("{0}, id: {1}, targetPath: {2}",
                                                   nameof(NodePublishVolume), id, targetPath))
            {
                try
                {
                    (var unc, var cred) = azureFileCsiService.GetSmbShare(id, request.NodePublishSecrets);
                    await smbShareAttacher.AttachAsync(
                        targetPath,
                        unc,
                        cred);
                }
                catch (Exception ex)
                {
                    logger.LogWarning(ex, "Exception in AttachAsync");
                    throw;
                }

                _s.Commit();
            }

            await Task.CompletedTask;

            return(new NodePublishVolumeResponse());
        }
Пример #3
0
        public async Task Attach()
        {
            var channel    = TestHelper.CreateChannel();
            var controller = new Controller.ControllerClient(channel);
            var request    = new CreateVolumeRequest
            {
                Name = namingProvider.VolumeName(),
            };

            populateSecretsFromEnv(request.ControllerCreateSecrets);

            var response = await controller.CreateVolumeAsync(request, null);

            Assert.NotNull(response.Volume);
            Assert.NotNull(response.Volume.Id);
            var volId = response.Volume.Id;

            var node    = new Node.NodeClient(TestHelper.CreateChannel());
            var tmppath = Path.Combine(Path.GetTempPath(), namingProvider.DirName());

            try
            {
                var npr = new NodePublishVolumeRequest
                {
                    VolumeId   = volId,
                    TargetPath = tmppath,
                };
                populateSecretsFromEnv(npr.NodePublishSecrets);

                await node.NodePublishVolumeAsync(npr, null);

                var tmpfile = Path.Combine(tmppath, namingProvider.FileName());
                var content = DateTimeOffset.UtcNow.ToString();
                await File.AppendAllTextAsync(tmpfile, content);

                // TODO valid content through storage API, and enable DeleteVolumeAsync
            }
            finally
            {
                await node.NodeUnpublishVolumeAsync(new NodeUnpublishVolumeRequest
                {
                    VolumeId   = volId,
                    TargetPath = tmppath,
                }, null);

                /*
                 * await controller.DeleteVolumeAsync(new DeleteVolumeRequest
                 * {
                 *  VolumeId = volId,
                 * });
                 */
            }
        }
Пример #4
0
        public override async Task <NodePublishVolumeResponse> NodePublishVolume(NodePublishVolumeRequest request, ServerCallContext context)
        {
            //todo check capabilities, readonly

            await _service.PublishDeviceAsync(new HypervNodePublishRequest
            {
                Name = request.VolumeId,
                StagingTargetPath = request.StagingTargetPath,
                PublishTargetPath = request.TargetPath
            },
                                              context.CancellationToken);

            var rsp = new NodePublishVolumeResponse
            {
            };

            return(rsp);
        }