Esempio n. 1
0
        //public async Task<string> CreateLoadBalancer(
        //    string name, List<string> securityGroups, List<string> subnets)
        //{
        //    var request = new CreateLoadBalancerRequest()
        //    {
        //        LoadBalancerName = name,
        //        SecurityGroups = securityGroups,
        //        Subnets = subnets,

        //        IpAddressType = IpAddressType.Ipv4,
        //        Scheme = LoadBalancerSchemeEnum.InternetFacing,
        //        //Type = LoadBalancerTypeEnum.Application
        //    };
        //    var response = await client.CreateLoadBalancerAsync(request);

        //    return response.LoadBalancers[0].LoadBalancerArn;
        //}

        public async Task <List <SA_LoadBalancer> > GetLoadBalancerList()
        {
            List <SA_LoadBalancer> lstLoadBalancers = new List <SA_LoadBalancer>();
            var request  = new DescribeLoadBalancersRequest();
            var response = await client.DescribeLoadBalancersAsync(request);

            var lstSourceELBs = response.LoadBalancerDescriptions;
            var reqTags       = new DescribeTagsRequest()
            {
                LoadBalancerNames = response.LoadBalancerDescriptions.Select(o => o.LoadBalancerName).ToList()
            };
            var respTags = await client.DescribeTagsAsync(reqTags);

            //LoadBalancer name like "awseb-e-c-AWSEBLoa-G25T4NILK22Q", need to get name from tag.
            foreach (var sourceELB in lstSourceELBs)
            {
                string tagName = string.Empty;
                //try
                //{
                //    var tags = respTags.TagDescriptions.Find
                //    (o => o.LoadBalancerName == sourceELB.LoadBalancerName).Tags.Find(o => o.Key == "Name").Value;
                //}
                //catch
                //{
                //    continue;
                //}
                var tags = respTags.TagDescriptions.Find
                               (o => o.LoadBalancerName == sourceELB.LoadBalancerName).Tags;
                var nameTag = tags.Find(o => o.Key == "Name");
                if (nameTag == null)
                {
                    continue;
                }

                tagName = nameTag.Value;
                if (!(tagName.IndexOf($"{environment}-{color}") == 0))   //check
                {
                    continue;
                }
                var elb = ModelTransformer <LoadBalancerDescription, SA_LoadBalancer> .
                          TransformAwsModelToSafeArrivalModel(sourceELB);

                elb.LoadBalancerName = tagName;
                lstLoadBalancers.Add(elb);
            }

            //lstLoadBalancers = lstLoadBalancers.FindAll(o => o.LoadBalancerName.Contains($"{environment}-"));
            return(lstLoadBalancers);
        }