def create_load_balancer_policy(self): load_balancer_name = self._get_param('LoadBalancerName') other_policy = OtherPolicy() policy_name = self._get_param("PolicyName") other_policy.policy_name = policy_name self.elb_backend.create_lb_other_policy(load_balancer_name, other_policy) template = self.response_template(CREATE_LOAD_BALANCER_POLICY_TEMPLATE) return template.render()
def create_from_cloudformation_json( cls, resource_name, cloudformation_json, region_name ): properties = cloudformation_json["Properties"] elb_backend = elb_backends[region_name] new_elb = elb_backend.create_load_balancer( name=properties.get("LoadBalancerName", resource_name), zones=properties.get("AvailabilityZones", []), ports=properties["Listeners"], scheme=properties.get("Scheme", "internet-facing"), ) instance_ids = properties.get("Instances", []) for instance_id in instance_ids: elb_backend.register_instances(new_elb.name, [instance_id]) policies = properties.get("Policies", []) port_policies = {} for policy in policies: policy_name = policy["PolicyName"] other_policy = OtherPolicy() other_policy.policy_name = policy_name elb_backend.create_lb_other_policy(new_elb.name, other_policy) for port in policy.get("InstancePorts", []): policies_for_port = port_policies.get(port, set()) policies_for_port.add(policy_name) port_policies[port] = policies_for_port for port, policies in port_policies.items(): elb_backend.set_load_balancer_policies_of_backend_server( new_elb.name, port, list(policies) ) health_check = properties.get("HealthCheck") if health_check: elb_backend.configure_health_check( load_balancer_name=new_elb.name, timeout=health_check["Timeout"], healthy_threshold=health_check["HealthyThreshold"], unhealthy_threshold=health_check["UnhealthyThreshold"], interval=health_check["Interval"], target=health_check["Target"], ) return new_elb
def create_from_cloudformation_json(cls, resource_name, cloudformation_json, region_name): properties = cloudformation_json['Properties'] elb_backend = elb_backends[region_name] new_elb = elb_backend.create_load_balancer( name=properties.get('LoadBalancerName', resource_name), zones=properties.get('AvailabilityZones', []), ports=properties['Listeners'], scheme=properties.get('Scheme', 'internet-facing'), ) instance_ids = properties.get('Instances', []) for instance_id in instance_ids: elb_backend.register_instances(new_elb.name, [instance_id]) policies = properties.get('Policies', []) port_policies = {} for policy in policies: policy_name = policy["PolicyName"] other_policy = OtherPolicy() other_policy.policy_name = policy_name elb_backend.create_lb_other_policy(new_elb.name, other_policy) for port in policy.get("InstancePorts", []): policies_for_port = port_policies.get(port, set()) policies_for_port.add(policy_name) port_policies[port] = policies_for_port for port, policies in port_policies.items(): elb_backend.set_load_balancer_policies_of_backend_server( new_elb.name, port, list(policies)) health_check = properties.get('HealthCheck') if health_check: elb_backend.configure_health_check( load_balancer_name=new_elb.name, timeout=health_check['Timeout'], healthy_threshold=health_check['HealthyThreshold'], unhealthy_threshold=health_check['UnhealthyThreshold'], interval=health_check['Interval'], target=health_check['Target'], ) return new_elb