<s> import six <EOL> import logging <EOL> import logging . config <EOL> from helion_configurationprocessor . cp . model . ControlPlane import ControlPlane <EOL> from helion_configurationprocessor . cp . model . Tier import Tier <EOL> from helion_configurationprocessor . cp . controller . CloudNameController import CloudNameController <EOL> from helion_configurationprocessor . cp . model . ExplainerPlugin import ExplainerPlugin <EOL> from helion_configurationprocessor . cp . model . ExplainerPlugin import ordinal <EOL> from helion_configurationprocessor . cp . model . ExplainerPlugin import pluralize <EOL> from helion_configurationprocessor . cp . model . CPLogging import CPLogging as KenLog <EOL> LOG = logging . getLogger ( __name__ ) <EOL> class CloudStructureExplainer ( ExplainerPlugin ) : <EOL> def __init__ ( self , instructions , models , controllers ) : <EOL> super ( CloudStructureExplainer , self ) . __init__ ( <EOL> <NUM_LIT:1> , instructions , models , controllers , <EOL> '<STR_LIT>' ) <EOL> LOG . info ( '<STR_LIT>' % KenLog . fcn ( ) ) <EOL> def explain ( self ) : <EOL> LOG . info ( '<STR_LIT>' % KenLog . fcn ( ) ) <EOL> fp = self . _get_explainer_file ( ) <EOL> message = self . _get_title ( ) <EOL> message += self . _get_structure ( ) <EOL> fp . write ( '<STR_LIT:%s>' % message ) <EOL> self . _close_explainer_file ( fp ) <EOL> def _get_title ( self ) : <EOL> message = '<STR_LIT>' <EOL> return message <EOL> def _get_structure ( self ) : <EOL> nt_controller = self . _controllers [ '<STR_LIT>' ] <EOL> path = self . _instructions [ '<STR_LIT>' ] <EOL> name , nickname = CloudNameController . get_cloud_names ( path ) <EOL> if nickname and ( len ( nickname ) > <NUM_LIT:0> ) : <EOL> message = '<STR_LIT>' % ( <EOL> name , nickname ) <EOL> else : <EOL> message = '<STR_LIT>' % name <EOL> num_cp = len ( self . _models [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> message += '<STR_LIT>' % ( num_cp , pluralize ( num_cp , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> cp_index = <NUM_LIT:1> <EOL> for elem_cp in self . _models [ '<STR_LIT>' ] [ '<STR_LIT>' ] : <EOL> if not ControlPlane . is_active ( elem_cp ) : <EOL> continue <EOL> cp_type = ControlPlane . get_name ( elem_cp ) <EOL> num_tiers = ControlPlane . get_active_tier_count ( elem_cp ) <EOL> str_tiers = pluralize ( num_tiers , '<STR_LIT>' , '<STR_LIT>' ) <EOL> message += '<STR_LIT>' '<STR_LIT>' % ( ordinal ( cp_index ) , cp_type , elem_cp [ '<STR_LIT:type>' ] , <EOL> num_tiers , str_tiers ) <EOL> t_index = <NUM_LIT:1> <EOL> for elem_t in elem_cp [ '<STR_LIT>' ] : <EOL> if not Tier . is_active ( elem_t ) : <EOL> continue <EOL> mc = Tier . get_active_member_count ( elem_t ) <EOL> if mc == <NUM_LIT:1> : <EOL> message += '<STR_LIT>' '<STR_LIT>' % ordinal ( t_index ) <EOL> else : <EOL> message += '<STR_LIT>' '<STR_LIT>' % ( ordinal ( t_index ) , mc , <EOL> pluralize ( mc , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> message += '<STR_LIT:\n>' <EOL> t_index += <NUM_LIT:1> <EOL> if ( '<STR_LIT>' not in elem_cp or <EOL> elem_cp [ '<STR_LIT>' ] == { } ) : <EOL> message += '<STR_LIT>' '<STR_LIT>' <EOL> else : <EOL> for rn , elem_rn in six . iteritems ( elem_cp [ '<STR_LIT>' ] ) : <EOL> count = elem_rn [ '<STR_LIT:count>' ] <EOL> node_type = nt_controller . get ( rn ) <EOL> fn_singular = node_type . friendly_name <EOL> fn_plural = node_type . friendly_name + '<STR_LIT:s>' <EOL> message += '<STR_LIT>' '<STR_LIT>' % ( <EOL> pluralize ( count , '<STR_LIT>' , '<STR_LIT>' ) , count , <EOL> pluralize ( count , fn_singular , fn_plural ) , <EOL> rn ) <EOL> message += '<STR_LIT:\n>' <EOL> cp_index += <NUM_LIT:1> <EOL> return message <EOL> def get_dependencies ( self ) : <EOL> return [ ] </s>
