<s> __import__ ( '<STR_LIT>' ) <EOL> import sys <EOL> from core . site . models import Site <EOL> from core . vlan . models import Vlan <EOL> from core . network . models import Network , NetworkKeyValue <EOL> def ensure_site ( site_name ) : <EOL> for s in reversed ( site_name . split ( '<STR_LIT:.>' ) ) : <EOL> site , _ = Site . objects . get_or_create ( full_name = s ) <EOL> return site <EOL> def ensure_vlan ( vlan_number , vlan_name ) : <EOL> if not ( vlan_number and vlan_name ) : <EOL> return None <EOL> v , _ = Vlan . objects . get_or_create ( number = vlan_number , name = vlan_name ) <EOL> return v <EOL> def ensure_network ( site , vlan , network_str , sec_zone ) : <EOL> ip_type = '<STR_LIT>' if network_str . find ( '<STR_LIT:.>' ) == - <NUM_LIT:1> else '<STR_LIT:4>' <EOL> if ip_type == '<STR_LIT:4>' : <EOL> network_addr , mask = network_str . split ( '<STR_LIT:/>' ) <EOL> octets = network_addr . split ( '<STR_LIT:.>' ) <EOL> while len ( octets ) != <NUM_LIT:4> : <EOL> octets . append ( '<STR_LIT:0>' ) <EOL> network_str = '<STR_LIT:.>' . join ( octets ) + '<STR_LIT:/>' + mask <EOL> n , _ = Network . objects . get_or_create ( <EOL> network_str = network_str , ip_type = ip_type <EOL> ) <EOL> n . vlan = vlan <EOL> n . site = site <EOL> n . save ( ) if vlan or site else <NUM_LIT:0> <EOL> return n <EOL> with open ( sys . argv [ <NUM_LIT:1> ] , '<STR_LIT:r>' ) as fd : <EOL> for line in fd . readlines ( ) [ <NUM_LIT:1> : ] : <EOL> ( site_name , vlan_number , sec_zone , vlan_name , <EOL> network_str ) = line . strip ( '<STR_LIT:\n>' ) . split ( '<STR_LIT:U+002C>' ) <EOL> print '<STR_LIT>' <EOL> print ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( site_name , vlan_number , sec_zone , <EOL> vlan_name , vlan_number , <EOL> network_str ) <EOL> site = ensure_site ( site_name ) <EOL> vlan = ensure_vlan ( vlan_number , vlan_name ) <EOL> network = ensure_network ( site , vlan , network_str , sec_zone ) <EOL> NetworkKeyValue . objects . get_or_create ( <EOL> key = '<STR_LIT>' , value = sec_zone , obj = network <EOL> ) </s>
