public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            CreateVolumeResponse response = new CreateVolumeResponse();

            int originalDepth = context.CurrentDepth;
            int targetDepth   = originalDepth + 1;

            if (context.IsStartOfDocument)
            {
                targetDepth = 2;
            }

            while (context.ReadAtDepth(originalDepth))
            {
                if (context.IsStartElement || context.IsAttribute)
                {
                    if (context.TestExpression(".", targetDepth))
                    {
                        response.Volume = VolumeUnmarshaller.Instance.Unmarshall(context);
                        continue;
                    }
                }
            }

            return(response);
        }
        public override async Task <CreateVolumeResponse> CreateVolume(
            CreateVolumeRequest request,
            ServerCallContext context)
        {
            CreateVolumeResponse response = new CreateVolumeResponse();

            if (string.IsNullOrEmpty(request.Name))
            {
                logger.LogDebug("Validation fail");
                throw new RpcException(new Status(StatusCode.InvalidArgument, "Name cannot be empty"));
            }

            using (var _s = logger.StepInformation("{0}, name: {1}", nameof(CreateVolume), request.Name))
            {
                try
                {
                    var ctx = new DataProviderContext <ManagedDiskConfig>();
                    await contextConfig.Provide(ctx);

                    var actx = new AzureAuthConfigProviderContext {
                        Secrets = request.ControllerCreateSecrets
                    };

                    var provisionService = provisionServiceFactory.Create(
                        provider.Provide(actx),
                        ctx.Result.SubscriptionId);

                    var sizeGiB = byteUnitConverter.ToGibibyte(
                        request.CapacityRange == null
                        ? 1
                        : request.CapacityRange.RequiredBytes);

                    var md = await provisionService.CreateAsync(
                        ctx.Result.SubscriptionId,
                        ctx.Result.ResourceGroupName,
                        request.Name,
                        ctx.Result.Location,
                        sizeGiB);

                    response.Volume = new Volume
                    {
                        Id            = md.Id.Id,
                        CapacityBytes = byteUnitConverter.FromGigibyte(md.Size),
                    };
                }
                catch (Exception ex)
                {
                    logger.LogError(ex, "Exception in CreateAsync");
                    throw new RpcException(new Status(StatusCode.Internal, ex.Message));
                }

                _s.Commit();
            }

            return(response);
        }
示例#3
0
        public static CreateVolumeResponse Unmarshall(UnmarshallerContext context)
        {
            CreateVolumeResponse createVolumeResponse = new CreateVolumeResponse();

            createVolumeResponse.HttpResponse = context.HttpResponse;
            createVolumeResponse.RequestId    = context.StringValue("CreateVolume.RequestId");
            createVolumeResponse.VolumeId     = context.StringValue("CreateVolume.VolumeId");

            return(createVolumeResponse);
        }
示例#4
0
        /// <summary>
        /// Creates a new volume
        /// </summary>
        /// <param name="avilabilityZone">The Availability zone to create the volume in</param>
        /// <param name="size"></param>
        /// <returns>Returns the VolumeId of the newly created volume</returns>
        public string CreateNewVolume(string availabilityZone, string size)
        {
            var request = new CreateVolumeRequest {
                AvailabilityZone = availabilityZone, Size = size
            };

            CreateVolumeResponse response = Client.CreateVolume(request);

            return(response.CreateVolumeResult.Volume.VolumeId);
        }
示例#5
0
        /// <summary>
        /// Create a volume from a snapshot
        /// </summary>
        /// <param name="avilabilityZone">The Availability zone to create the volume in</param>
        /// <param name="snapshotId">The SnapShot to create the volume from</param>
        /// <returns>Returns the VolumeId of the newly created volume</returns>
        public string CreateVolumeFromSnapshot(string avilabilityZone, string snapshotId)
        {
            CreateVolumeRequest request = new CreateVolumeRequest();

            request.AvailabilityZone = avilabilityZone;
            request.SnapshotId       = snapshotId;

            CreateVolumeResponse response = Client.CreateVolume(request);

            return(response.CreateVolumeResult.Volume.VolumeId);
        }
示例#6
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            CreateVolumeResponse response = new CreateVolumeResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("Volume", targetDepth))
                {
                    var unmarshaller = VolumeUnmarshaller.Instance;
                    response.Volume = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
示例#7
0
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            CreateVolumeResponse response = new CreateVolumeResponse();

            int targetDepth = 2;

            while (context.Read())
            {
                if (context.IsStartElement || context.IsAttribute)
                {
                    if (context.TestExpression(".", targetDepth))
                    {
                        response.Volume = VolumeUnmarshaller.GetInstance().Unmarshall(context);

                        continue;
                    }
                }
            }


            return(response);
        }
示例#8
0
        private static void CreateVolume(EvsClient client)
        {
            CreateVolumeRequest req = new CreateVolumeRequest()
            {
                Body = new CreateVolumeRequestBody
                {
                    Volume = new CreateVolumeOption()
                    {
                        AvailabilityZone = "br-iaas-odin1a",
                        Count            = 1,
                        Size             = 40,
                        VolumeType       = "SATA",
                        Description      = "csharp",
                        Name             = "test"
                    }
                }
            };

            try
            {
                CreateVolumeResponse resp = client.CreateVolume(req);
                Console.WriteLine(resp.JobId);
                Console.WriteLine(resp.HttpStatusCode);
            }
            catch (RequestTimeoutException requestTimeoutException)
            {
                Console.WriteLine(requestTimeoutException.ErrorMessage);
            }
            catch (ServiceResponseException clientRequestException)
            {
                Console.WriteLine(clientRequestException.HttpStatusCode);
                Console.WriteLine(clientRequestException.ErrorCode);
                Console.WriteLine(clientRequestException.ErrorMsg);
            }
            catch (ConnectionException connectionException)
            {
                Console.WriteLine(connectionException.ErrorMessage);
            }
        }
        public override async Task <CreateVolumeResponse> CreateVolume(
            CreateVolumeRequest request,
            ServerCallContext context)
        {
            CreateVolumeResponse response = new CreateVolumeResponse();

            if (string.IsNullOrEmpty(request.Name))
            {
                logger.LogDebug("Validation fail");
                throw new RpcException(new Status(StatusCode.InvalidArgument, "Name cannot be empty"));
            }

            using (var _s = logger.StepInformation("{0}, name: {1}", nameof(CreateVolume), request.Name))
            {
                try
                {
                    response.Volume = await azureFileCsiService.CreateVolumeAsync(
                        request.Name,
                        request.ControllerCreateSecrets,
                        request.CapacityRange);
                }
                catch (StorageException ex)
                {
                    logger.LogWarning(ex, "Error from storage service");
                    _s.Commit();
                    throw new RpcException(new Status(StatusCode.InvalidArgument, ex.Message));
                }
                catch (Exception ex)
                {
                    logger.LogError(ex, "Exception in CreateVolume");
                    throw new RpcException(new Status(StatusCode.Internal, ex.Message));
                }

                _s.Commit();
            }

            return(response);
        }
        public override async Task <CreateVolumeResponse> CreateVolume(CreateVolumeRequest request, ServerCallContext context)
        {
            var name      = request.Name;
            var storage   = string.Empty;
            var sizeBytes = 10 * 1024 * 1024UL; //10GB
            var shared    = false;              //todo VHDSet's

            if (request.CapacityRange != null)
            {
                var requestSize = request.CapacityRange.RequiredBytes;
                if (requestSize == 0)
                {
                    requestSize = request.CapacityRange.LimitBytes;
                }
                if (requestSize > 0)
                {
                    sizeBytes = (ulong)requestSize;
                }

                //maybe test existed volume for limit
            }

            foreach (var entry in request.Parameters)
            {
                switch (entry.Key.ToUpper())
                {
                case "STORAGE":
                    storage = entry.Value;
                    break;

                default:
                    //unknown parameter
                    break;
                }
            }

            foreach (var entry in request.Secrets)
            {
                switch (entry.Key)
                {
                default:
                    //unknown secret
                    break;
                }
            }

            foreach (var entry in request.VolumeCapabilities)
            {
                switch (entry.AccessMode.Mode)
                {
                case VolumneAccessMode.SingleNodeWriter:
                    shared = false;
                    break;

                default:
                    throw new RpcException(new Status(StatusCode.InvalidArgument, string.Empty),
                                           "not supported volume access mode");
                }

                switch (entry.AccessTypeCase)
                {
                case VolumeCapability.AccessTypeOneofCase.Mount:
                    //throw new RpcException(new Status(StatusCode.InvalidArgument, string.Empty),
                    //    "not supported volume access type");
                    //maybe SMB3 FileServer support
                    //entry.Mount.MountFlags;
                    //entry.Mount.FsType;
                    break;

                case VolumeCapability.AccessTypeOneofCase.Block:
                    break;

                //case VolumeCapability.AccessTypeOneofCase.None:
                default:
                    throw new RpcException(new Status(StatusCode.InvalidArgument, string.Empty),
                                           "unknown volume access type");
                }
            }

            //todo request.AccessibilityRequirements
            //todo request.VolumeContentSource

            var foundVolumes = await _service.GetVolumesAsync(new HypervVolumeFilter { Name = name }).ToListAsync(context.CancellationToken);

            if (foundVolumes.Count > 1)
            {
                throw new RpcException(new Status(StatusCode.AlreadyExists, string.Empty), "volume name ambiguous");
            }


            HypervVolumeDetail volume;

            if (foundVolumes.Count == 1)
            {
                var foundVolume = foundVolumes[0];

                if (!string.IsNullOrEmpty(storage) && !StringComparer.OrdinalIgnoreCase.Equals(storage, foundVolume.Storage))
                {
                    throw new RpcException(new Status(StatusCode.AlreadyExists, string.Empty), "volume storage mismatch");
                }
                if (shared != foundVolume.Shared)
                {
                    throw new RpcException(new Status(StatusCode.AlreadyExists, string.Empty), "volume share mode mismatch");
                }

                volume = await _service.GetVolumeAsync(foundVolume.Path, context.CancellationToken);
            }
            else
            {
                volume = await _service.CreateVolumeAsync(new HypervCreateVolumeRequest
                {
                    Name      = name,
                    Storage   = storage,
                    SizeBytes = sizeBytes,
                    Shared    = shared
                },
                                                          context.CancellationToken);
            }

            if (request.CapacityRange != null)
            {
                if (request.CapacityRange.RequiredBytes > 0 && volume.SizeBytes < (ulong)request.CapacityRange.RequiredBytes)
                {
                    throw new RpcException(new Status(StatusCode.AlreadyExists, string.Empty), "volume too small");
                }

                if (request.CapacityRange.LimitBytes > 0 && (ulong)request.CapacityRange.LimitBytes < volume.SizeBytes)
                {
                    throw new RpcException(new Status(StatusCode.AlreadyExists, string.Empty), "volume too large");
                }
            }

            var rsp = new CreateVolumeResponse
            {
                Volume = new Volume
                {
                    VolumeId      = volume.Name,
                    CapacityBytes = (long)volume.SizeBytes
                }
            };

            rsp.Volume.VolumeContext.Add("Id", volume.Id.ToString());
            rsp.Volume.VolumeContext.Add("Storage", volume.Storage);
            rsp.Volume.VolumeContext.Add("Path", volume.Path);
            //maybe add path

            //todo rsp.Volume.AccessibleTopology
            //todo rsp.Volume.ContentSource

            return(rsp);
        }