<s> import logging <EOL> import logging . config <EOL> import re <EOL> from helion_configurationprocessor . cp . model . ValidatorPlugin import ValidatorPlugin <EOL> from helion_configurationprocessor . cp . model . CPLogging import CPLogging as KenLog <EOL> LOG = logging . getLogger ( __name__ ) <EOL> class DiskModelValidator ( ValidatorPlugin ) : <EOL> def __init__ ( self , instructions , config_files ) : <EOL> super ( DiskModelValidator , self ) . __init__ ( <EOL> <NUM_LIT> , instructions , config_files , <EOL> '<STR_LIT>' ) <EOL> self . _valid = False <EOL> LOG . info ( '<STR_LIT>' % KenLog . fcn ( ) ) <EOL> def validate ( self ) : <EOL> LOG . info ( '<STR_LIT>' % KenLog . fcn ( ) ) <EOL> version = float ( self . version ( ) ) <EOL> input = self . _create_content ( version , "<STR_LIT>" ) <EOL> self . _valid = self . validate_schema ( input , "<STR_LIT>" ) <EOL> if self . _valid : <EOL> disk_models = input [ '<STR_LIT>' ] <EOL> self . _validate_names ( disk_models ) <EOL> self . _prevent_device_duplication ( disk_models ) <EOL> self . _validate_vg_space ( disk_models ) <EOL> self . _validate_mode_bits ( disk_models ) <EOL> return self . _valid <EOL> def _mode_bits_parser ( self , mode , error_msg ) : <EOL> if not re . match ( r"<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , str ( mode ) ) : <EOL> self . add_error ( error_msg ) <EOL> self . _valid = False <EOL> def _validate_mode_bits ( self , disk_models ) : <EOL> for model in disk_models : <EOL> for vg in model [ '<STR_LIT>' ] : <EOL> for lv in vg [ '<STR_LIT>' ] : <EOL> if '<STR_LIT>' in lv : <EOL> msg = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) . format ( dmName = model [ '<STR_LIT:name>' ] , <EOL> vgName = vg [ '<STR_LIT:name>' ] , <EOL> lvMode = lv [ '<STR_LIT>' ] , <EOL> lvName = lv [ '<STR_LIT:name>' ] ) <EOL> self . _mode_bits_parser ( lv [ '<STR_LIT>' ] , msg ) <EOL> for pv in vg [ '<STR_LIT>' ] : <EOL> if '<STR_LIT>' in pv : <EOL> msg = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) . format ( dmName = model [ '<STR_LIT:name>' ] , <EOL> pvMode = pv [ '<STR_LIT>' ] , <EOL> pvDevice = pv [ '<STR_LIT>' ] ) <EOL> self . _mode_bits_parser ( pv [ '<STR_LIT>' ] , msg ) <EOL> def _validate_vg_space ( self , disk_models ) : <EOL> for model in disk_models : <EOL> for vg in model [ '<STR_LIT>' ] : <EOL> space = <NUM_LIT:0> <EOL> for lv in vg [ '<STR_LIT>' ] : <EOL> space += int ( lv [ '<STR_LIT:size>' ] . replace ( '<STR_LIT:%>' , '<STR_LIT>' ) ) <EOL> if space > <NUM_LIT> : <EOL> msg = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % ( model [ '<STR_LIT:name>' ] , vg [ '<STR_LIT:name>' ] ) ) <EOL> self . add_warning ( msg ) <EOL> return <EOL> def _validate_names ( self , disk_models ) : <EOL> names = set ( ) <EOL> for model in disk_models : <EOL> if model [ '<STR_LIT:name>' ] in names : <EOL> msg = ( "<STR_LIT>" % <EOL> ( model [ '<STR_LIT:name>' ] ) ) <EOL> self . add_error ( msg ) <EOL> self . _valid = False <EOL> else : <EOL> names . add ( model [ '<STR_LIT:name>' ] ) <EOL> def _prevent_device_duplication ( self , disk_models ) : <EOL> for model in disk_models : <EOL> devices = set ( ) <EOL> if '<STR_LIT>' in model . keys ( ) : <EOL> for vg in model [ '<STR_LIT>' ] : <EOL> for pv in vg [ '<STR_LIT>' ] : <EOL> if pv in devices : <EOL> self . add_error ( ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> % ( pv , model [ '<STR_LIT:name>' ] ) ) ) <EOL> self . _valid = False <EOL> continue <EOL> else : <EOL> devices . add ( pv ) <EOL> if '<STR_LIT>' in model . keys ( ) : <EOL> for dg in model [ '<STR_LIT>' ] : <EOL> for device in dg [ '<STR_LIT>' ] : <EOL> if device [ '<STR_LIT:name>' ] in devices : <EOL> self . add_error ( ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> % ( device [ '<STR_LIT:name>' ] , model [ '<STR_LIT:name>' ] ) ) ) <EOL> self . _valid = False <EOL> continue <EOL> else : <EOL> devices . add ( device [ '<STR_LIT:name>' ] ) <EOL> @ property <EOL> def instructions ( self ) : <EOL> return self . _instructions <EOL> def get_dependencies ( self ) : <EOL> return [ ] </s>
