<s> import re <EOL> from systems . models import System <EOL> from migrate_dns . utils import * <EOL> import pprint <EOL> pp = pprint . PrettyPrinter ( indent = <NUM_LIT:2> ) <EOL> nic_nums = re . compile ( "<STR_LIT>" ) <EOL> is_mac_key = re . compile ( "<STR_LIT>" ) <EOL> is_hostname_key = re . compile ( "<STR_LIT>" ) <EOL> is_ip_key = re . compile ( "<STR_LIT>" ) <EOL> is_dns_auto_build_key = re . compile ( "<STR_LIT>" ) <EOL> is_dns_auto_hostname_key = re . compile ( "<STR_LIT>" ) <EOL> is_dns_has_conflict_key = re . compile ( "<STR_LIT>" ) <EOL> is_some_key = re . compile ( "<STR_LIT>" ) <EOL> def build_nic ( sub_nic ) : <EOL> intr = Interface ( sub_nic [ <NUM_LIT:0> ] . system , sub_nic ) <EOL> for nic_data in sub_nic : <EOL> if is_mac_key . match ( nic_data . key ) : <EOL> if intr . mac is not None : <EOL> log ( "<STR_LIT:!>" * <NUM_LIT:20> , WARNING ) <EOL> log ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> . format ( intr . system , intr . system . pk ) , WARNING ) <EOL> log ( pp . pformat ( sub_nic ) , WARNING ) <EOL> intr . mac = nic_data . value <EOL> intr . keys . append ( '<STR_LIT>' ) <EOL> continue <EOL> if is_hostname_key . match ( nic_data . key ) : <EOL> if intr . hostname is not None : <EOL> log ( "<STR_LIT:!>" * <NUM_LIT:20> , WARNING ) <EOL> log ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> . format ( intr . system , intr . system . pk ) , WARNING ) <EOL> log ( pp . pformat ( sub_nic ) , WARNING ) <EOL> intr . hostname = nic_data . value <EOL> intr . keys . append ( '<STR_LIT>' ) <EOL> continue <EOL> if is_ip_key . match ( nic_data . key ) : <EOL> intr . ips . append ( nic_data . value ) <EOL> continue <EOL> if is_dns_auto_build_key . match ( nic_data . key ) : <EOL> if nic_data . value == '<STR_LIT:False>' : <EOL> intr . dns_auto_build = False <EOL> continue <EOL> if is_dns_auto_hostname_key . match ( nic_data . key ) : <EOL> if nic_data . value == '<STR_LIT:False>' : <EOL> intr . dns_auto_hostname = False <EOL> continue <EOL> if is_dns_has_conflict_key . match ( nic_data . key ) : <EOL> if nic_data . value == '<STR_LIT:True>' : <EOL> intr . dns_has_conflict = True <EOL> else : <EOL> intr . dns_has_conflict = False <EOL> continue <EOL> tmp = is_some_key . match ( nic_data . key ) <EOL> if tmp : <EOL> if hasattr ( intr , tmp . group ( <NUM_LIT:1> ) ) : <EOL> setattr ( intr , tmp . group ( <NUM_LIT:1> ) , [ nic_data . value , <EOL> getattr ( intr , tmp . group ( <NUM_LIT:1> ) ) ] ) <EOL> intr . keys . append ( tmp . group ( s ) ) <EOL> else : <EOL> setattr ( intr , tmp . group ( <NUM_LIT:1> ) , nic_data . value ) <EOL> if intr . hostname is None : <EOL> log ( "<STR_LIT>" <EOL> "<STR_LIT>" . format ( print_system ( intr . system ) , intr . primary , <EOL> intr . alias ) , ERROR ) <EOL> intr . hostname = intr . system . hostname <EOL> return intr <EOL> def get_nic_objs ( ) : <EOL> """<STR_LIT>""" <EOL> systems = System . objects . all ( ) <EOL> formated_nics = [ ] <EOL> for system in systems : <EOL> raw_nics = system . keyvalue_set . all ( ) <EOL> if not raw_nics : <EOL> continue <EOL> formated_nics . append ( transform_nics ( raw_nics ) ) <EOL> interfaces = [ ] <EOL> for system_nics in formated_nics : <EOL> for primary_nic_number , primary_nic in system_nics . items ( ) : <EOL> for sub_nic_number , sub_nic in primary_nic [ '<STR_LIT>' ] . items ( ) : <EOL> interface = build_nic ( sub_nic ) <EOL> if not interface : <EOL> continue <EOL> interfaces . append ( interface ) <EOL> return interfaces <EOL> def build_nics_from_system ( system ) : <EOL> """<STR_LIT>""" <EOL> raw_nics = system . keyvalue_set . all ( ) <EOL> formated_nics = transform_nics ( raw_nics ) <EOL> interfaces = [ ] <EOL> for primary_nic_number , primary_nic in formated_nics . items ( ) : <EOL> for sub_nic_number , sub_nic in primary_nic [ '<STR_LIT>' ] . items ( ) : <EOL> interface = build_nic ( sub_nic ) <EOL> if not interface : <EOL> continue <EOL> interfaces . append ( interface ) <EOL> return interfaces <EOL> def get_dns_data ( ) : <EOL> dns_data , nic_objs = _get_dns_data ( ) <EOL> return dns_data <EOL> get_nic_primary_number = re . compile ( "<STR_LIT>" ) <EOL> def transform_nics ( nics ) : <EOL> """<STR_LIT>""" <EOL> formated_nics = _build_primary_nics ( nics ) <EOL> for nic_number , nics in formated_nics . items ( ) : <EOL> formated_nics [ nic_number ] [ '<STR_LIT>' ] = _build_sub_nics ( nics ) <EOL> formated_nics [ nic_number ] . pop ( '<STR_LIT>' ) <EOL> return formated_nics <EOL> def _build_primary_nics ( all_nics ) : <EOL> """<STR_LIT>""" <EOL> primary_nics = { } <EOL> for nic in all_nics : <EOL> if not isinstance ( nic . key , basestring ) : <EOL> log ( "<STR_LIT:=>" * <NUM_LIT:15> , DEBUG ) <EOL> log ( "<STR_LIT>" <EOL> "<STR_LIT>" . format ( nic . system , nic ) , DEBUG ) <EOL> log ( print_system ( nic . system ) , DEBUG ) <EOL> continue <EOL> possible_primary_nic = get_nic_primary_number . match ( nic . key ) <EOL> if not possible_primary_nic : <EOL> log ( "<STR_LIT:=>" * <NUM_LIT:15> , DEBUG ) <EOL> log ( "<STR_LIT>" <EOL> "<STR_LIT>" . format ( nic . system , nic ) , DEBUG ) <EOL> log ( print_system ( nic . system ) , DEBUG ) <EOL> continue <EOL> primary_nic_number = possible_primary_nic . group ( <NUM_LIT:1> ) <EOL> if primary_nic_number in primary_nics : <EOL> primary_nics [ primary_nic_number ] [ '<STR_LIT>' ] . append ( nic ) <EOL> else : <EOL> primary_nics [ primary_nic_number ] = { '<STR_LIT>' : [ nic ] } <EOL> return primary_nics <EOL> get_nic_sub_number = re . compile ( "<STR_LIT>" ) <EOL> def _build_sub_nics ( all_nics ) : <EOL> """<STR_LIT>""" <EOL> sub_nics = { } <EOL> for nic in all_nics [ '<STR_LIT>' ] : <EOL> possible_sub_nic = get_nic_sub_number . match ( nic . key ) <EOL> if not possible_sub_nic : <EOL> log ( "<STR_LIT>" <EOL> "<STR_LIT>" . format ( nic . system , nic . key ) , DEBUG ) <EOL> continue <EOL> sub_nic_number = possible_sub_nic . group ( <NUM_LIT:1> ) <EOL> if sub_nic_number in sub_nics : <EOL> sub_nics [ sub_nic_number ] . append ( nic ) <EOL> else : <EOL> sub_nics [ sub_nic_number ] = [ nic ] <EOL> return sub_nics </s>
