<s> """<STR_LIT>""" <EOL> from boto . connection import AWSQueryConnection <EOL> from boto . ec2 . instanceinfo import InstanceInfo <EOL> from boto . ec2 . elb . loadbalancer import LoadBalancer <EOL> from boto . ec2 . elb . instancestate import InstanceState <EOL> from boto . ec2 . elb . healthcheck import HealthCheck <EOL> from boto . regioninfo import RegionInfo <EOL> import boto <EOL> RegionData = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> def regions ( ) : <EOL> """<STR_LIT>""" <EOL> regions = [ ] <EOL> for region_name in RegionData : <EOL> region = RegionInfo ( name = region_name , <EOL> endpoint = RegionData [ region_name ] , <EOL> connection_cls = ELBConnection ) <EOL> regions . append ( region ) <EOL> return regions <EOL> def connect_to_region ( region_name , ** kw_params ) : <EOL> """<STR_LIT>""" <EOL> for region in regions ( ) : <EOL> if region . name == region_name : <EOL> return region . connect ( ** kw_params ) <EOL> return None <EOL> class ELBConnection ( AWSQueryConnection ) : <EOL> APIVersion = boto . config . get ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> DefaultRegionName = boto . config . get ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> DefaultRegionEndpoint = boto . config . get ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> def __init__ ( self , aws_access_key_id = None , aws_secret_access_key = None , <EOL> is_secure = False , port = None , proxy = None , proxy_port = None , <EOL> proxy_user = None , proxy_pass = None , debug = <NUM_LIT:0> , <EOL> https_connection_factory = None , region = None , path = '<STR_LIT:/>' ) : <EOL> """<STR_LIT>""" <EOL> if not region : <EOL> region = RegionInfo ( self , self . DefaultRegionName , <EOL> self . DefaultRegionEndpoint ) <EOL> self . region = region <EOL> AWSQueryConnection . __init__ ( self , aws_access_key_id , <EOL> aws_secret_access_key , <EOL> is_secure , port , proxy , proxy_port , <EOL> proxy_user , proxy_pass , <EOL> self . region . endpoint , debug , <EOL> https_connection_factory , path ) <EOL> def _required_auth_capability ( self ) : <EOL> return [ '<STR_LIT>' ] <EOL> def build_list_params ( self , params , items , label ) : <EOL> if isinstance ( items , str ) : <EOL> items = [ items ] <EOL> for index , item in enumerate ( items ) : <EOL> params [ label % ( index + <NUM_LIT:1> ) ] = item <EOL> def get_all_load_balancers ( self , load_balancer_names = None ) : <EOL> """<STR_LIT>""" <EOL> params = { } <EOL> if load_balancer_names : <EOL> self . build_list_params ( params , load_balancer_names , <EOL> '<STR_LIT>' ) <EOL> return self . get_list ( '<STR_LIT>' , params , <EOL> [ ( '<STR_LIT>' , LoadBalancer ) ] ) <EOL> def create_load_balancer ( self , name , zones , listeners ) : <EOL> """<STR_LIT>""" <EOL> params = { '<STR_LIT>' : name } <EOL> for index , listener in enumerate ( listeners ) : <EOL> i = index + <NUM_LIT:1> <EOL> params [ '<STR_LIT>' % i ] = listener [ <NUM_LIT:0> ] <EOL> params [ '<STR_LIT>' % i ] = listener [ <NUM_LIT:1> ] <EOL> params [ '<STR_LIT>' % i ] = listener [ <NUM_LIT:2> ] <EOL> if listener [ <NUM_LIT:2> ] == '<STR_LIT>' : <EOL> params [ '<STR_LIT>' % i ] = listener [ <NUM_LIT:3> ] <EOL> self . build_list_params ( params , zones , '<STR_LIT>' ) <EOL> load_balancer = self . get_object ( '<STR_LIT>' , <EOL> params , LoadBalancer ) <EOL> load_balancer . name = name <EOL> load_balancer . listeners = listeners <EOL> load_balancer . availability_zones = zones <EOL> return load_balancer <EOL> def create_load_balancer_listeners ( self , name , listeners ) : <EOL> """<STR_LIT>""" <EOL> params = { '<STR_LIT>' : name } <EOL> for index , listener in enumerate ( listeners ) : <EOL> i = index + <NUM_LIT:1> <EOL> params [ '<STR_LIT>' % i ] = listener [ <NUM_LIT:0> ] <EOL> params [ '<STR_LIT>' % i ] = listener [ <NUM_LIT:1> ] <EOL> params [ '<STR_LIT>' % i ] = listener [ <NUM_LIT:2> ] <EOL> if listener [ <NUM_LIT:2> ] == '<STR_LIT>' : <EOL> params [ '<STR_LIT>' % i ] = listener [ <NUM_LIT:3> ] <EOL> return self . get_status ( '<STR_LIT>' , params ) <EOL> def delete_load_balancer ( self , name ) : <EOL> """<STR_LIT>""" <EOL> params = { '<STR_LIT>' : name } <EOL> return self . get_status ( '<STR_LIT>' , params ) <EOL> def delete_load_balancer_listeners ( self , name , ports ) : <EOL> """<STR_LIT>""" <EOL> params = { '<STR_LIT>' : name } <EOL> for index , port in enumerate ( ports ) : <EOL> params [ '<STR_LIT>' % ( index + <NUM_LIT:1> ) ] = port <EOL> return self . get_status ( '<STR_LIT>' , params ) <EOL> def enable_availability_zones ( self , load_balancer_name , zones_to_add ) : <EOL> """<STR_LIT>""" <EOL> params = { '<STR_LIT>' : load_balancer_name } <EOL> self . build_list_params ( params , zones_to_add , <EOL> '<STR_LIT>' ) <EOL> return self . get_list ( '<STR_LIT>' , <EOL> params , None ) <EOL> def disable_availability_zones ( self , load_balancer_name , zones_to_remove ) : <EOL> """<STR_LIT>""" <EOL> params = { '<STR_LIT>' : load_balancer_name } <EOL> self . build_list_params ( params , zones_to_remove , <EOL> '<STR_LIT>' ) <EOL> return self . get_list ( '<STR_LIT>' , <EOL> params , None ) <EOL> def register_instances ( self , load_balancer_name , instances ) : <EOL> """<STR_LIT>""" <EOL> params = { '<STR_LIT>' : load_balancer_name } <EOL> self . build_list_params ( params , instances , <EOL> '<STR_LIT>' ) <EOL> return self . get_list ( '<STR_LIT>' , <EOL> params , [ ( '<STR_LIT>' , InstanceInfo ) ] ) <EOL> def deregister_instances ( self , load_balancer_name , instances ) : <EOL> """<STR_LIT>""" <EOL> params = { '<STR_LIT>' : load_balancer_name } <EOL> self . build_list_params ( params , instances , <EOL> '<STR_LIT>' ) <EOL> return self . get_list ( '<STR_LIT>' , <EOL> params , [ ( '<STR_LIT>' , InstanceInfo ) ] ) <EOL> def describe_instance_health ( self , load_balancer_name , instances = None ) : <EOL> """<STR_LIT>""" <EOL> params = { '<STR_LIT>' : load_balancer_name } <EOL> if instances : <EOL> self . build_list_params ( params , instances , <EOL> '<STR_LIT>' ) <EOL> return self . get_list ( '<STR_LIT>' , params , <EOL> [ ( '<STR_LIT>' , InstanceState ) ] ) <EOL> def configure_health_check ( self , name , health_check ) : <EOL> """<STR_LIT>""" <EOL> params = { '<STR_LIT>' : name , <EOL> '<STR_LIT>' : health_check . timeout , <EOL> '<STR_LIT>' : health_check . target , <EOL> '<STR_LIT>' : health_check . interval , <EOL> '<STR_LIT>' : health_check . unhealthy_threshold , <EOL> '<STR_LIT>' : health_check . healthy_threshold } <EOL> return self . get_object ( '<STR_LIT>' , params , HealthCheck ) <EOL> def set_lb_listener_SSL_certificate ( self , lb_name , lb_port , <EOL> ssl_certificate_id ) : <EOL> """<STR_LIT>""" <EOL> params = { <EOL> '<STR_LIT>' : lb_name , <EOL> '<STR_LIT>' : lb_port , <EOL> '<STR_LIT>' : ssl_certificate_id , <EOL> } <EOL> return self . get_status ( '<STR_LIT>' , params ) <EOL> def create_app_cookie_stickiness_policy ( self , name , lb_name , policy_name ) : <EOL> """<STR_LIT>""" <EOL> params = { <EOL> '<STR_LIT>' : name , <EOL> '<STR_LIT>' : lb_name , <EOL> '<STR_LIT>' : policy_name , <EOL> } <EOL> return self . get_status ( '<STR_LIT>' , params ) <EOL> def create_lb_cookie_stickiness_policy ( self , cookie_expiration_period , <EOL> lb_name , policy_name ) : <EOL> """<STR_LIT>""" <EOL> params = { <EOL> '<STR_LIT>' : cookie_expiration_period , <EOL> '<STR_LIT>' : lb_name , <EOL> '<STR_LIT>' : policy_name , <EOL> } <EOL> return self . get_status ( '<STR_LIT>' , params ) <EOL> def delete_lb_policy ( self , lb_name , policy_name ) : <EOL> """<STR_LIT>""" <EOL> params = { <EOL> '<STR_LIT>' : lb_name , <EOL> '<STR_LIT>' : policy_name , <EOL> } <EOL> return self . get_status ( '<STR_LIT>' , params ) <EOL> def set_lb_policies_of_listener ( self , lb_name , lb_port , policies ) : <EOL> """<STR_LIT>""" <EOL> params = { <EOL> '<STR_LIT>' : lb_name , <EOL> '<STR_LIT>' : lb_port , <EOL> } <EOL> self . build_list_params ( params , policies , '<STR_LIT>' ) <EOL> return self . get_status ( '<STR_LIT>' , params ) </s>
