<s> class ServerGroup ( object ) : <EOL> @ staticmethod <EOL> def name ( elem_sg ) : <EOL> return elem_sg . get ( '<STR_LIT:name>' , None ) <EOL> @ staticmethod <EOL> def server_groups ( elem_sg ) : <EOL> return elem_sg . get ( '<STR_LIT>' , [ ] ) <EOL> @ staticmethod <EOL> def add_group ( elem_sg , group ) : <EOL> if '<STR_LIT>' not in elem_sg : <EOL> elem_sg [ '<STR_LIT>' ] = [ ] <EOL> elem_sg [ '<STR_LIT>' ] . append ( group ) <EOL> group [ '<STR_LIT>' ] = elem_sg <EOL> @ staticmethod <EOL> def clear_parent ( elem_sg ) : <EOL> if '<STR_LIT>' in elem_sg : <EOL> del ( elem_sg [ '<STR_LIT>' ] ) <EOL> @ staticmethod <EOL> def add_server ( elem_sg , server ) : <EOL> if '<STR_LIT>' not in elem_sg : <EOL> elem_sg [ '<STR_LIT>' ] = [ ] <EOL> elem_sg [ '<STR_LIT>' ] . append ( server ) <EOL> @ staticmethod <EOL> def get_server ( sg_list , state , roles , default = None , child = False ) : <EOL> res = None <EOL> for sg in sg_list : <EOL> for server in sg . get ( '<STR_LIT>' , [ ] ) : <EOL> if server [ '<STR_LIT:state>' ] == state and server [ '<STR_LIT>' ] in roles : <EOL> res = server <EOL> break <EOL> if not res : <EOL> res , subgroup = ServerGroup . get_server ( sg . get ( '<STR_LIT>' , [ ] ) , <EOL> state , <EOL> roles ) <EOL> if res : <EOL> zone = sg . get ( '<STR_LIT:name>' , None ) <EOL> return res , zone <EOL> if default : <EOL> return ServerGroup . get_server ( [ default ] , state , roles , None ) <EOL> else : <EOL> return None , None <EOL> @ staticmethod <EOL> def get_zone ( sg_list , server_id , default = None , child = False ) : <EOL> res = None <EOL> for sg in sg_list : <EOL> for server in sg . get ( '<STR_LIT>' , [ ] ) : <EOL> if server [ '<STR_LIT:id>' ] == server_id : <EOL> res = server <EOL> break <EOL> if not res : <EOL> res = ServerGroup . get_zone ( sg . get ( '<STR_LIT>' , [ ] ) , <EOL> server_id ) <EOL> if res : <EOL> zone = sg . get ( '<STR_LIT:name>' , None ) <EOL> return zone <EOL> if default : <EOL> return ServerGroup . get_zone ( [ default ] , server_id , None ) <EOL> else : <EOL> return None <EOL> @ staticmethod <EOL> def networks ( elem_sg ) : <EOL> return elem_sg . get ( '<STR_LIT>' , [ ] ) <EOL> @ staticmethod <EOL> def add_network ( elem_sg , network , net_group ) : <EOL> if '<STR_LIT>' not in elem_sg : <EOL> elem_sg [ '<STR_LIT>' ] = { } <EOL> elem_sg [ '<STR_LIT>' ] [ net_group ] = network <EOL> @ staticmethod <EOL> def find_network ( elem_sg , net_group , default = None ) : <EOL> res = None <EOL> if elem_sg : <EOL> if net_group in elem_sg . get ( '<STR_LIT>' , { } ) : <EOL> res = elem_sg [ '<STR_LIT>' ] [ net_group ] <EOL> elif '<STR_LIT>' in elem_sg : <EOL> res = ServerGroup . find_network ( elem_sg [ '<STR_LIT>' ] , net_group ) <EOL> if res : <EOL> return res <EOL> if default : <EOL> return ServerGroup . find_network ( default , net_group ) <EOL> else : <EOL> return None </s>
