<s> from piston . handler import BaseHandler , rc <EOL> from systems . models import System , SystemRack , SystemStatus , NetworkAdapter , KeyValue , ScheduledTask <EOL> from truth . models import Truth , KeyValue as TruthKeyValue <EOL> from MacroExpansion import MacroExpansion <EOL> from KeyValueTree import KeyValueTree <EOL> import re <EOL> try : <EOL> import json <EOL> except : <EOL> from django . utils import simplejson as json <EOL> from django . test . client import Client <EOL> from settings import API_ACCESS <EOL> class ReverseDNSHandler ( BaseHandler ) : <EOL> allowed_methods = API_ACCESS <EOL> model = System <EOL> exclude = ( ) <EOL> def read ( self , request , reverse_dns_zone = None , reverse_dns_action = None ) : <EOL> if reverse_dns_zone and reverse_dns_action == '<STR_LIT>' : <EOL> tasks = [ ] <EOL> for task in ScheduledTask . objects . get_all_reverse_dns ( ) : <EOL> tasks . append ( task . task ) <EOL> return tasks <EOL> elif reverse_dns_zone and reverse_dns_action == '<STR_LIT>' : <EOL> truths = Truth . objects . select_related ( ) . filter ( keyvalue__key = '<STR_LIT>' , keyvalue__value = '<STR_LIT:True>' ) <EOL> truth_list = [ ] <EOL> for t in truths : <EOL> truth_list . append ( { '<STR_LIT:name>' : t . name . strip ( ) , '<STR_LIT:description>' : t . description . strip ( ) } ) <EOL> return truth_list <EOL> elif reverse_dns_zone and reverse_dns_action == '<STR_LIT>' : <EOL> scope_options = [ ] <EOL> client = Client ( ) <EOL> hosts = json . loads ( client . get ( '<STR_LIT>' % reverse_dns_zone , follow = True ) . content ) <EOL> adapter_list = [ ] <EOL> for host in hosts : <EOL> if '<STR_LIT>' in host : <EOL> the_url = '<STR_LIT>' % ( reverse_dns_zone , host [ '<STR_LIT>' ] ) <EOL> try : <EOL> adapter_list . append ( json . loads ( client . get ( the_url , follow = True ) . content ) ) <EOL> except : <EOL> pass <EOL> return None <EOL> else : <EOL> resp = rc . NOT_FOUND <EOL> resp . write ( "<STR_LIT>" ) </s>
