AwsSnapshotScheduler.Ec2Helper.DeleteSnapsot C# (CSharp) Méthode

DeleteSnapsot() public static méthode

Delete the snapshop with the given ID from EBS
public static DeleteSnapsot ( string snapshotid ) : void
snapshotid string
Résultat void
        public static void DeleteSnapsot(string snapshotid)
        {
            AmazonEC2Client ec2 = CreateClient();

            DeleteSnapshotRequest rq = new DeleteSnapshotRequest();
            rq.SnapshotId = snapshotid;

            DeleteSnapshotResponse rs = ec2.DeleteSnapshot(rq);
        }

Usage Example

        /// <summary>
        /// Check for any snapshots set to expire -- that have a tag key of "expires" with a value that is in the past.
        /// </summary>
        public static void CheckForExpiredSnapshots()
        {
            Console.WriteLine("Checking for expired snapshots...");

            AmazonEC2 ec2 = Ec2Helper.CreateClient();

            DescribeSnapshotsRequest rq = new DescribeSnapshotsRequest();

            rq.WithOwner("self");
            rq.WithFilter(new Filter()
            {
                Name = "tag-key", Value = new List <string>()
                {
                    "expires"
                }
            });

            DescribeSnapshotsResponse rs = ec2.DescribeSnapshots(rq);

            foreach (Snapshot s in rs.DescribeSnapshotsResult.Snapshot)
            {
                string expireText = Ec2Helper.GetTagValue(s.Tag, "expires");

                DateTime expires;

                if (DateTime.TryParse(expireText, out expires))
                {
                    if (expires < DateTime.UtcNow)
                    {
                        Console.WriteLine("Deleting " + s.SnapshotId + " for " + s.VolumeId + "...");
                        Ec2Helper.DeleteSnapsot(s.SnapshotId);
                    }
                }
            }
        }