<s> """<STR_LIT>""" <EOL> import operator <EOL> from ganeti import utils <EOL> from ganeti import constants <EOL> from ganeti import pathutils <EOL> import qa_config <EOL> import qa_error <EOL> import qa_utils <EOL> from qa_utils import AssertIn , AssertCommand <EOL> def RemoveInstance ( instance ) : <EOL> AssertCommand ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , instance . name ] ) <EOL> def GetGenericAddParameters ( inst , disk_template , force_mac = None ) : <EOL> params = [ "<STR_LIT>" ] <EOL> params . append ( "<STR_LIT>" % ( constants . BE_MINMEM , <EOL> qa_config . get ( constants . BE_MINMEM ) , <EOL> constants . BE_MAXMEM , <EOL> qa_config . get ( constants . BE_MAXMEM ) ) ) <EOL> if disk_template != constants . DT_DISKLESS : <EOL> for idx , disk in enumerate ( qa_config . GetDiskOptions ( ) ) : <EOL> size = disk . get ( "<STR_LIT:size>" ) <EOL> name = disk . get ( "<STR_LIT:name>" ) <EOL> diskparams = "<STR_LIT>" % ( idx , size ) <EOL> if name : <EOL> diskparams += "<STR_LIT>" % name <EOL> if qa_config . AreSpindlesSupported ( ) : <EOL> spindles = disk . get ( "<STR_LIT>" ) <EOL> if spindles is None : <EOL> raise qa_error . Error ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> diskparams += "<STR_LIT>" % spindles <EOL> params . extend ( [ "<STR_LIT>" , diskparams ] ) <EOL> if force_mac : <EOL> nic0_mac = force_mac <EOL> else : <EOL> nic0_mac = inst . GetNicMacAddr ( <NUM_LIT:0> , None ) <EOL> if nic0_mac : <EOL> params . extend ( [ "<STR_LIT>" , "<STR_LIT>" % nic0_mac ] ) <EOL> return params <EOL> def _CreateInstanceByDiskTemplateRaw ( nodes_spec , disk_template , fail = False ) : <EOL> """<STR_LIT>""" <EOL> instance = qa_config . AcquireInstance ( ) <EOL> try : <EOL> cmd = ( [ "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" % qa_config . get ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" % disk_template , <EOL> "<STR_LIT>" % nodes_spec ] + <EOL> GetGenericAddParameters ( instance , disk_template ) ) <EOL> cmd . append ( instance . name ) <EOL> AssertCommand ( cmd , fail = fail ) <EOL> if not fail : <EOL> CheckSsconfInstanceList ( instance . name ) <EOL> instance . SetDiskTemplate ( disk_template ) <EOL> return instance <EOL> except : <EOL> instance . Release ( ) <EOL> raise <EOL> assert fail <EOL> instance . Release ( ) <EOL> return None <EOL> def CreateInstanceDrbd8 ( nodes , fail = False ) : <EOL> """<STR_LIT>""" <EOL> assert len ( nodes ) > <NUM_LIT:1> <EOL> return _CreateInstanceByDiskTemplateRaw ( <EOL> "<STR_LIT::>" . join ( map ( operator . attrgetter ( "<STR_LIT>" ) , nodes ) ) , <EOL> constants . DT_DRBD8 , fail = fail ) <EOL> def CreateInstanceByDiskTemplateOneNode ( nodes , disk_template , fail = False ) : <EOL> """<STR_LIT>""" <EOL> assert len ( nodes ) > <NUM_LIT:0> <EOL> return _CreateInstanceByDiskTemplateRaw ( nodes [ <NUM_LIT:0> ] . primary , disk_template , <EOL> fail = fail ) <EOL> def CreateInstanceByDiskTemplate ( nodes , disk_template , fail = False ) : <EOL> """<STR_LIT>""" <EOL> if disk_template == constants . DT_DRBD8 : <EOL> return CreateInstanceDrbd8 ( nodes , fail = fail ) <EOL> elif disk_template in [ constants . DT_DISKLESS , constants . DT_PLAIN , <EOL> constants . DT_FILE ] : <EOL> return CreateInstanceByDiskTemplateOneNode ( nodes , disk_template , fail = fail ) <EOL> else : <EOL> return CreateInstanceByDiskTemplateOneNode ( nodes , disk_template , fail = fail ) <EOL> def _ReadSsconfInstanceList ( ) : <EOL> """<STR_LIT>""" <EOL> master = qa_config . GetMasterNode ( ) <EOL> ssconf_path = utils . PathJoin ( pathutils . DATA_DIR , <EOL> "<STR_LIT>" % constants . SS_INSTANCE_LIST ) <EOL> cmd = [ "<STR_LIT>" , qa_utils . MakeNodePath ( master , ssconf_path ) ] <EOL> return qa_utils . GetCommandOutput ( master . primary , <EOL> utils . ShellQuoteArgs ( cmd ) ) . splitlines ( ) <EOL> def CheckSsconfInstanceList ( instance ) : <EOL> """<STR_LIT>""" <EOL> AssertIn ( qa_utils . ResolveInstanceName ( instance ) , <EOL> _ReadSsconfInstanceList ( ) ) </s>
