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

            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("keySet/item", targetDepth))
                    {
                        var unmarshaller = KeyPairInfoUnmarshaller.Instance;
                        var item         = unmarshaller.Unmarshall(context);
                        response.KeyPairs.Add(item);
                        continue;
                    }
                }
            }

            return(response);
        }
Esempio n. 2
0
        public List <string> descrbibeKeyPairs()
        {
            List <string> keyPairs = new List <string>();

            try
            {
                DescribeKeyPairsRequest  request  = new DescribeKeyPairsRequest();
                DescribeKeyPairsResponse response = _service.DescribeKeyPairs(request);

                if (response.IsSetDescribeKeyPairsResult())
                {
                    DescribeKeyPairsResult describeKeyPairsResult = response.DescribeKeyPairsResult;
                    List <KeyPair>         keyPairList            = describeKeyPairsResult.KeyPair;
                    foreach (KeyPair keyPair in keyPairList)
                    {
                        if (keyPair.IsSetKeyName())
                        {
                            keyPairs.Add(keyPair.KeyName);
                        }
                    }
                }
            }
            catch (AmazonEC2Exception ex)
            {
                throw new Exception("Caught Exception: " + ex.XML);
            }
            return(keyPairs);
        }
Esempio n. 3
0
        private DescribeKeyPairsResponse GetKeyPairs()
        {
            DescribeKeyPairsRequest  request = new DescribeKeyPairsRequest();
            DescribeKeyPairsResponse resp    = ec2.DescribeKeyPairs(request);

            return(resp);
        }
Esempio n. 4
0
        public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems)
        {
            AmazonEC2Config config = new AmazonEC2Config();

            config.RegionEndpoint = region;
            ConfigureClient(config);
            AmazonEC2Client client = new AmazonEC2Client(creds, config);

            DescribeKeyPairsResponse resp = new DescribeKeyPairsResponse();
            DescribeKeyPairsRequest  req  = new DescribeKeyPairsRequest
            {
            };

            resp = client.DescribeKeyPairs(req);
            CheckError(resp.HttpStatusCode, "200");

            foreach (var obj in resp.KeyPairs)
            {
                AddObject(obj);
            }
        }
Esempio n. 5
0
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            DescribeKeyPairsResponse response = new DescribeKeyPairsResponse();

            int targetDepth = 2;

            while (context.Read())
            {
                if (context.IsStartElement || context.IsAttribute)
                {
                    if (context.TestExpression("keySet/item", targetDepth))
                    {
                        response.KeyPairs.Add(KeyPairInfoUnmarshaller.GetInstance().Unmarshall(context));

                        continue;
                    }
                }
            }


            return(response);
        }
        public static DescribeKeyPairsResponse Unmarshall(UnmarshallerContext _ctx)
        {
            DescribeKeyPairsResponse describeKeyPairsResponse = new DescribeKeyPairsResponse();

            describeKeyPairsResponse.HttpResponse = _ctx.HttpResponse;
            describeKeyPairsResponse.RequestId    = _ctx.StringValue("DescribeKeyPairs.RequestId");
            describeKeyPairsResponse.TotalCount   = _ctx.IntegerValue("DescribeKeyPairs.TotalCount");
            describeKeyPairsResponse.PageNumber   = _ctx.IntegerValue("DescribeKeyPairs.PageNumber");
            describeKeyPairsResponse.PageSize     = _ctx.IntegerValue("DescribeKeyPairs.PageSize");

            List <DescribeKeyPairsResponse.DescribeKeyPairs_KeyPair> describeKeyPairsResponse_keyPairs = new List <DescribeKeyPairsResponse.DescribeKeyPairs_KeyPair>();

            for (int i = 0; i < _ctx.Length("DescribeKeyPairs.KeyPairs.Length"); i++)
            {
                DescribeKeyPairsResponse.DescribeKeyPairs_KeyPair keyPair = new DescribeKeyPairsResponse.DescribeKeyPairs_KeyPair();
                keyPair.KeyPairName        = _ctx.StringValue("DescribeKeyPairs.KeyPairs[" + i + "].KeyPairName");
                keyPair.KeyPairFingerPrint = _ctx.StringValue("DescribeKeyPairs.KeyPairs[" + i + "].KeyPairFingerPrint");
                keyPair.CreationTime       = _ctx.StringValue("DescribeKeyPairs.KeyPairs[" + i + "].CreationTime");
                keyPair.ResourceGroupId    = _ctx.StringValue("DescribeKeyPairs.KeyPairs[" + i + "].ResourceGroupId");

                List <DescribeKeyPairsResponse.DescribeKeyPairs_KeyPair.DescribeKeyPairs_Tag> keyPair_tags = new List <DescribeKeyPairsResponse.DescribeKeyPairs_KeyPair.DescribeKeyPairs_Tag>();
                for (int j = 0; j < _ctx.Length("DescribeKeyPairs.KeyPairs[" + i + "].Tags.Length"); j++)
                {
                    DescribeKeyPairsResponse.DescribeKeyPairs_KeyPair.DescribeKeyPairs_Tag tag = new DescribeKeyPairsResponse.DescribeKeyPairs_KeyPair.DescribeKeyPairs_Tag();
                    tag.TagKey   = _ctx.StringValue("DescribeKeyPairs.KeyPairs[" + i + "].Tags[" + j + "].TagKey");
                    tag.TagValue = _ctx.StringValue("DescribeKeyPairs.KeyPairs[" + i + "].Tags[" + j + "].TagValue");

                    keyPair_tags.Add(tag);
                }
                keyPair.Tags = keyPair_tags;

                describeKeyPairsResponse_keyPairs.Add(keyPair);
            }
            describeKeyPairsResponse.KeyPairs = describeKeyPairsResponse_keyPairs;

            return(describeKeyPairsResponse);
        }
        public static DescribeKeyPairsResponse Unmarshall(UnmarshallerContext context)
        {
            DescribeKeyPairsResponse describeKeyPairsResponse = new DescribeKeyPairsResponse();

            describeKeyPairsResponse.HttpResponse = context.HttpResponse;
            describeKeyPairsResponse.RequestId    = context.StringValue("DescribeKeyPairs.RequestId");
            describeKeyPairsResponse.TotalCount   = context.IntegerValue("DescribeKeyPairs.TotalCount");
            describeKeyPairsResponse.PageNumber   = context.IntegerValue("DescribeKeyPairs.PageNumber");
            describeKeyPairsResponse.PageSize     = context.IntegerValue("DescribeKeyPairs.PageSize");

            List <DescribeKeyPairsResponse.DescribeKeyPairs_KeyPair> describeKeyPairsResponse_keyPairs = new List <DescribeKeyPairsResponse.DescribeKeyPairs_KeyPair>();

            for (int i = 0; i < context.Length("DescribeKeyPairs.KeyPairs.Length"); i++)
            {
                DescribeKeyPairsResponse.DescribeKeyPairs_KeyPair keyPair = new DescribeKeyPairsResponse.DescribeKeyPairs_KeyPair();
                keyPair.KeyPairName        = context.StringValue("DescribeKeyPairs.KeyPairs[" + i + "].KeyPairName");
                keyPair.KeyPairFingerPrint = context.StringValue("DescribeKeyPairs.KeyPairs[" + i + "].KeyPairFingerPrint");

                describeKeyPairsResponse_keyPairs.Add(keyPair);
            }
            describeKeyPairsResponse.KeyPairs = describeKeyPairsResponse_keyPairs;

            return(describeKeyPairsResponse);
        }
Esempio n. 8
0
        void MonitorFunction()
        {
            Thread.CurrentThread.Name = "MonitorThread";
            Program.TraceLine("Monitoring thread started...");
            Program.MonitorMessage = "Monitor starting...";
            while (true)
            {
                try
                {
                    //TEST ZONE
                    {
                    }
                    //Now continues normally


                    lock (Ec2Lock) { if (!RunMonitoring)
                                     {
                                         return;
                                     }
                    }
                    DescribeInstancesResponse respEc2 = GetRunningInstances();
                    UpdateClassOfObjects(currentStatusEc2, respEc2.DescribeInstancesResult.Reservation);
                    Program.MonitorMessage = "Updated EC2s...";
                    foreach (ZAwsEc2 ec2Instance in CurrentEc2s)
                    {
                        lock (Ec2Lock) { if (!RunMonitoring)
                                         {
                                             return;
                                         }
                        }
                        ec2Instance.UpdateInfo();
                        Program.MonitorMessage = "Updated EC2 " + ec2Instance.Name;
                    }

                    lock (Ec2Lock) { if (!RunMonitoring)
                                     {
                                         return;
                                     }
                    }
                    DescribeAddressesResponse respElasitIp = GetElasticIps();
                    UpdateClassOfObjects(currentStatusElIps, respElasitIp.DescribeAddressesResult.Address);
                    Program.MonitorMessage = "Updated elastic IPs";

                    lock (Ec2Lock) { if (!RunMonitoring)
                                     {
                                         return;
                                     }
                    }
                    ListHostedZonesResponse route53Zones = GetHostedZones();
                    UpdateClassOfObjects(currentHostedZones, route53Zones.ListHostedZonesResult.HostedZones);
                    Program.MonitorMessage = "Updated hosted zones...";

                    foreach (ZAwsHostedZone zone in CurrentHostedZones)
                    {
                        lock (Ec2Lock) { if (!RunMonitoring)
                                         {
                                             return;
                                         }
                        }
                        zone.UpdateInfo();
                        Program.MonitorMessage = "Updated zone " + zone.Name;
                    }

                    /*
                     * We will not be checking S3 service, because that actually costs money!
                     * lock (Ec2Lock) { if (!RunMonitoring) { return; } }
                     * ListBucketsResponse s3Buckects = GetBuckets();
                     * UpdateClassOfObjects(currentS3Buckets, s3Buckects.Buckets);
                     * Program.MonitorMessage = "Updated S3 Buckets...";
                     * */

                    lock (Ec2Lock) { if (!RunMonitoring)
                                     {
                                         return;
                                     }
                    }
                    DescribeSnapshotsResponse respEc2Snapshots = GetSnapshots();
                    UpdateClassOfObjects(currentSnapshots, respEc2Snapshots.DescribeSnapshotsResult.Snapshot);
                    Program.MonitorMessage = "Updated EC2 Snapshots...";

                    lock (Ec2Lock) { if (!RunMonitoring)
                                     {
                                         return;
                                     }
                    }
                    DescribeKeyPairsResponse respKeyPairs = GetKeyPairs();
                    UpdateClassOfObjects(currentKeyPairs, respKeyPairs.DescribeKeyPairsResult.KeyPair);
                    Program.MonitorMessage = "Updated KeyPairs...";

                    lock (Ec2Lock) { if (!RunMonitoring)
                                     {
                                         return;
                                     }
                    }
                    DescribeSecurityGroupsResponse respSecGroups = GetSecurityGroups();
                    UpdateClassOfObjects(currentSecGroups, respSecGroups.DescribeSecurityGroupsResult.SecurityGroup);
                    Program.MonitorMessage = "Updated Sec Groups...";

                    lock (Ec2Lock) { if (!RunMonitoring)
                                     {
                                         return;
                                     }
                    }
                    DescribeImagesResponse respAmis = GetAmis();
                    UpdateClassOfObjects(currentAmis, respAmis.DescribeImagesResult.Image);
                    Program.MonitorMessage = "Updated AMIs...";

                    lock (Ec2Lock) { if (!RunMonitoring)
                                     {
                                         return;
                                     }
                    }
                    DescribeVolumesResponse respEbsVolumes = GetEbsVolumes();
                    UpdateClassOfObjects(currentEbsVolumes, respEbsVolumes.DescribeVolumesResult.Volume);
                    Program.MonitorMessage = "Updated EBS volumes...";

                    lock (Ec2Lock) { if (!RunMonitoring)
                                     {
                                         return;
                                     }
                    }
                    DescribeSpotInstanceRequestsResponse respSpotRequests = GetSpotRequests();
                    UpdateClassOfObjects(currentSpotRequests, respSpotRequests.DescribeSpotInstanceRequestsResult.SpotInstanceRequest);
                    Program.MonitorMessage = "Updated spot requests...";

                    lock (Ec2Lock) { if (!RunMonitoring)
                                     {
                                         return;
                                     }
                    }

                    if (ThreadInRecovery)
                    {
                        Program.TraceLine("Monitoring working fine again...");
                        ThreadInRecovery = false;
                    }
                }
                catch (Exception ex)
                {
                    Program.TraceLine("Monitoring thread encountered an error. Will restart in {0}...", ex, ThreadInRecovery ? "1 minute" : "5 seconds");
                    Program.MonitorMessage = "Monitor paused...";
                    for (int i = 0; i < (ThreadInRecovery ? 600 : 50); i++)
                    {
                        lock (Ec2Lock) { if (!RunMonitoring)
                                         {
                                             return;
                                         }
                        }
                        Thread.Sleep(100);
                    }
                    Program.TraceLine("Monitoring thread trying to recover...");
                    Program.MonitorMessage = "Monitor restarting...";
                    ThreadInRecovery       = true;
                }
                finally
                {
                    if (!RunMonitoring)
                    {
                        Program.MonitorMessage = "Monitor stopped.";
                    }
                }
            }
        }