示例#1
0
        public static async Task DestroyLoadBalancer(this ELBHelper elbh, string loadBalancerName, bool throwIfNotFound, CancellationToken cancellationToken = default(CancellationToken))
        {
            var loadbalancers = await elbh.GetLoadBalancersByName(loadBalancerName, throwIfNotFound, cancellationToken);

            if (loadbalancers.Count() != 1)
            {
                if (throwIfNotFound)
                {
                    throw new Exception($"DestroyLoadBalancer, LoadBalancer '{loadBalancerName}' was not found, or multiple load balancers with the same name were found.");
                }
                else
                {
                    return;
                }
            }

            var arn       = loadbalancers.First().LoadBalancerArn;
            var listeners = await elbh.ListListenersAsync(arn, cancellationToken);

            var targetGroups = await elbh.ListTargetGroupsAsync(arn, cancellationToken : cancellationToken);

            //kill listeners
            await elbh.DeleteListenersAsync(listeners, cancellationToken);

            //kill target groups
            await elbh.DeleteTargetGroupsAsync(targetGroups, cancellationToken);

            //kill loadbalancer
            await elbh.DeleteLoadBalancersAsync(new List <string>() { arn }, cancellationToken);
        }
示例#2
0
        public static async Task <IEnumerable <TargetGroup> > DescribeLoadBalancerTargetGroupsAsync(
            this ELBHelper elbh,
            string loadBalancerName,
            bool thowIfNotFound,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            var loadbalancer = (await elbh.GetLoadBalancersByName(loadBalancerName, thowIfNotFound, cancellationToken)).SingleOrDefault();

            if (!thowIfNotFound)
            {
                return(null);
            }

            return(await elbh.DescribeTargetGroupsAsync(loadBalancerArn : loadbalancer.LoadBalancerArn, cancellationToken : cancellationToken));
        }