AwsSnapshotScheduler.Program.CheckForExpiredSnapshots C# (CSharp) Метод

CheckForExpiredSnapshots() публичный статический Метод

Check for any snapshots set to expire -- that have a tag key of "expires" with a value that is in the past.
public static CheckForExpiredSnapshots ( ) : void
Результат void
        public static void CheckForExpiredSnapshots()
        {
            Console.WriteLine("Checking for expired snapshots...");

            var ec2 = Ec2Helper.CreateClient();

            DescribeSnapshotsRequest rq = new DescribeSnapshotsRequest();
            rq.OwnerIds.Add("self");
            rq.Filters.Add(new Filter() { Name = "tag-key", Values = new List<string>() { "expires" } });

            DescribeSnapshotsResponse rs = ec2.DescribeSnapshots(rq);

            foreach(Snapshot s in rs.Snapshots)
            {
                string expireText = Ec2Helper.GetTagValue(s.Tags, "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);
                    }
                }

            }
        }