<s> import six <EOL> from ... util import Util <EOL> from . lbserver import LbServer <EOL> import saklient <EOL> str = six . text_type <EOL> class LbVirtualIp ( object ) : <EOL> def get_virtual_ip_address ( self ) : <EOL> return self . _virtual_ip_address <EOL> def set_virtual_ip_address ( self , v ) : <EOL> Util . validate_type ( v , "<STR_LIT:str>" ) <EOL> self . _virtual_ip_address = v <EOL> return self . _virtual_ip_address <EOL> virtual_ip_address = property ( get_virtual_ip_address , set_virtual_ip_address , None ) <EOL> def get_port ( self ) : <EOL> return self . _port <EOL> def set_port ( self , v ) : <EOL> Util . validate_type ( v , "<STR_LIT:int>" ) <EOL> self . _port = v <EOL> return self . _port <EOL> port = property ( get_port , set_port , None ) <EOL> def get_delay_loop ( self ) : <EOL> return self . _delay_loop <EOL> def set_delay_loop ( self , v ) : <EOL> Util . validate_type ( v , "<STR_LIT:int>" ) <EOL> self . _delay_loop = v <EOL> return self . _delay_loop <EOL> delay_loop = property ( get_delay_loop , set_delay_loop , None ) <EOL> def get_servers ( self ) : <EOL> return self . _servers <EOL> servers = property ( get_servers , None , None ) <EOL> def __init__ ( self , obj = None ) : <EOL> if obj is None : <EOL> obj = { } <EOL> vip = Util . get_by_path_any ( [ obj ] , [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> self . _virtual_ip_address = vip <EOL> port = Util . get_by_path_any ( [ obj ] , [ "<STR_LIT>" , "<STR_LIT:port>" ] ) <EOL> self . _port = None <EOL> if port is not None : <EOL> self . _port = int ( port ) <EOL> if self . _port == <NUM_LIT:0> : <EOL> self . _port = None <EOL> delayLoop = Util . get_by_path_any ( [ obj ] , [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> self . _delay_loop = None <EOL> if delayLoop is not None : <EOL> self . _delay_loop = int ( delayLoop ) <EOL> if self . _delay_loop == <NUM_LIT:0> : <EOL> self . _delay_loop = None <EOL> self . _servers = [ ] <EOL> serversDyn = Util . get_by_path_any ( [ obj ] , [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> if serversDyn is not None : <EOL> servers = serversDyn <EOL> for server in servers : <EOL> self . _servers . append ( LbServer ( server ) ) <EOL> def add_server ( self , settings = None ) : <EOL> ret = LbServer ( settings ) <EOL> self . _servers . append ( ret ) <EOL> return ret <EOL> def to_raw_settings ( self ) : <EOL> servers = [ ] <EOL> for server in self . _servers : <EOL> servers . append ( server . to_raw_settings ( ) ) <EOL> return { <EOL> '<STR_LIT>' : self . _virtual_ip_address , <EOL> '<STR_LIT>' : self . _port , <EOL> '<STR_LIT>' : self . _delay_loop , <EOL> '<STR_LIT>' : servers <EOL> } <EOL> def get_server_by_address ( self , address ) : <EOL> Util . validate_type ( address , "<STR_LIT:str>" ) <EOL> for srv in self . _servers : <EOL> if srv . ip_address == address : <EOL> return srv <EOL> return None <EOL> def remove_server_by_address ( self , address ) : <EOL> Util . validate_type ( address , "<STR_LIT:str>" ) <EOL> servers = [ ] <EOL> for srv in self . _servers : <EOL> if srv . ip_address != address : <EOL> servers . append ( srv ) <EOL> self . _servers = servers <EOL> return self <EOL> def update_status ( self , srvs ) : <EOL> Util . validate_type ( srvs , "<STR_LIT:list>" ) <EOL> for srvDyn in srvs : <EOL> ip = ( srvDyn [ "<STR_LIT>" ] if "<STR_LIT>" in srvDyn else None ) <EOL> srv = self . get_server_by_address ( ip ) <EOL> if srv is None : <EOL> next <EOL> srv . update_status ( srvDyn ) <EOL> return self </s>
