<s> """<STR_LIT>""" <EOL> import copy <EOL> import logging <EOL> import re <EOL> from ganeti import constants <EOL> from ganeti import errors <EOL> from ganeti import ht <EOL> from ganeti import outils <EOL> _OPID_RE = re . compile ( "<STR_LIT>" ) <EOL> SUMMARY_PREFIX = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } <EOL> DEPEND_ATTR = "<STR_LIT>" <EOL> COMMENT_ATTR = "<STR_LIT>" <EOL> def _NameComponents ( name ) : <EOL> """<STR_LIT>""" <EOL> assert name . startswith ( "<STR_LIT>" ) <EOL> name = _OPID_RE . sub ( r"<STR_LIT>" , name ) <EOL> elems = name . split ( "<STR_LIT:U+002C>" ) <EOL> return elems <EOL> def _NameToId ( name ) : <EOL> """<STR_LIT>""" <EOL> if not name . startswith ( "<STR_LIT>" ) : <EOL> return None <EOL> return "<STR_LIT:_>" . join ( n . upper ( ) for n in _NameComponents ( name ) ) <EOL> def NameToReasonSrc ( name , prefix ) : <EOL> """<STR_LIT>""" <EOL> if not name . startswith ( "<STR_LIT>" ) : <EOL> return None <EOL> return "<STR_LIT>" % ( prefix , <EOL> "<STR_LIT:_>" . join ( n . lower ( ) for n in _NameComponents ( name ) ) ) <EOL> class _AutoOpParamSlots ( outils . AutoSlots ) : <EOL> """<STR_LIT>""" <EOL> def __new__ ( mcs , name , bases , attrs ) : <EOL> """<STR_LIT>""" <EOL> assert "<STR_LIT>" not in attrs , "<STR_LIT>" % name <EOL> slots = mcs . _GetSlots ( attrs ) <EOL> assert "<STR_LIT>" not in attrs or attrs [ "<STR_LIT>" ] in slots , "<STR_LIT>" % name <EOL> assert ( "<STR_LIT>" not in attrs or <EOL> callable ( attrs [ "<STR_LIT>" ] ) ) , ( "<STR_LIT>" % <EOL> ( name , type ( attrs [ "<STR_LIT>" ] ) ) ) <EOL> attrs [ "<STR_LIT>" ] = _NameToId ( name ) <EOL> return outils . AutoSlots . __new__ ( mcs , name , bases , attrs ) <EOL> @ classmethod <EOL> def _GetSlots ( mcs , attrs ) : <EOL> """<STR_LIT>""" <EOL> params = attrs . setdefault ( "<STR_LIT>" , [ ] ) <EOL> return [ pname for ( pname , _ , _ , _ ) in params ] <EOL> class BaseOpCode ( outils . ValidatedSlots ) : <EOL> """<STR_LIT>""" <EOL> __metaclass__ = _AutoOpParamSlots <EOL> def __init__ ( self , ** kwargs ) : <EOL> outils . ValidatedSlots . __init__ ( self , ** kwargs ) <EOL> for key , default , _ , _ in self . __class__ . GetAllParams ( ) : <EOL> if not hasattr ( self , key ) : <EOL> setattr ( self , key , default ) <EOL> def __getstate__ ( self ) : <EOL> """<STR_LIT>""" <EOL> state = { } <EOL> for name in self . GetAllSlots ( ) : <EOL> if hasattr ( self , name ) : <EOL> state [ name ] = getattr ( self , name ) <EOL> return state <EOL> def __setstate__ ( self , state ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( state , dict ) : <EOL> raise ValueError ( "<STR_LIT>" % <EOL> type ( state ) ) <EOL> for name in self . GetAllSlots ( ) : <EOL> if name not in state and hasattr ( self , name ) : <EOL> delattr ( self , name ) <EOL> for name in state : <EOL> setattr ( self , name , state [ name ] ) <EOL> @ classmethod <EOL> def GetAllParams ( cls ) : <EOL> """<STR_LIT>""" <EOL> slots = [ ] <EOL> for parent in cls . __mro__ : <EOL> slots . extend ( getattr ( parent , "<STR_LIT>" , [ ] ) ) <EOL> return slots <EOL> def Validate ( self , set_defaults ) : <EOL> """<STR_LIT>""" <EOL> for ( attr_name , default , test , _ ) in self . GetAllParams ( ) : <EOL> assert callable ( test ) <EOL> if hasattr ( self , attr_name ) : <EOL> attr_val = getattr ( self , attr_name ) <EOL> else : <EOL> attr_val = copy . deepcopy ( default ) <EOL> if test ( attr_val ) : <EOL> if set_defaults : <EOL> setattr ( self , attr_name , attr_val ) <EOL> elif ht . TInt ( attr_val ) and test ( float ( attr_val ) ) : <EOL> if set_defaults : <EOL> setattr ( self , attr_name , float ( attr_val ) ) <EOL> else : <EOL> logging . error ( "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> self . OP_ID , attr_name , type ( attr_val ) , attr_val , test ) <EOL> if attr_val is None : <EOL> logging . error ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> self . OP_ID , attr_name ) <EOL> raise errors . OpPrereqError ( "<STR_LIT>" % <EOL> ( self . OP_ID , attr_name ) , <EOL> errors . ECODE_INVAL ) <EOL> def BuildJobDepCheck ( relative ) : <EOL> """<STR_LIT>""" <EOL> if relative : <EOL> job_id = ht . TOr ( ht . TJobId , ht . TRelativeJobId ) <EOL> else : <EOL> job_id = ht . TJobId <EOL> job_dep = ht . TAnd ( ht . TOr ( ht . TListOf ( ht . TAny ) , ht . TTuple ) , <EOL> ht . TIsLength ( <NUM_LIT:2> ) , <EOL> ht . TItems ( [ job_id , <EOL> ht . TListOf ( ht . TElemOf ( constants . JOBS_FINALIZED ) ) ] ) ) <EOL> return ht . TMaybe ( ht . TListOf ( job_dep ) ) <EOL> TNoRelativeJobDependencies = BuildJobDepCheck ( False ) </s>
