Exemplo n.º 1
0
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            CreateSnapshotResponse response = new CreateSnapshotResponse();

            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.Snapshot = SnapshotUnmarshaller.Instance.Unmarshall(context);
                        continue;
                    }
                }
            }

            return(response);
        }
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            CreateSnapshotResponse response = new CreateSnapshotResponse();

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

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

            return(response);
        }
Exemplo n.º 3
0
        private static void UnmarshallResult(XmlUnmarshallerContext context, CreateSnapshotResponse response)
        {
            int originalDepth = context.CurrentDepth;
            int targetDepth   = originalDepth + 1;

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

            while (context.Read())
            {
                if (context.IsStartElement || context.IsAttribute)
                {
                    if (context.TestExpression("Snapshot", targetDepth))
                    {
                        response.Snapshot = SnapshotUnmarshaller.GetInstance().Unmarshall(context);
                        continue;
                    }
                }
                else if (context.IsEndElement && context.CurrentDepth < originalDepth)
                {
                    return;
                }
            }
        }
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            CreateSnapshotResponse response = new CreateSnapshotResponse();

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

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.IsStartElement)
                {
                    if (context.TestExpression("CreateSnapshotResult", 2))
                    {
                        UnmarshallResult(context, response);
                        continue;
                    }

                    if (context.TestExpression("ResponseMetadata", 2))
                    {
                        response.ResponseMetadata = ResponseMetadataUnmarshaller.Instance.Unmarshall(context);
                    }
                }
            }

            return(response);
        }
        /**
         * Creates a point in time snapshot of a file system and waits for it to become available. Note that snapshot
         * names are immutable and must be unique amongst all non-DELETED snapshots for a file system.
         *
         * We recommend using a retry token on these requests so that if you receive a timeout or server error
         * and need to retry the request you won't run the risk of creating multiple resources.
         *
         * @param fsClient the service client used to communicate with the File Storage service
         * @param fileSystem the file system to create the snapshot of
         */
        private static async Task <Snapshot> CreateSnapshot(FileStorageClient fsClient, FileSystem fileSystem)
        {
            logger.Info("Creating Snapshot...");

            CreateSnapshotDetails createSnapshotDetails = new CreateSnapshotDetails
            {
                FileSystemId = fileSystem.Id,
                Name         = "example_snapshot"
            };
            CreateSnapshotRequest createRequest = new CreateSnapshotRequest
            {
                CreateSnapshotDetails = createSnapshotDetails
            };
            CreateSnapshotResponse createResponse = await fsClient.CreateSnapshot(createRequest);

            logger.Info($"Created snapshot: {createResponse.Snapshot.Name}");

            logger.Info($"Waiting for snapshot to become available");
            GetSnapshotRequest getRequest = new GetSnapshotRequest
            {
                SnapshotId = createResponse.Snapshot.Id
            };
            GetSnapshotResponse getResponse = fsClient.Waiters.ForSnapshot(getRequest, Snapshot.LifecycleStateEnum.Active).Execute();

            logger.Info($"Snapshot state: {getResponse.Snapshot.LifecycleState}");

            return(getResponse.Snapshot);
        }
Exemplo n.º 6
0
        private static void UnmarshallResult(JsonUnmarshallerContext context, CreateSnapshotResponse response)
        {
            int originalDepth = context.CurrentDepth;
            int targetDepth   = originalDepth + 1;

            while (context.Read())
            {
                if (context.TestExpression("VolumeARN", targetDepth))
                {
                    context.Read();
                    response.VolumeARN = StringUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("SnapshotId", targetDepth))
                {
                    context.Read();
                    response.SnapshotId = StringUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.CurrentDepth <= originalDepth)
                {
                    return;
                }
            }

            return;
        }
Exemplo n.º 7
0
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            CreateSnapshotResponse response = new CreateSnapshotResponse();

            context.Read();

            UnmarshallResult(context, response);
            return(response);
        }
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            CreateSnapshotResponse response = new CreateSnapshotResponse();

            context.Read();
            response.CreateSnapshotResult = CreateSnapshotResultUnmarshaller.GetInstance().Unmarshall(context);

            return(response);
        }
Exemplo n.º 9
0
        public static CreateSnapshotResponse Unmarshall(UnmarshallerContext context)
        {
            CreateSnapshotResponse createSnapshotResponse = new CreateSnapshotResponse();

            createSnapshotResponse.HttpResponse = context.HttpResponse;
            createSnapshotResponse.RequestId    = context.StringValue("CreateSnapshot.RequestId");
            createSnapshotResponse.SnapshotId   = context.StringValue("CreateSnapshot.SnapshotId");

            return(createSnapshotResponse);
        }
        public static CreateSnapshotResponse Unmarshall(UnmarshallerContext _ctx)
        {
            CreateSnapshotResponse createSnapshotResponse = new CreateSnapshotResponse();

            createSnapshotResponse.HttpResponse = _ctx.HttpResponse;
            createSnapshotResponse.RequestId    = _ctx.StringValue("CreateSnapshot.RequestId");
            createSnapshotResponse.Result       = _ctx.BooleanValue("CreateSnapshot.Result");

            return(createSnapshotResponse);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Create a snapshot of a volume.
        /// </summary>
        /// <param name="volumeId"></param>
        /// <param name="description"></param>
        /// <returns></returns>
        public string CreateSnapShot(string volumeId, string description)
        {
            var request = new CreateSnapshotRequest {
                VolumeId = volumeId, Description = description
            };

            CreateSnapshotResponse response = Client.CreateSnapshot(request);

            return(response.CreateSnapshotResult.Snapshot.SnapshotId);
        }
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            CreateSnapshotResponse response = new CreateSnapshotResponse();

            int targetDepth = 2;

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

                        continue;
                    }
                }
            }


            return(response);
        }
        private static void CreateSnapshot(EvsClient client)
        {
            CreateSnapshotRequest req = new CreateSnapshotRequest()
            {
                Body = new CreateSnapshotRequestBody()
                {
                    Snapshot = new CreateSnapshotOption()
                    {
                        VolumeId    = "1bebb541-5601-450f-a87a-55f9a3c8327b",
                        Description = "test",
                        Name        = "test",
                        Force       = false
                    }
                }
            };

            try
            {
                CreateSnapshotResponse resp = client.CreateSnapshot(req);
                Console.WriteLine(resp.Snapshot);
                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);
            }
        }
Exemplo n.º 14
0
        public static void Backup(string name, string description, string volumeid, string volumename, string instancename, string expires)
        {
            Console.WriteLine("Creating snapshot of " + volumeid + " / " + volumename + " / " + instancename);

            AmazonEC2 ec2 = Ec2Helper.CreateClient();

            CreateSnapshotRequest rq = new CreateSnapshotRequest();

            rq.VolumeId    = volumeid;
            rq.Description = description;

            CreateSnapshotResponse rs = ec2.CreateSnapshot(rq);

            string snapshotid = rs.CreateSnapshotResult.Snapshot.SnapshotId;


            // build tags for snapshot

            List <Tag> tags = new List <Tag>();

            tags.Add(new Tag {
                Key = "Name", Value = name
            });
            tags.Add(new Tag {
                Key = "source", Value = "scheduler"
            });
            tags.Add(new Tag {
                Key = "instance", Value = instancename
            });
            tags.Add(new Tag {
                Key = "volume", Value = volumename
            });
            tags.Add(new Tag {
                Key = "expires", Value = expires.ToString()
            });


            // get tags from volume to be applied to snapshot

            DescribeTagsRequest trq = new DescribeTagsRequest();

            trq.WithFilter(new Filter()
            {
                Name = "resource-id", Value = new List <string>()
                {
                    volumeid
                }
            });
            DescribeTagsResponse trs = ec2.DescribeTags(trq);

            foreach (ResourceTag t in trs.DescribeTagsResult.ResourceTag)
            {
                if (t.Key != "nextSnapshot" && t.Key != "lastSnapshot" && t.Key != "Name")
                {
                    tags.Add(new Tag {
                        Key = t.Key, Value = t.Value
                    });
                }
            }


            // apply tags to snapshopt

            CreateTagsRequest rqq = new CreateTagsRequest();

            rqq.WithResourceId(snapshotid);

            rqq.WithTag(tags.ToArray());


            var createTagResponse = ec2.CreateTags(rqq);
        }