<s> from systems . models import ScheduledTask , KeyValue , System <EOL> import re <EOL> class DHCPHelper ( object ) : <EOL> scopes_to_generate = [ ] <EOL> def __init__ ( self ) : <EOL> pass <EOL> def get_scopes_to_generate ( self ) : <EOL> return ScheduledTask . objects . get_all_dhcp ( ) <EOL> def systems_by_scope ( self , scope ) : <EOL> keyvalue_pairs = KeyValue . objects . filter ( key__contains = '<STR_LIT>' , value = scope ) . filter ( key__startswith = '<STR_LIT>' ) <EOL> tmp_list = [ ] <EOL> for row in keyvalue_pairs : <EOL> keyvalue = KeyValue . objects . filter ( system = row . system ) <EOL> tmp_dict = { } <EOL> for kv in keyvalue : <EOL> tmp_dict [ kv . key ] = kv . value <EOL> tmp_dict [ '<STR_LIT>' ] = row . system . hostname <EOL> appendable = True <EOL> for the_items in tmp_list : <EOL> if '<STR_LIT>' not in the_items : <EOL> appendable = True <EOL> elif the_items [ '<STR_LIT>' ] == row . system . hostname : <EOL> appendable = False <EOL> if appendable is True : <EOL> tmp_list . append ( tmp_dict ) <EOL> return tmp_list <EOL> def adapters_by_system_and_scope ( self , system , scope ) : <EOL> dhcp_scope = scope <EOL> system = System . objects . get ( hostname = system ) <EOL> keyvalue_pairs = KeyValue . objects . filter ( key__startswith = '<STR_LIT>' ) . filter ( system = system ) . order_by ( '<STR_LIT:key>' ) <EOL> tmp_dict = { } <EOL> adapter_ids = [ ] <EOL> final_list = [ ] <EOL> for kv in keyvalue_pairs : <EOL> tmp_dict [ kv . key ] = kv . value <EOL> for k in tmp_dict . iterkeys ( ) : <EOL> matches = re . match ( '<STR_LIT>' , k ) <EOL> if matches . group is not None : <EOL> dhcp_scope_match = '<STR_LIT>' % matches . group ( <NUM_LIT:1> ) <EOL> ip_address_match = '<STR_LIT>' % matches . group ( <NUM_LIT:1> ) <EOL> if matches . group ( <NUM_LIT:1> ) not in adapter_ids and ip_address_match in tmp_dict and dhcp_scope_match in tmp_dict and tmp_dict [ dhcp_scope_match ] == dhcp_scope : <EOL> adapter_ids . append ( matches . group ( <NUM_LIT:1> ) ) <EOL> adapter_ids . sort ( ) <EOL> for a in adapter_ids : <EOL> adapter_name = '<STR_LIT>' <EOL> mac_address = '<STR_LIT>' <EOL> dhcp_hostname = '<STR_LIT>' <EOL> dhcp_filename = '<STR_LIT>' <EOL> dhcp_domain_name = '<STR_LIT>' <EOL> ipv4_address = '<STR_LIT>' <EOL> dhcp_domain_name_servers = '<STR_LIT>' <EOL> if '<STR_LIT>' % a in tmp_dict : <EOL> ipv4_address = tmp_dict [ '<STR_LIT>' % a ] <EOL> if '<STR_LIT>' % a in tmp_dict : <EOL> adapter_name = tmp_dict [ '<STR_LIT>' % a ] <EOL> if '<STR_LIT>' % a in tmp_dict : <EOL> mac_address = tmp_dict [ '<STR_LIT>' % a ] <EOL> if '<STR_LIT>' % a in tmp_dict and '<STR_LIT>' % a not in tmp_dict : <EOL> dhcp_hostname = tmp_dict [ '<STR_LIT>' % a ] <EOL> if '<STR_LIT>' % a in tmp_dict : <EOL> dhcp_hostname = tmp_dict [ '<STR_LIT>' % a ] <EOL> if '<STR_LIT>' % a in tmp_dict : <EOL> dhcp_filename = tmp_dict [ '<STR_LIT>' % a ] <EOL> if '<STR_LIT>' % a in tmp_dict : <EOL> dhcp_domain_name = tmp_dict [ '<STR_LIT>' % a ] <EOL> if '<STR_LIT>' % a in tmp_dict : <EOL> dhcp_domain_name_servers = tmp_dict [ '<STR_LIT>' % a ] <EOL> final_list . append ( { '<STR_LIT>' : system . hostname , '<STR_LIT>' : ipv4_address , '<STR_LIT>' : adapter_name , '<STR_LIT>' : mac_address , '<STR_LIT>' : dhcp_hostname , '<STR_LIT>' : dhcp_hostname , '<STR_LIT>' : dhcp_filename , '<STR_LIT>' : dhcp_domain_name , '<STR_LIT>' : dhcp_domain_name_servers } ) <EOL> return final_list </s>
