<s> import logging <EOL> import logging . config <EOL> from netaddr import IPNetwork , IPAddress , AddrFormatError <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 DeployerNetworkLifecycleMgrValidator ( ValidatorPlugin ) : <EOL> def __init__ ( self , instructions , config_files ) : <EOL> super ( DeployerNetworkLifecycleMgrValidator , self ) . __init__ ( <EOL> <NUM_LIT> , instructions , config_files , <EOL> '<STR_LIT>' ) <EOL> self . _valid = True <EOL> LOG . info ( '<STR_LIT>' % KenLog . fcn ( ) ) <EOL> def validate ( self ) : <EOL> LOG . info ( '<STR_LIT>' % KenLog . fcn ( ) ) <EOL> self . _load_inputs ( ) <EOL> component_all_servers = [ ] <EOL> component_on_server_network = [ ] <EOL> component_on_server = [ ] <EOL> for component_name , component in self . _service_components . iteritems ( ) : <EOL> if component . get ( '<STR_LIT>' , False ) : <EOL> component_all_servers . append ( component_name ) <EOL> if component . get ( '<STR_LIT>' , False ) : <EOL> component_on_server_network . append ( component_name ) <EOL> if component . get ( '<STR_LIT>' , False ) : <EOL> component_on_server . append ( component_name ) <EOL> self . _validate_control_planes ( component_all_servers , component_on_server ) <EOL> self . _validate_servers ( component_on_server_network ) <EOL> def _load_inputs ( self ) : <EOL> version = float ( self . version ( ) ) <EOL> self . _service_components = self . _get_dict_from_config_value ( version , '<STR_LIT>' ) <EOL> self . _control_planes = self . _get_dict_from_config_value ( version , '<STR_LIT>' ) <EOL> self . _server_roles = self . _get_dict_from_config_value ( version , '<STR_LIT>' ) <EOL> self . _iface_models = self . _get_dict_from_config_value ( version , '<STR_LIT>' ) <EOL> self . _network_groups = self . _get_dict_from_config_value ( version , '<STR_LIT>' ) <EOL> self . _networks = self . _get_dict_from_config_value ( version , '<STR_LIT>' ) <EOL> self . _bm_servers = self . _get_config_value ( version , '<STR_LIT>' ) <EOL> def _validate_control_planes ( self , component_all_servers , component_on_server ) : <EOL> for cp_name , cp in self . _control_planes . iteritems ( ) : <EOL> for component in component_all_servers : <EOL> if component not in cp [ '<STR_LIT>' ] : <EOL> for cluster in cp [ '<STR_LIT>' ] : <EOL> if component not in cluster [ '<STR_LIT>' ] : <EOL> msg = ( "<STR_LIT>" <EOL> % ( cp_name , component ) + "<STR_LIT>" ) <EOL> self . add_error ( msg ) <EOL> self . _valid = False <EOL> continue <EOL> for resources in cp . get ( '<STR_LIT>' , cp . get ( '<STR_LIT>' , [ ] ) ) : <EOL> if component not in resources [ '<STR_LIT>' ] : <EOL> msg = ( "<STR_LIT>" <EOL> % ( cp_name , component ) + "<STR_LIT>" ) <EOL> self . add_error ( msg ) <EOL> self . _valid = False <EOL> continue <EOL> for component in component_on_server : <EOL> found = False <EOL> for cp_name , cp in self . _control_planes . iteritems ( ) : <EOL> for cluster in cp [ '<STR_LIT>' ] : <EOL> if component in cluster [ '<STR_LIT>' ] : <EOL> found = True <EOL> break <EOL> if not found : <EOL> for resources in cp . get ( '<STR_LIT>' , cp . get ( '<STR_LIT>' , [ ] ) ) : <EOL> if component in resources [ '<STR_LIT>' ] : <EOL> found = True <EOL> break <EOL> if not found : <EOL> msg = ( "<STR_LIT>" <EOL> % ( component ) ) <EOL> self . add_error ( msg ) <EOL> self . _valid = False <EOL> def _validate_servers ( self , component_on_server_network ) : <EOL> for s in self . _bm_servers : <EOL> self . _validate_server_network ( s ) <EOL> def _validate_server_network ( self , s ) : <EOL> network = self . _network_from_address ( s ) <EOL> if not network : <EOL> msg = ( "<STR_LIT>" <EOL> % ( s [ '<STR_LIT>' ] , s [ '<STR_LIT:id>' ] ) ) <EOL> self . add_error ( msg ) <EOL> self . _valid = False <EOL> return None <EOL> self . _check_for_tagged_network ( s , network ) <EOL> s_int_model , s_network_group = self . _check_server_interface ( s , network ) <EOL> if not s_network_group : <EOL> msg = ( "<STR_LIT>" % ( s [ '<STR_LIT>' ] , s [ '<STR_LIT:id>' ] , network ) + <EOL> "<STR_LIT>" <EOL> % s_int_model ) <EOL> self . add_error ( msg ) <EOL> self . _valid = False <EOL> return None <EOL> else : <EOL> return s_network_group <EOL> def _net_grp_for_component ( self , component ) : <EOL> def_net_grp = None <EOL> for net_name , net_grp in self . _network_groups . iteritems ( ) : <EOL> endpoints = [ ] <EOL> if '<STR_LIT>' in net_grp : <EOL> endpoints += net_grp [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in net_grp : <EOL> endpoints += net_grp [ '<STR_LIT>' ] <EOL> if component in endpoints : <EOL> return net_grp [ '<STR_LIT:name>' ] <EOL> elif '<STR_LIT:default>' in endpoints : <EOL> def_net_grp = net_grp [ '<STR_LIT:name>' ] <EOL> return def_net_grp <EOL> def _network_from_address ( self , s ) : <EOL> for net_name , net in self . _networks . iteritems ( ) : <EOL> if '<STR_LIT>' in net : <EOL> ip_net = IPNetwork ( unicode ( net [ '<STR_LIT>' ] ) ) <EOL> net_start = ip_net [ <NUM_LIT:1> ] <EOL> net_end = ip_net [ - <NUM_LIT:2> ] <EOL> if '<STR_LIT>' in net : <EOL> net_start = IPAddress ( net [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT>' in net : <EOL> net_end = IPAddress ( net [ '<STR_LIT>' ] ) <EOL> try : <EOL> server_ip = IPAddress ( s [ '<STR_LIT>' ] ) <EOL> except AddrFormatError : <EOL> return None <EOL> else : <EOL> if net_start <= server_ip <= net_end : <EOL> return net_name <EOL> return None <EOL> def _check_server_interface ( self , s , network ) : <EOL> net_group = self . _networks [ network ] [ '<STR_LIT>' ] <EOL> s_int_model = self . _server_roles [ s [ '<STR_LIT>' ] ] [ '<STR_LIT>' ] <EOL> interfaces = self . _iface_models [ s_int_model ] . get ( '<STR_LIT>' , [ ] ) <EOL> for interface in interfaces : <EOL> iface_net_groups = interface . get ( '<STR_LIT>' , [ ] ) + interface . get ( '<STR_LIT>' , [ ] ) <EOL> if net_group in iface_net_groups : <EOL> return ( s_int_model , net_group ) <EOL> return ( s_int_model , None ) <EOL> def _check_for_tagged_network ( self , s , network ) : <EOL> if '<STR_LIT>' not in s : <EOL> return <EOL> if self . _networks [ network ] . get ( '<STR_LIT>' , True ) : <EOL> msg = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> % ( network ) ) <EOL> self . add_warning ( msg ) <EOL> self . _valid = False <EOL> @ property <EOL> def instructions ( self ) : <EOL> return self . _instructions <EOL> def get_dependencies ( self ) : <EOL> return [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] </s>
