<s> from libcloud . common . base import ConnectionKey , BaseDriver <EOL> from libcloud . common . types import LibcloudError <EOL> __all__ = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> class Member ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , id , ip , port , balancer = None , extra = None ) : <EOL> """<STR_LIT>""" <EOL> self . id = str ( id ) if id else None <EOL> self . ip = ip <EOL> self . port = port <EOL> self . balancer = balancer <EOL> self . extra = extra or { } <EOL> def __repr__ ( self ) : <EOL> return ( '<STR_LIT>' % ( self . id , <EOL> self . ip , self . port ) ) <EOL> class LoadBalancer ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , id , name , state , ip , port , driver , extra = None ) : <EOL> """<STR_LIT>""" <EOL> self . id = str ( id ) if id else None <EOL> self . name = name <EOL> self . state = state <EOL> self . ip = ip <EOL> self . port = port <EOL> self . driver = driver <EOL> self . extra = extra or { } <EOL> def attach_compute_node ( self , node ) : <EOL> return self . driver . balancer_attach_compute_node ( balancer = self , <EOL> node = node ) <EOL> def attach_member ( self , member ) : <EOL> return self . driver . balancer_attach_member ( balancer = self , <EOL> member = member ) <EOL> def detach_member ( self , member ) : <EOL> return self . driver . balancer_detach_member ( balancer = self , <EOL> member = member ) <EOL> def list_members ( self ) : <EOL> return self . driver . balancer_list_members ( balancer = self ) <EOL> def destroy ( self ) : <EOL> return self . driver . destroy_balancer ( balancer = self ) <EOL> def __repr__ ( self ) : <EOL> return ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( self . id , self . name , self . state , self . ip , <EOL> self . port ) ) <EOL> class Algorithm ( object ) : <EOL> """<STR_LIT>""" <EOL> RANDOM = <NUM_LIT:0> <EOL> ROUND_ROBIN = <NUM_LIT:1> <EOL> LEAST_CONNECTIONS = <NUM_LIT:2> <EOL> WEIGHTED_ROUND_ROBIN = <NUM_LIT:3> <EOL> WEIGHTED_LEAST_CONNECTIONS = <NUM_LIT:4> <EOL> SHORTEST_RESPONSE = <NUM_LIT:5> <EOL> PERSISTENT_IP = <NUM_LIT:6> <EOL> DEFAULT_ALGORITHM = Algorithm . ROUND_ROBIN <EOL> class Driver ( BaseDriver ) : <EOL> """<STR_LIT>""" <EOL> name = None <EOL> website = None <EOL> connectionCls = ConnectionKey <EOL> _ALGORITHM_TO_VALUE_MAP = { } <EOL> _VALUE_TO_ALGORITHM_MAP = { } <EOL> def __init__ ( self , key , secret = None , secure = True , host = None , <EOL> port = None , ** kwargs ) : <EOL> super ( Driver , self ) . __init__ ( key = key , secret = secret , secure = secure , <EOL> host = host , port = port , ** kwargs ) <EOL> def list_protocols ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( <EOL> '<STR_LIT>' ) <EOL> def list_balancers ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( <EOL> '<STR_LIT>' ) <EOL> def create_balancer ( self , name , port , protocol , algorithm , members ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( <EOL> '<STR_LIT>' ) <EOL> def destroy_balancer ( self , balancer ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( <EOL> '<STR_LIT>' ) <EOL> def get_balancer ( self , balancer_id ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( <EOL> '<STR_LIT>' ) <EOL> def update_balancer ( self , balancer , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( <EOL> '<STR_LIT>' ) <EOL> def balancer_attach_compute_node ( self , balancer , node ) : <EOL> """<STR_LIT>""" <EOL> member = Member ( id = None , ip = node . public_ips [ <NUM_LIT:0> ] , port = balancer . port ) <EOL> return self . balancer_attach_member ( balancer , member ) <EOL> def balancer_attach_member ( self , balancer , member ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( <EOL> '<STR_LIT>' ) <EOL> def balancer_detach_member ( self , balancer , member ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( <EOL> '<STR_LIT>' ) <EOL> def balancer_list_members ( self , balancer ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( <EOL> '<STR_LIT>' ) <EOL> def list_supported_algorithms ( self ) : <EOL> """<STR_LIT>""" <EOL> return list ( self . _ALGORITHM_TO_VALUE_MAP . keys ( ) ) <EOL> def _value_to_algorithm ( self , value ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return self . _VALUE_TO_ALGORITHM_MAP [ value ] <EOL> except KeyError : <EOL> raise LibcloudError ( value = '<STR_LIT>' % ( value ) , <EOL> driver = self ) <EOL> def _algorithm_to_value ( self , algorithm ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return self . _ALGORITHM_TO_VALUE_MAP [ algorithm ] <EOL> except KeyError : <EOL> raise LibcloudError ( value = '<STR_LIT>' % ( algorithm ) , <EOL> driver = self ) </s>
