public override void Execute() { AmazonEC2Client client = new AmazonEC2Client(AWSAuthConnection.OUR_ACCESS_KEY_ID, AWSAuthConnection.OUR_SECRET_ACCESS_KEY); DescribeSnapshotsRequest request = new DescribeSnapshotsRequest(); DescribeSnapshotsResponse response = client.DescribeSnapshots(request); Dictionary<string, List<Amazon.EC2.Model.Snapshot>> snapshots = new Dictionary<string, List<Amazon.EC2.Model.Snapshot>>(); foreach (Amazon.EC2.Model.Snapshot r in response.DescribeSnapshotsResult.Snapshot) { if (!snapshots.ContainsKey(r.VolumeId)) snapshots[r.VolumeId] = new List<Amazon.EC2.Model.Snapshot>(); snapshots[r.VolumeId].Add(r); } foreach (string volumeId in snapshots.Keys) { Console.WriteLine("--- Volume: {0}", volumeId); snapshots[volumeId].Sort(delegate(Amazon.EC2.Model.Snapshot x,Amazon.EC2.Model.Snapshot y) { return DateTime.Parse(x.StartTime).CompareTo(DateTime.Parse(y.StartTime)); }); foreach (Amazon.EC2.Model.Snapshot s in snapshots[volumeId]) { DateTime startTime = DateTime.Parse(s.StartTime); Console.Write("{0}\t{1}\t{2}\t{3}", s.SnapshotId, startTime, s.Progress, s.Status); Console.WriteLine(); } Console.WriteLine(); } }
public override void Execute() { Amazon.EC2.AmazonEC2Client client = new Amazon.EC2.AmazonEC2Client(AWSAuthConnection.OUR_ACCESS_KEY_ID, AWSAuthConnection.OUR_SECRET_ACCESS_KEY); List<string> snapshotsToDelete = new List<string>(); if (isVolumeId) { // delete snapshots belonging to this volume DescribeSnapshotsRequest request = new DescribeSnapshotsRequest(); DescribeSnapshotsResponse response = client.DescribeSnapshots(request); foreach (Amazon.EC2.Model.Snapshot s in response.DescribeSnapshotsResult.Snapshot) { if (string.Equals(s.VolumeId, id, StringComparison.InvariantCultureIgnoreCase)) { DateTime snapshotDate = DateTime.Parse(s.StartTime); if (snapshotDate.AddDays(days) < DateTime.Now) snapshotsToDelete.Add(s.SnapshotId); } } } else { snapshotsToDelete.Add(id); } foreach (string snapshotId in snapshotsToDelete) { Console.WriteLine("Deleting snapshot ID {0}", snapshotId); Amazon.EC2.Model.DeleteSnapshotRequest request = new Amazon.EC2.Model.DeleteSnapshotRequest(); request.SnapshotId = snapshotId; Amazon.EC2.Model.DeleteSnapshotResponse response = client.DeleteSnapshot(request); } }
public override void Execute() { Amazon.EC2.AmazonEC2Client client = new Amazon.EC2.AmazonEC2Client(AWSAuthConnection.OUR_ACCESS_KEY_ID, AWSAuthConnection.OUR_SECRET_ACCESS_KEY); List <string> snapshotsToDelete = new List <string>(); if (isVolumeId) { // delete snapshots belonging to this volume DescribeSnapshotsRequest request = new DescribeSnapshotsRequest(); DescribeSnapshotsResponse response = client.DescribeSnapshots(request); foreach (Amazon.EC2.Model.Snapshot s in response.DescribeSnapshotsResult.Snapshot) { if (string.Equals(s.VolumeId, id, StringComparison.InvariantCultureIgnoreCase)) { DateTime snapshotDate = DateTime.Parse(s.StartTime); if (snapshotDate.AddDays(days) < DateTime.Now) { snapshotsToDelete.Add(s.SnapshotId); } } } } else { snapshotsToDelete.Add(id); } foreach (string snapshotId in snapshotsToDelete) { Console.WriteLine("Deleting snapshot ID {0}", snapshotId); Amazon.EC2.Model.DeleteSnapshotRequest request = new Amazon.EC2.Model.DeleteSnapshotRequest(); request.SnapshotId = snapshotId; //Amazon.EC2.Model.DeleteSnapshotResponse response = client.DeleteSnapshot(request); } }