<s> '''<STR_LIT>''' <EOL> from actuator . utils import ClassModifier , process_modifiers <EOL> from actuator . modeling import ( ActuatorException , ModelBaseMeta , ModelBase , <EOL> ModelComponent , AbstractModelingEntity , <EOL> ModelInstanceReference , KeyAsAttr , <EOL> _ComputeModelComponents , ModelReference , <EOL> ComponentGroup , MultiComponent , <EOL> MultiComponentGroup ) <EOL> class InfraException ( ActuatorException ) : pass <EOL> _infra_options = "<STR_LIT>" <EOL> _recognized_options = set ( [ "<STR_LIT>" ] ) <EOL> @ ClassModifier <EOL> def with_resources ( cls , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> components = getattr ( cls , InfraModelMeta . _COMPONENTS ) <EOL> if components is None : <EOL> raise InfraException ( "<STR_LIT>" ) <EOL> for k , v in kwargs . items ( ) : <EOL> if not isinstance ( v , AbstractModelingEntity ) : <EOL> raise InfraException ( "<STR_LIT>" % k ) <EOL> setattr ( cls , k , v ) <EOL> components [ k ] = v <EOL> return <EOL> class ResourceGroup ( ComponentGroup ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class MultiResource ( MultiComponent ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class MultiResourceGroup ( MultiComponentGroup ) : <EOL> """<STR_LIT>""" <EOL> def __new__ ( self , name , ** kwargs ) : <EOL> group = ResourceGroup ( name , ** kwargs ) <EOL> return MultiResource ( group ) <EOL> class Provisionable ( ModelComponent ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class InfraModelMeta ( ModelBaseMeta ) : <EOL> model_ref_class = ModelReference <EOL> def __new__ ( cls , name , bases , attr_dict ) : <EOL> new_class = super ( InfraModelMeta , cls ) . __new__ ( cls , name , bases , attr_dict ) <EOL> process_modifiers ( new_class ) <EOL> new_class . _class_refs_for_resources ( ) <EOL> return new_class <EOL> class InfraModel ( ModelBase ) : <EOL> """<STR_LIT>""" <EOL> __metaclass__ = InfraModelMeta <EOL> ref_class = ModelInstanceReference <EOL> def __init__ ( self , name ) : <EOL> """<STR_LIT>""" <EOL> super ( InfraModel , self ) . __init__ ( ) <EOL> self . name = name <EOL> ga = super ( InfraModel , self ) . __getattribute__ <EOL> attrdict = self . __dict__ <EOL> for k , v in ga ( InfraModelMeta . _COMPONENTS ) . items ( ) : <EOL> attrdict [ k ] = clone = v . clone ( ) <EOL> clone . _set_model_instance ( self ) <EOL> self . provisioning_computed = False <EOL> def validate_args ( self ) : <EOL> """<STR_LIT>""" <EOL> for resource in self . __class__ . __dict__ [ InfraModelMeta . _COMPONENTS ] . values ( ) : <EOL> resource . _validate_args ( self ) <EOL> def provisioning_been_computed ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . provisioning_computed <EOL> def components ( self ) : <EOL> """<STR_LIT>""" <EOL> _resources = super ( InfraModel , self ) . components ( ) <EOL> for resource in _resources : <EOL> resource . _set_model_instance ( self ) <EOL> return _resources <EOL> resources = components <EOL> def compute_provisioning_from_refs ( self , modelrefs , exclude_refs = None ) : <EOL> """<STR_LIT>""" <EOL> if self . provisioning_computed : <EOL> raise InfraException ( "<STR_LIT>" ) <EOL> self . provisioning_computed = True <EOL> if exclude_refs is None : <EOL> exclude_refs = set ( ) <EOL> else : <EOL> exclude_refs = set ( exclude_refs ) <EOL> for mr in modelrefs : <EOL> if mr not in exclude_refs and mr . get_containing_component_ref ( ) not in exclude_refs : <EOL> _ = self . get_inst_ref ( mr ) <EOL> @ classmethod <EOL> def _class_refs_for_resources ( cls , my_ref = None ) : <EOL> all_refs = set ( ) <EOL> for k , v in cls . __dict__ [ InfraModelMeta . _COMPONENTS ] . items ( ) : <EOL> if isinstance ( v , Provisionable ) : <EOL> if isinstance ( k , KeyAsAttr ) : <EOL> all_refs . add ( my_ref [ k ] ) <EOL> else : <EOL> all_refs . add ( getattr ( cls if my_ref is None else my_ref , k ) ) <EOL> elif isinstance ( v , _ComputeModelComponents ) : <EOL> ref = getattr ( cls , k ) <EOL> all_refs |= v . refs_for_components ( my_ref = ref ) <EOL> return all_refs <EOL> def _comp_source ( self ) : <EOL> return dict ( self . __dict__ ) <EOL> class IPAddressable ( object ) : <EOL> """<STR_LIT>""" <EOL> def get_ip ( self , context = None ) : <EOL> """<STR_LIT>""" <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> class StaticServer ( IPAddressable , Provisionable ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name , hostname_or_ip ) : <EOL> """<STR_LIT>""" <EOL> super ( StaticServer , self ) . __init__ ( name ) <EOL> self . hostname_or_ip = None <EOL> self . _hostname_or_ip = hostname_or_ip <EOL> def _fix_arguments ( self ) : <EOL> self . hostname_or_ip = self . _get_arg_value ( self . _hostname_or_ip ) <EOL> def get_init_args ( self ) : <EOL> __doc__ = Provisionable . get_init_args . __doc__ <EOL> return ( ( self . name , self . _hostname_or_ip ) , { } ) <EOL> def get_ip ( self , context = None ) : <EOL> """<STR_LIT>""" <EOL> return self . hostname_or_ip </s>
