<s> import six <EOL> from helion_configurationprocessor . cp . model . CPState import CPState <EOL> from helion_configurationprocessor . cp . model . NodeRole import NodeRole <EOL> from helion_configurationprocessor . cp . controller . NetworkConfigController import NetworkConfigController <EOL> class ResourceNode ( object ) : <EOL> @ staticmethod <EOL> def is_active ( elem_cp , node_type , rn ) : <EOL> if isinstance ( rn , int ) : <EOL> rn_id = int ( rn ) <EOL> else : <EOL> rn_id = ResourceNode . id_from_hostname ( rn ) <EOL> resource_nodes = elem_cp . get ( '<STR_LIT>' , dict ( ) ) <EOL> for rn , elem_rn in six . iteritems ( resource_nodes ) : <EOL> if rn . lower ( ) != node_type . lower ( ) : <EOL> continue <EOL> states = elem_rn . get ( '<STR_LIT>' , dict ( ) ) <EOL> for s , elem_s in six . iteritems ( states ) : <EOL> if int ( s ) != rn_id : <EOL> continue <EOL> state = elem_s . get ( '<STR_LIT:state>' , '<STR_LIT>' ) <EOL> return CPState . is_active ( state ) <EOL> return True <EOL> @ staticmethod <EOL> def get_active_count ( elem_cp , node_type ) : <EOL> resource_nodes = elem_cp . get ( '<STR_LIT>' , dict ( ) ) <EOL> for rn , elem_rn in six . iteritems ( resource_nodes ) : <EOL> if rn . lower ( ) != node_type . lower ( ) : <EOL> continue <EOL> count = elem_rn . get ( '<STR_LIT:count>' , <NUM_LIT:0> ) <EOL> states = elem_rn . get ( '<STR_LIT>' , dict ( ) ) <EOL> for s , elem_s in six . iteritems ( states ) : <EOL> state = elem_s . get ( '<STR_LIT:state>' , '<STR_LIT>' ) <EOL> if not CPState . is_active ( state ) : <EOL> count -= <NUM_LIT:1> <EOL> return count <EOL> return <NUM_LIT:0> <EOL> @ staticmethod <EOL> def get_control_plane_id ( hostname ) : <EOL> host_enc = NetworkConfigController . decode_hostname ( hostname ) <EOL> return host_enc [ '<STR_LIT>' ] <EOL> @ staticmethod <EOL> def get_type ( hostname ) : <EOL> host_enc = NetworkConfigController . decode_hostname ( hostname ) <EOL> return host_enc [ '<STR_LIT>' ] <EOL> @ staticmethod <EOL> def id_from_hostname ( hostname ) : <EOL> host_enc = NetworkConfigController . decode_hostname ( hostname ) <EOL> node_id = host_enc [ '<STR_LIT>' ] <EOL> return int ( node_id . replace ( '<STR_LIT:N>' , '<STR_LIT>' ) ) <EOL> @ staticmethod <EOL> def equals_ignoring_traffic_group ( hostname1 , hostname2 ) : <EOL> host_enc1 = NetworkConfigController . decode_hostname ( hostname1 ) <EOL> host_enc2 = NetworkConfigController . decode_hostname ( hostname2 ) <EOL> if host_enc1 [ '<STR_LIT>' ] != host_enc2 [ '<STR_LIT>' ] : <EOL> return False <EOL> if host_enc1 [ '<STR_LIT>' ] != host_enc2 [ '<STR_LIT>' ] : <EOL> return False <EOL> if host_enc1 [ '<STR_LIT>' ] != host_enc2 [ '<STR_LIT>' ] : <EOL> return False <EOL> if host_enc1 [ '<STR_LIT>' ] != host_enc2 [ '<STR_LIT>' ] : <EOL> return False <EOL> if host_enc1 [ '<STR_LIT>' ] != host_enc2 [ '<STR_LIT>' ] : <EOL> return False <EOL> return True <EOL> @ staticmethod <EOL> def is_resource_node ( hostname ) : <EOL> host_enc = NetworkConfigController . decode_hostname ( hostname ) <EOL> host_type = host_enc [ '<STR_LIT>' ] <EOL> resource_node = NodeRole . to_type ( NodeRole . RESOURCE_NODE ) <EOL> return host_type == resource_node <EOL> @ staticmethod <EOL> def get_hostname ( elem_rn ) : <EOL> pass <EOL> @ staticmethod <EOL> def get_services ( elem_rn ) : <EOL> return elem_rn . get ( '<STR_LIT>' , [ ] ) <EOL> @ staticmethod <EOL> def is_service_present ( svc_controller , elem_rn , service_name ) : <EOL> for elem_s in elem_rn . get ( '<STR_LIT>' , [ ] ) : <EOL> if svc_controller . equals ( elem_s , service_name ) : <EOL> return True <EOL> return False <EOL> @ staticmethod <EOL> def is_any_service_present ( svc_controller , elem_rn , service_names ) : <EOL> for sn in service_names : <EOL> if ResourceNode . is_service_present ( svc_controller , elem_rn , sn ) : <EOL> return True <EOL> return False </s>
