<s> """<STR_LIT>""" <EOL> import base64 <EOL> import hostlists <EOL> import json <EOL> import os <EOL> try : <EOL> from urllib2 import urlopen <EOL> from urllib2 import URLError <EOL> from urllib2 import Request <EOL> except ImportError : <EOL> from urllib . request import urlopen <EOL> from urllib . request import URLError <EOL> from urllib . request import Request <EOL> def name ( ) : <EOL> """<STR_LIT>""" <EOL> return [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def plugin_type ( ) : <EOL> """<STR_LIT>""" <EOL> return [ '<STR_LIT>' ] <EOL> def server_setting ( server = '<STR_LIT:default>' , setting = None ) : <EOL> if not setting : <EOL> return None <EOL> settings = hostlists . get_setting ( '<STR_LIT>' ) <EOL> if not settings : <EOL> return None <EOL> if server in settings . keys ( ) : <EOL> if setting in settings [ server ] . keys ( ) : <EOL> return settings [ server ] [ setting ] <EOL> return None <EOL> def expand ( value , name = '<STR_LIT>' , method = None ) : <EOL> state = '<STR_LIT>' <EOL> if name in [ '<STR_LIT>' ] : <EOL> state = '<STR_LIT>' <EOL> if name in [ '<STR_LIT>' ] : <EOL> state = '<STR_LIT>' <EOL> temp = value . split ( '<STR_LIT::>' ) <EOL> if len ( temp ) : <EOL> haproxy = temp [ <NUM_LIT:0> ] <EOL> if len ( temp ) > <NUM_LIT:1> : <EOL> backend = temp [ <NUM_LIT:1> ] <EOL> else : <EOL> backend = '<STR_LIT:all>' <EOL> else : <EOL> return [ ] <EOL> timeout = <NUM_LIT:2> <EOL> userid = None <EOL> password = None <EOL> if server_setting ( '<STR_LIT:default>' , '<STR_LIT>' ) : <EOL> userid = server_setting ( '<STR_LIT:default>' , '<STR_LIT>' ) <EOL> if server_setting ( '<STR_LIT:default>' , '<STR_LIT:password>' ) : <EOL> password = server_setting ( '<STR_LIT:default>' , '<STR_LIT:password>' ) <EOL> if server_setting ( '<STR_LIT:default>' , '<STR_LIT>' ) : <EOL> timeout = server_setting ( '<STR_LIT:default>' , '<STR_LIT>' ) <EOL> if haproxy and not method and server_setting ( haproxy , '<STR_LIT>' ) : <EOL> method = server_setting ( haproxy , '<STR_LIT>' ) <EOL> if not method and server_setting ( '<STR_LIT:default>' , '<STR_LIT>' ) : <EOL> method = server_setting ( '<STR_LIT:default>' , '<STR_LIT>' ) <EOL> if haproxy : <EOL> if server_setting ( haproxy , '<STR_LIT>' ) : <EOL> userid = server_setting ( haproxy , '<STR_LIT>' ) <EOL> if server_setting ( haproxy , '<STR_LIT:password>' ) : <EOL> password = server_setting ( haproxy , '<STR_LIT:password>' ) <EOL> if server_setting ( haproxy , '<STR_LIT>' ) : <EOL> timeout = server_setting ( haproxy , '<STR_LIT>' ) <EOL> tmplist = [ ] <EOL> if method == '<STR_LIT>' : <EOL> command = '<STR_LIT>' % ( <EOL> haproxy , backend , state ) <EOL> try : <EOL> hosts = json . loads ( os . popen ( command ) . read ( ) ) <EOL> return hosts <EOL> except : <EOL> return [ ] <EOL> else : <EOL> url = "<STR_LIT>" % haproxy <EOL> request = Request ( url ) <EOL> if userid and password : <EOL> base64string = base64 . encodestring ( <EOL> '<STR_LIT>' % ( userid , password ) ) . replace ( '<STR_LIT:\n>' , '<STR_LIT>' ) <EOL> request . add_header ( "<STR_LIT>" , "<STR_LIT>" % base64string ) <EOL> try : <EOL> result = urlopen ( request , timeout = timeout ) . read ( ) <EOL> for line in result . split ( '<STR_LIT:\n>' ) : <EOL> if not line . startswith ( '<STR_LIT:#>' ) and len ( <EOL> line . strip ( ) ) and '<STR_LIT:U+002C>' in line : <EOL> splitline = line . strip ( ) . split ( '<STR_LIT:U+002C>' ) <EOL> if ( splitline [ <NUM_LIT:0> ] == backend or backend . lower ( ) == '<STR_LIT:all>' ) and splitline [ <NUM_LIT:1> ] not in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> if state . upper ( ) == '<STR_LIT>' or ( splitline [ <NUM_LIT> ] == state ) : <EOL> tmplist . append ( splitline [ <NUM_LIT:1> ] ) <EOL> return tmplist <EOL> except URLError : <EOL> return [ ] </s>
