<s> """<STR_LIT>""" <EOL> import commands <EOL> import os <EOL> import re <EOL> import socket <EOL> import xmlrpclib <EOL> from compass . actions . health_check import base <EOL> class DhcpCheck ( base . BaseCheck ) : <EOL> """<STR_LIT>""" <EOL> NAME = "<STR_LIT>" <EOL> def run ( self ) : <EOL> """<STR_LIT>""" <EOL> method_name = "<STR_LIT>" + self . os_installer [ '<STR_LIT:name>' ] + "<STR_LIT>" <EOL> return eval ( method_name ) <EOL> def check_cobbler_dhcp ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> remote = xmlrpclib . Server ( <EOL> self . os_installer [ '<STR_LIT>' ] , <EOL> allow_none = True ) <EOL> credentials = self . os_installer [ '<STR_LIT>' ] <EOL> remote . login ( <EOL> credentials [ '<STR_LIT:username>' ] , credentials [ '<STR_LIT:password>' ] ) <EOL> except Exception : <EOL> self . _set_status ( <EOL> <NUM_LIT:0> , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % self . NAME ) <EOL> return ( self . code , self . messages ) <EOL> cobbler_settings = remote . get_settings ( ) <EOL> if cobbler_settings [ '<STR_LIT>' ] == <NUM_LIT:0> : <EOL> self . messages . append ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % self . NAME ) <EOL> self . code = <NUM_LIT:0> <EOL> return ( self . code , self . messages ) <EOL> self . check_cobbler_dhcp_template ( ) <EOL> print "<STR_LIT>" <EOL> self . check_dhcp_service ( ) <EOL> self . check_dhcp_netmask ( ) <EOL> print "<STR_LIT>" <EOL> if self . code == <NUM_LIT:1> : <EOL> self . messages . append ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % self . NAME ) <EOL> return ( self . code , self . messages ) <EOL> def check_cobbler_dhcp_template ( self ) : <EOL> """<STR_LIT>""" <EOL> print "<STR_LIT>" , <EOL> if os . path . exists ( "<STR_LIT>" ) : <EOL> var_map = { <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT>" : False , <EOL> } <EOL> ip_regex = re . compile ( r'<STR_LIT>' ) <EOL> dhcp_template = open ( "<STR_LIT>" ) <EOL> for line in dhcp_template . readlines ( ) : <EOL> if line . find ( "<STR_LIT>" ) != - <NUM_LIT:1> : <EOL> elmlist = line . split ( "<STR_LIT:U+0020>" ) <EOL> for elm in elmlist : <EOL> if "<STR_LIT:;>" in elm : <EOL> elm = elm [ : - <NUM_LIT:2> ] <EOL> if "<STR_LIT>" in elm or ip_regex . match ( elm ) : <EOL> var_map [ "<STR_LIT>" ] = True <EOL> elif line . find ( "<STR_LIT>" ) != - <NUM_LIT:1> and line . find ( "<STR_LIT:{>" ) != - <NUM_LIT:1> : <EOL> elmlist = line . split ( "<STR_LIT:U+0020>" ) <EOL> for elm in elmlist : <EOL> if ip_regex . match ( elm ) : <EOL> if elm [ - <NUM_LIT:1> ] == "<STR_LIT:0>" and "<STR_LIT>" not in elm : <EOL> var_map [ "<STR_LIT>" ] = True <EOL> elif elm [ - <NUM_LIT:1> ] != "<STR_LIT:0>" : <EOL> self . messages . append ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % self . NAME ) <EOL> elif line . find ( "<STR_LIT:filename>" ) != - <NUM_LIT:1> : <EOL> var_map [ "<STR_LIT>" ] = True <EOL> elif line . find ( "<STR_LIT>" ) != - <NUM_LIT:1> : <EOL> elmlist = line . split ( "<STR_LIT:U+0020>" ) <EOL> ip_count = <NUM_LIT:0> <EOL> for elm in elmlist : <EOL> if "<STR_LIT:;>" in elm and "<STR_LIT:\n>" in elm : <EOL> elm = elm [ : - <NUM_LIT:2> ] <EOL> if ip_regex . match ( elm ) : <EOL> ip_count += <NUM_LIT:1> <EOL> if ip_count != <NUM_LIT:2> : <EOL> self . messages . append ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % self . NAME ) <EOL> else : <EOL> var_map [ "<STR_LIT>" ] = True <EOL> dhcp_template . close ( ) <EOL> fails = [ ] <EOL> for var in var_map . keys ( ) : <EOL> if var_map [ var ] is False : <EOL> fails . append ( var ) <EOL> if len ( fails ) != <NUM_LIT:0> : <EOL> self . _set_status ( <EOL> <NUM_LIT:0> , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % ( <EOL> self . NAME , '<STR_LIT:U+0020>' . join ( failed for failed in fails ) ) ) <EOL> else : <EOL> self . _set_status ( <EOL> <NUM_LIT:0> , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % self . NAME ) <EOL> return True <EOL> def check_dhcp_netmask ( self ) : <EOL> with open ( '<STR_LIT>' ) as conf_reader : <EOL> lines = conf_reader . readlines ( ) <EOL> for line in lines : <EOL> if re . search ( '<STR_LIT>' , line ) : <EOL> elm_list = line . split ( '<STR_LIT:U+0020>' ) <EOL> break <EOL> subnet_ip = elm_list [ <NUM_LIT:1> ] <EOL> netmask = elm_list [ - <NUM_LIT:2> ] <EOL> subnet_ip_elm = subnet_ip . split ( '<STR_LIT:.>' ) <EOL> netmask_elm = netmask . split ( '<STR_LIT:.>' ) <EOL> for index , digit in enumerate ( subnet_ip_elm ) : <EOL> if int ( digit ) & int ( netmask_elm [ index ] ) != int ( digit ) : <EOL> self . _set_status ( <EOL> <NUM_LIT:0> , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % self . NAME ) <EOL> break <EOL> return True <EOL> def check_dhcp_service ( self ) : <EOL> """<STR_LIT>""" <EOL> print "<STR_LIT>" , <EOL> if not commands . getoutput ( '<STR_LIT>' ) : <EOL> self . _set_status ( <EOL> <NUM_LIT:0> , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % self . NAME ) <EOL> if socket . getservbyport ( <NUM_LIT> ) != '<STR_LIT>' : <EOL> self . _set_status ( <EOL> <NUM_LIT:0> , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % self . NAME ) <EOL> return True </s>
