def passed_softfailure_detector()

in application-load-balancer-copy-utility/copy_classic_load_balancer.py [0:0]


def passed_softfailure_detector(elb_data):
    if debug:
        print('Checking soft failure detector')
    # error will change to True if any failure conditions are found
     # 1. If The expiration period of Duration-Based stickiness policy is more than 7 days,
     # we will override its value to 7 day.
    error = None
    for elb_listener in elb_data['LoadBalancerDescriptions'][0]['ListenerDescriptions']:
        if len(elb_listener['PolicyNames']) > 0:
            if 'LBCookieStickinessPolicy' in elb_listener['PolicyNames'][0]:
                for policy in elb_data['PolicyDescriptions']:
                    if elb_listener['PolicyNames'][0] in policy.values():
                        # Check if the expiration period  is larger than 7 days
                        if int(policy['PolicyAttributeDescriptions'][0]['AttributeValue']) > 604800:
                            # Overide the expiration to 7days
                            policy['PolicyAttributeDescriptions'][0]['AttributeValue'] = '604800'
                            print("The maximum expiration period of "
                                  "Duration-Based stickiness policy that Application "
                                  "Load Balancer supports is 7 days."
                                  "Your Application Load Balancer will be created with "
                                  "7-day expiration period Duration-Based stickiness policy.")
    # 2. If unsupported policy attribute is detected we prompt user if we want
    # to continue.
    supported_attributes = [
        'ConnectionDraining', 'CrossZoneLoadBalancing', 'ConnectionSettings', 'AccessLog']
    for key in elb_data['LoadBalancerAttributes']:
        if key not in supported_attributes:
            answer = input(
                "{} is not supported for an Application Load Balancer. "
                "Continue anyway? (y/n)".format(key))
            if answer.lower() == 'y':
                pass
            else:
                print(
                    "We will not create an Application Load Balancer. Stopping the script.")
                error = True
    # 3. Check for AWS reserved tag
    if len(elb_data['TagDescriptions']) > 0:
        #this creates a copy of the list and
        # allows us to iterate over the copy so we cand modify the original
        for tag in elb_data['TagDescriptions'][0]['Tags'][:]:
            if tag['Key'].startswith('aws:'):
                print("AWS reserved tag is in use. The aws: prefix in your tag names or "
                      "values because it is reserved for AWS use -- "
                      "http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/"
                      "Using_Tags.html#tag-restrictions")
                print('Tag key: {}'.format(tag['Key']))
                answer = input(
                    "Do you want to proceed without AWS reserved tag? y/n ")
                if answer.lower() == 'y':
                    elb_data['TagDescriptions'][0]['Tags'].remove(tag)
                    pass
                else:
                    print(
                        "We will not clone the ELB to an "
                        "Application Load Balancer. stopping script.")
                    error = True
    if error:
        return False
    else:
        return True