<s> import six <EOL> from helion_configurationprocessor . cp . model . CPState import CPState <EOL> from helion_configurationprocessor . cp . model . ControlPlane import ControlPlane <EOL> from helion_configurationprocessor . cp . model . CloudModel import CloudModel <EOL> from helion_configurationprocessor . cp . model . ResourceNode import ResourceNode <EOL> from helion_configurationprocessor . cp . model . StatePersistor import StatePersistor <EOL> class Server ( object ) : <EOL> @ staticmethod <EOL> def is_active ( cloud_model , elem_s ) : <EOL> if isinstance ( elem_s , dict ) : <EOL> if '<STR_LIT:state>' in elem_s : <EOL> state = elem_s . get ( '<STR_LIT:state>' , CPState . ACTIVE ) <EOL> return CPState . is_active ( state ) <EOL> if Server . is_allocated ( elem_s ) : <EOL> name = Server . hostname ( elem_s ) <EOL> if ResourceNode . is_resource_node ( name ) : <EOL> return Server . is_resource_node_active ( cloud_model , name ) <EOL> elif ResourceNode . is_resource_node ( elem_s ) : <EOL> return Server . is_resource_node_active ( cloud_model , elem_s ) <EOL> return True <EOL> @ staticmethod <EOL> def is_deleted ( models , controllers , elem_s ) : <EOL> state_persistor = StatePersistor ( <EOL> models , controllers , <EOL> persistence_file = '<STR_LIT>' ) <EOL> info = state_persistor . recall_info ( ) <EOL> for k , v in six . iteritems ( info ) : <EOL> if ( v [ '<STR_LIT>' ] != elem_s [ '<STR_LIT>' ] or <EOL> v [ '<STR_LIT>' ] != elem_s [ '<STR_LIT>' ] ) : <EOL> continue <EOL> if '<STR_LIT:state>' not in v : <EOL> return False <EOL> if not CPState . is_active ( v [ '<STR_LIT:state>' ] ) : <EOL> return True <EOL> return False <EOL> return False <EOL> @ staticmethod <EOL> def is_resource_node_active ( cloud_model , elem_s ) : <EOL> control_planes = CloudModel . control_planes ( cloud_model ) <EOL> control_plane = ResourceNode . get_control_plane_id ( elem_s ) <EOL> node_type = ResourceNode . get_type ( elem_s ) <EOL> for elem_cp in control_planes : <EOL> cp_name = ControlPlane . get_name ( elem_cp ) <EOL> if cp_name . lower ( ) != control_plane . lower ( ) : <EOL> continue <EOL> if not ResourceNode . is_active ( elem_cp , node_type , elem_s ) : <EOL> return False <EOL> return True <EOL> @ staticmethod <EOL> def is_allocated ( elem_s ) : <EOL> elem_a = elem_s . get ( '<STR_LIT>' , dict ( ) ) <EOL> return '<STR_LIT>' in elem_a <EOL> @ staticmethod <EOL> def allocations ( elem_s ) : <EOL> return elem_s . get ( '<STR_LIT>' , dict ( ) ) <EOL> @ staticmethod <EOL> def hostname ( elem_s ) : <EOL> elem_a = elem_s . get ( '<STR_LIT>' , dict ( ) ) <EOL> return elem_a . get ( '<STR_LIT>' , None ) <EOL> @ staticmethod <EOL> def tags ( elem_s ) : <EOL> return elem_s . get ( '<STR_LIT>' , None ) </s>
