Ejemplo n.º 1
0
        public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems)
        {
            AmazonElasticLoadBalancingConfig config = new AmazonElasticLoadBalancingConfig();

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

            DescribeLoadBalancersResponse resp = new DescribeLoadBalancersResponse();

            do
            {
                DescribeLoadBalancersRequest req = new DescribeLoadBalancersRequest
                {
                    Marker = resp.NextMarker
                };

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

                foreach (var obj in resp.LoadBalancerDescriptions)
                {
                    AddObject(obj);
                }
            }while (!string.IsNullOrEmpty(resp.NextMarker));
        }
Ejemplo n.º 2
0
        public void ElasticLoadBalancingDescribeLoadBalancers()
        {
            #region elb-describe-load-balancers-1

            var client   = new AmazonElasticLoadBalancingClient();
            var response = client.DescribeLoadBalancers(new DescribeLoadBalancersRequest
            {
                LoadBalancerNames = new List <string> {
                    "my-load-balancer"
                }
            });

            List <LoadBalancerDescription> loadBalancerDescriptions = response.LoadBalancerDescriptions;

            #endregion
        }
Ejemplo n.º 3
0
        internal static void WriteElbs(DateTime captureTime, string accountId, RegionEndpoint regionEndPoint)
        {
            var elbc        = new AmazonElasticLoadBalancingClient(regionEndPoint);
            var elbResponse = elbc.DescribeLoadBalancers();
            var db          = RedisManager.GetRedisDatabase();

            foreach (var elb in elbResponse.LoadBalancerDescriptions)
            {
                //to do: may not be required.
                //RedisManager.AddSetWithExpiry(string.Format("{0}-lbs", dataKey), string.Format("lbg-{0}", elb.LoadBalancerName), db);

                var elbJson = JsonConvert.SerializeObject(elb);
                //RedisManager.AddWithExpiry(string.Format("{0}-lb-{1}", dataKey, elb.LoadBalancerName), elbJson, db);
                var newDataKey = Common.GetDataKey(captureTime, accountId, regionEndPoint.SystemName);
                var entityKey  = string.Format("{0}-{1}-{2}", newDataKey, "lb", elb.LoadBalancerName);
                Common.UpdateTopology(captureTime, accountId, regionEndPoint.SystemName, "lb", elb.LoadBalancerName, elbJson, "UPDATE");
                //code to add elb name to the instance details
                var latestDataKey      = Common.GetDataKey("latest", accountId, regionEndPoint.SystemName);
                var latestEntitySetKey = string.Format("{0}-{1}set", latestDataKey, "ins");
                foreach (var instance in elb.Instances)
                {
                    //load instance data from redis
                    var latestInstanceKey = RedisManager.GetSetMember(latestEntitySetKey, instance.InstanceId, db);
                    var instanceJson      = db.StringGet(latestInstanceKey.ToString());
                    if (instanceJson.HasValue)
                    {
                        var dataInstance = JsonConvert.DeserializeObject <Data.Instance>(instanceJson);
                        //add elb name to instance
                        dataInstance.ElbKeyName = entityKey;
                        //add the instance data with asg name back to redis
                        instanceJson = JsonConvert.SerializeObject(dataInstance);
                        RedisManager.AddWithExpiry(latestInstanceKey, instanceJson, db);
                    }
                }
            }
        }
        public List <string> GetServers()
        {
            if (ConfigurationManager.AppSettings["AWS_ENV_NAME"] == null)
            {
                throw new ArgumentException("Missing AWS_ENV_NAME app setting");
            }

            if (ConfigurationManager.AppSettings["AWS_REGION"] == null)
            {
                throw new ArgumentException("Missing AWS_REGION app setting");
            }

            var environmentName = ConfigurationManager.AppSettings["AWS_ENV_NAME"];

            RegionEndpoint regionEndpoint = null;

            switch (ConfigurationManager.AppSettings["AWS_REGION"].Trim().ToLower())
            {
            case "us-east-1":
                regionEndpoint = RegionEndpoint.USEast1;
                break;

            case "us-west-1":
                regionEndpoint = RegionEndpoint.USWest1;
                break;

            case "us-west-2":
                regionEndpoint = RegionEndpoint.USWest2;
                break;

            case "eu-west-1":
                regionEndpoint = RegionEndpoint.EUWest1;
                break;

            case "ap-northeast-1":
                regionEndpoint = RegionEndpoint.APNortheast1;
                break;

            case "ap-southeast-1":
                regionEndpoint = RegionEndpoint.APSoutheast1;
                break;

            case "ap-southeast-2":
                regionEndpoint = RegionEndpoint.APSoutheast2;
                break;

            case "sa-east-1":
                regionEndpoint = RegionEndpoint.SAEast1;
                break;

            case "us-gov-west-1":
                regionEndpoint = RegionEndpoint.USGovCloudWest1;
                break;

            case "cn-north-1":
                regionEndpoint = RegionEndpoint.CNNorth1;
                break;
            }

            if (regionEndpoint == null)
            {
                throw new ArgumentException("Incorrect AWS_REGION endpoint");
            }

            // Create client
            var elasticBeanstalkClient = new AmazonElasticBeanstalkClient(regionEndpoint);

            // Get environment resources for environment
            var environmentResourcesRequest = new DescribeEnvironmentResourcesRequest {
                EnvironmentName = environmentName
            };
            var resourceResponse = elasticBeanstalkClient.DescribeEnvironmentResources(environmentResourcesRequest);

            // Create ELB client
            var elasticLoadBalancingClient = new AmazonElasticLoadBalancingClient(regionEndpoint);

            // Get load balancers for all environment's load balancers
            var loadBalancersRequest = new DescribeLoadBalancersRequest();

            foreach (var loadBalancer in resourceResponse.EnvironmentResources.LoadBalancers)
            {
                loadBalancersRequest.LoadBalancerNames.Add(loadBalancer.Name);
            }

            var describeLoadBalancersResponse = elasticLoadBalancingClient.DescribeLoadBalancers(loadBalancersRequest);

            // Create EC2 client
            var ec2Client = new AmazonEC2Client(regionEndpoint);

            // Get instances for all instance ids in all load balancers
            var instancesRequest = new DescribeInstancesRequest();

            // Get all instance ids for all load balancers
            foreach (var instance in describeLoadBalancersResponse.LoadBalancerDescriptions.SelectMany(loadBalancer => loadBalancer.Instances))
            {
                instancesRequest.InstanceIds.Add(instance.InstanceId);
            }

            var instancesResponse = ec2Client.DescribeInstances(instancesRequest);

            // Find all private dns names
            return((from reservation in instancesResponse.Reservations from instance in reservation.Instances select instance.PublicDnsName).ToList());
        }