<s> """<STR_LIT>""" <EOL> from ganeti import compat <EOL> from ganeti import constants <EOL> from ganeti import errors <EOL> from ganeti import ht <EOL> from ganeti import outils <EOL> from ganeti import opcodes <EOL> import ganeti . rpc . node as rpc <EOL> from ganeti import serializer <EOL> from ganeti import utils <EOL> import ganeti . masterd . instance as gmi <EOL> import logging <EOL> _STRING_LIST = ht . TListOf ( ht . TString ) <EOL> _JOB_LIST = ht . TListOf ( ht . TListOf ( ht . TStrictDict ( True , False , { <EOL> "<STR_LIT>" : ht . TElemOf ( [ opcodes . OpInstanceFailover . OP_ID , <EOL> opcodes . OpInstanceMigrate . OP_ID , <EOL> opcodes . OpInstanceReplaceDisks . OP_ID ] ) , <EOL> } ) ) ) <EOL> _NEVAC_MOVED = ht . TListOf ( ht . TAnd ( ht . TIsLength ( <NUM_LIT:3> ) , <EOL> ht . TItems ( [ ht . TNonEmptyString , <EOL> ht . TNonEmptyString , <EOL> ht . TListOf ( ht . TNonEmptyString ) , <EOL> ] ) ) ) <EOL> _NEVAC_FAILED = ht . TListOf ( ht . TAnd ( ht . TIsLength ( <NUM_LIT:2> ) , <EOL> ht . TItems ( [ ht . TNonEmptyString , <EOL> ht . TMaybeString , <EOL> ] ) ) ) <EOL> _NEVAC_RESULT = ht . TAnd ( ht . TIsLength ( <NUM_LIT:3> ) , <EOL> ht . TItems ( [ _NEVAC_MOVED , _NEVAC_FAILED , _JOB_LIST ] ) ) <EOL> _INST_NAME = ( "<STR_LIT:name>" , ht . TNonEmptyString ) <EOL> _INST_UUID = ( "<STR_LIT>" , ht . TNonEmptyString ) <EOL> class _AutoReqParam ( outils . AutoSlots ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def _GetSlots ( mcs , attrs ) : <EOL> """<STR_LIT>""" <EOL> params = attrs . setdefault ( "<STR_LIT>" , [ ] ) <EOL> return [ slot for ( slot , _ ) in params ] <EOL> class IARequestBase ( outils . ValidatedSlots ) : <EOL> """<STR_LIT>""" <EOL> __metaclass__ = _AutoReqParam <EOL> MODE = NotImplemented <EOL> REQ_PARAMS = [ ] <EOL> REQ_RESULT = NotImplemented <EOL> def __init__ ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> outils . ValidatedSlots . __init__ ( self , ** kwargs ) <EOL> self . Validate ( ) <EOL> def Validate ( self ) : <EOL> """<STR_LIT>""" <EOL> assert self . MODE in constants . VALID_IALLOCATOR_MODES <EOL> for ( param , validator ) in self . REQ_PARAMS : <EOL> if not hasattr ( self , param ) : <EOL> raise errors . OpPrereqError ( "<STR_LIT>" % param , <EOL> errors . ECODE_INVAL ) <EOL> value = getattr ( self , param ) <EOL> if not validator ( value ) : <EOL> raise errors . OpPrereqError ( ( "<STR_LIT>" <EOL> "<STR_LIT>" ) % <EOL> ( param , type ( value ) , value ) , <EOL> errors . ECODE_INVAL ) <EOL> def GetRequest ( self , cfg ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def GetExtraParams ( self ) : <EOL> """<STR_LIT>""" <EOL> return { } <EOL> def ValidateResult ( self , ia , result ) : <EOL> """<STR_LIT>""" <EOL> if ia . success and not self . REQ_RESULT ( result ) : <EOL> raise errors . ResultValidationError ( "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> ( self . REQ_RESULT , result ) ) <EOL> class IAReqInstanceAlloc ( IARequestBase ) : <EOL> """<STR_LIT>""" <EOL> MODE = constants . IALLOCATOR_MODE_ALLOC <EOL> REQ_PARAMS = [ <EOL> _INST_NAME , <EOL> ( "<STR_LIT>" , ht . TNonNegativeInt ) , <EOL> ( "<STR_LIT>" , ht . TNonNegativeInt ) , <EOL> ( "<STR_LIT>" , ht . TListOf ( ht . TDict ) ) , <EOL> ( "<STR_LIT>" , ht . TString ) , <EOL> ( "<STR_LIT>" , ht . TMaybe ( ht . TNonEmptyString ) ) , <EOL> ( "<STR_LIT>" , ht . TString ) , <EOL> ( "<STR_LIT>" , _STRING_LIST ) , <EOL> ( "<STR_LIT>" , ht . TListOf ( ht . TDict ) ) , <EOL> ( "<STR_LIT>" , ht . TInt ) , <EOL> ( "<STR_LIT>" , ht . TString ) , <EOL> ( "<STR_LIT>" , ht . TMaybeListOf ( ht . TNonEmptyString ) ) , <EOL> ] <EOL> REQ_RESULT = ht . TList <EOL> def RequiredNodes ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . disk_template in constants . DTS_INT_MIRROR : <EOL> return <NUM_LIT:2> <EOL> else : <EOL> return <NUM_LIT:1> <EOL> def GetRequest ( self , cfg ) : <EOL> """<STR_LIT>""" <EOL> for d in self . disks : <EOL> d [ constants . IDISK_TYPE ] = self . disk_template <EOL> disk_space = gmi . ComputeDiskSize ( self . disks ) <EOL> return { <EOL> "<STR_LIT:name>" : self . name , <EOL> "<STR_LIT>" : self . disk_template , <EOL> "<STR_LIT>" : self . group_name , <EOL> "<STR_LIT>" : self . tags , <EOL> "<STR_LIT>" : self . os , <EOL> "<STR_LIT>" : self . vcpus , <EOL> "<STR_LIT>" : self . memory , <EOL> "<STR_LIT>" : self . spindle_use , <EOL> "<STR_LIT>" : self . disks , <EOL> "<STR_LIT>" : disk_space , <EOL> "<STR_LIT>" : self . nics , <EOL> "<STR_LIT>" : self . RequiredNodes ( ) , <EOL> "<STR_LIT>" : self . hypervisor , <EOL> } <EOL> def ValidateResult ( self , ia , result ) : <EOL> """<STR_LIT>""" <EOL> IARequestBase . ValidateResult ( self , ia , result ) <EOL> if ia . success and len ( result ) != self . RequiredNodes ( ) : <EOL> raise errors . ResultValidationError ( "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> ( len ( result ) , self . RequiredNodes ( ) ) ) <EOL> class IAReqInstanceAllocateSecondary ( IARequestBase ) : <EOL> """<STR_LIT>""" <EOL> MODE = constants . IALLOCATOR_MODE_ALLOCATE_SECONDARY <EOL> REQ_PARAMS = [ <EOL> _INST_NAME , <EOL> ] <EOL> REQ_RESULT = ht . TString <EOL> def GetRequest ( self , cfg ) : <EOL> return { <EOL> "<STR_LIT:name>" : self . name <EOL> } <EOL> class IAReqMultiInstanceAlloc ( IARequestBase ) : <EOL> """<STR_LIT>""" <EOL> MODE = constants . IALLOCATOR_MODE_MULTI_ALLOC <EOL> REQ_PARAMS = [ <EOL> ( "<STR_LIT>" , ht . TListOf ( ht . TInstanceOf ( IAReqInstanceAlloc ) ) ) , <EOL> ] <EOL> _MASUCCESS = ht . TListOf ( ht . TAnd ( ht . TIsLength ( <NUM_LIT:2> ) , <EOL> ht . TItems ( [ ht . TNonEmptyString , <EOL> ht . TListOf ( ht . TNonEmptyString ) , <EOL> ] ) ) ) <EOL> _MAFAILED = ht . TListOf ( ht . TNonEmptyString ) <EOL> REQ_RESULT = ht . TAnd ( ht . TList , ht . TIsLength ( <NUM_LIT:2> ) , <EOL> ht . TItems ( [ _MASUCCESS , _MAFAILED ] ) ) <EOL> def GetRequest ( self , cfg ) : <EOL> return { <EOL> "<STR_LIT>" : [ iareq . GetRequest ( cfg ) for iareq in self . instances ] , <EOL> } <EOL> class IAReqRelocate ( IARequestBase ) : <EOL> """<STR_LIT>""" <EOL> MODE = constants . IALLOCATOR_MODE_RELOC <EOL> REQ_PARAMS = [ <EOL> _INST_UUID , <EOL> ( "<STR_LIT>" , _STRING_LIST ) , <EOL> ] <EOL> REQ_RESULT = ht . TList <EOL> def GetRequest ( self , cfg ) : <EOL> """<STR_LIT>""" <EOL> instance = cfg . GetInstanceInfo ( self . inst_uuid ) <EOL> disks = cfg . GetInstanceDisks ( self . inst_uuid ) <EOL> if instance is None : <EOL> raise errors . ProgrammerError ( "<STR_LIT>" <EOL> "<STR_LIT>" % self . inst_uuid ) <EOL> if not utils . AllDiskOfType ( disks , constants . DTS_MIRRORED ) : <EOL> raise errors . OpPrereqError ( "<STR_LIT>" , <EOL> errors . ECODE_INVAL ) <EOL> secondary_nodes = cfg . GetInstanceSecondaryNodes ( instance . uuid ) <EOL> if ( utils . AnyDiskOfType ( disks , constants . DTS_INT_MIRROR ) and <EOL> len ( secondary_nodes ) != <NUM_LIT:1> ) : <EOL> raise errors . OpPrereqError ( "<STR_LIT>" , <EOL> errors . ECODE_STATE ) <EOL> disk_sizes = [ { constants . IDISK_SIZE : disk . size , <EOL> constants . IDISK_TYPE : disk . dev_type } for disk in disks ] <EOL> disk_space = gmi . ComputeDiskSize ( disk_sizes ) <EOL> return { <EOL> "<STR_LIT:name>" : instance . name , <EOL> "<STR_LIT>" : disk_space , <EOL> "<STR_LIT>" : <NUM_LIT:1> , <EOL> "<STR_LIT>" : cfg . GetNodeNames ( self . relocate_from_node_uuids ) , <EOL> } <EOL> def ValidateResult ( self , ia , result ) : <EOL> """<STR_LIT>""" <EOL> IARequestBase . ValidateResult ( self , ia , result ) <EOL> node2group = dict ( ( name , ndata [ "<STR_LIT>" ] ) <EOL> for ( name , ndata ) in ia . in_data [ "<STR_LIT>" ] . items ( ) ) <EOL> fn = compat . partial ( self . _NodesToGroups , node2group , <EOL> ia . in_data [ "<STR_LIT>" ] ) <EOL> instance = ia . cfg . GetInstanceInfo ( self . inst_uuid ) <EOL> request_groups = fn ( ia . cfg . GetNodeNames ( self . relocate_from_node_uuids ) + <EOL> ia . cfg . GetNodeNames ( [ instance . primary_node ] ) ) <EOL> result_groups = fn ( result + ia . cfg . GetNodeNames ( [ instance . primary_node ] ) ) <EOL> if ia . success and not set ( result_groups ) . issubset ( request_groups ) : <EOL> raise errors . ResultValidationError ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> ( utils . CommaJoin ( result_groups ) , <EOL> utils . CommaJoin ( request_groups ) ) ) <EOL> @ staticmethod <EOL> def _NodesToGroups ( node2group , groups , nodes ) : <EOL> """<STR_LIT>""" <EOL> result = set ( ) <EOL> for node in nodes : <EOL> try : <EOL> group_uuid = node2group [ node ] <EOL> except KeyError : <EOL> pass <EOL> else : <EOL> try : <EOL> group = groups [ group_uuid ] <EOL> except KeyError : <EOL> group_name = group_uuid <EOL> else : <EOL> group_name = group [ "<STR_LIT:name>" ] <EOL> result . add ( group_name ) <EOL> return sorted ( result ) <EOL> class IAReqNodeEvac ( IARequestBase ) : <EOL> """<STR_LIT>""" <EOL> MODE = constants . IALLOCATOR_MODE_NODE_EVAC <EOL> REQ_PARAMS = [ <EOL> ( "<STR_LIT>" , _STRING_LIST ) , <EOL> ( "<STR_LIT>" , ht . TEvacMode ) , <EOL> ( "<STR_LIT>" , ht . TMaybe ( ht . TBool ) ) , <EOL> ] <EOL> REQ_RESULT = _NEVAC_RESULT <EOL> def GetRequest ( self , cfg ) : <EOL> """<STR_LIT>""" <EOL> return { <EOL> "<STR_LIT>" : self . instances , <EOL> "<STR_LIT>" : self . evac_mode , <EOL> } <EOL> def GetExtraParams ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . ignore_soft_errors : <EOL> return { "<STR_LIT>" : None } <EOL> else : <EOL> return { } <EOL> class IAReqGroupChange ( IARequestBase ) : <EOL> """<STR_LIT>""" <EOL> MODE = constants . IALLOCATOR_MODE_CHG_GROUP <EOL> REQ_PARAMS = [ <EOL> ( "<STR_LIT>" , _STRING_LIST ) , <EOL> ( "<STR_LIT>" , _STRING_LIST ) , <EOL> ] <EOL> REQ_RESULT = _NEVAC_RESULT <EOL> def GetRequest ( self , cfg ) : <EOL> """<STR_LIT>""" <EOL> return { <EOL> "<STR_LIT>" : self . instances , <EOL> "<STR_LIT>" : self . target_groups , <EOL> } <EOL> class IAllocator ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , cfg , rpc_runner , req ) : <EOL> self . cfg = cfg <EOL> self . rpc = rpc_runner <EOL> self . req = req <EOL> self . in_text = self . out_text = self . in_data = self . out_data = None <EOL> self . success = self . info = self . result = None <EOL> self . _BuildInputData ( req ) <EOL> def _ComputeClusterDataNodeInfo ( self , disk_templates , node_list , <EOL> cluster_info , hypervisor_name ) : <EOL> """<STR_LIT>""" <EOL> storage_units_raw = utils . storage . GetStorageUnits ( self . cfg , disk_templates ) <EOL> storage_units = rpc . PrepareStorageUnitsForNodes ( self . cfg , storage_units_raw , <EOL> node_list ) <EOL> hvspecs = [ ( hypervisor_name , cluster_info . hvparams [ hypervisor_name ] ) ] <EOL> return self . rpc . call_node_info ( node_list , storage_units , hvspecs ) <EOL> def _ComputeClusterData ( self , disk_template = None ) : <EOL> """<STR_LIT>""" <EOL> cfg = self . cfg . GetDetachedConfig ( ) <EOL> cluster_info = cfg . GetClusterInfo ( ) <EOL> data = { <EOL> "<STR_LIT:version>" : constants . IALLOCATOR_VERSION , <EOL> "<STR_LIT>" : cluster_info . cluster_name , <EOL> "<STR_LIT>" : list ( cluster_info . GetTags ( ) ) , <EOL> "<STR_LIT>" : list ( cluster_info . enabled_hypervisors ) , <EOL> "<STR_LIT>" : cluster_info . ipolicy , <EOL> } <EOL> ginfo = cfg . GetAllNodeGroupsInfo ( ) <EOL> ninfo = cfg . GetAllNodesInfo ( ) <EOL> iinfo = cfg . GetAllInstancesInfo ( ) <EOL> i_list = [ ( inst , cluster_info . FillBE ( inst ) ) for inst in iinfo . values ( ) ] <EOL> node_list = [ n . uuid for n in ninfo . values ( ) if n . vm_capable ] <EOL> if isinstance ( self . req , IAReqInstanceAlloc ) : <EOL> hypervisor_name = self . req . hypervisor <EOL> elif isinstance ( self . req , IAReqRelocate ) : <EOL> hypervisor_name = iinfo [ self . req . inst_uuid ] . hypervisor <EOL> else : <EOL> hypervisor_name = cluster_info . primary_hypervisor <EOL> if not disk_template : <EOL> disk_template = cluster_info . enabled_disk_templates [ <NUM_LIT:0> ] <EOL> node_data = self . _ComputeClusterDataNodeInfo ( [ disk_template ] , node_list , <EOL> cluster_info , hypervisor_name ) <EOL> node_iinfo = self . rpc . call_all_instances_info ( node_list , <EOL> cluster_info . enabled_hypervisors , <EOL> cluster_info . hvparams ) <EOL> data [ "<STR_LIT>" ] = self . _ComputeNodeGroupData ( cluster_info , ginfo ) <EOL> config_ndata = self . _ComputeBasicNodeData ( cfg , ninfo ) <EOL> data [ "<STR_LIT>" ] = self . _ComputeDynamicNodeData ( <EOL> ninfo , node_data , node_iinfo , i_list , config_ndata , disk_template ) <EOL> assert len ( data [ "<STR_LIT>" ] ) == len ( ninfo ) , "<STR_LIT>" <EOL> data [ "<STR_LIT>" ] = self . _ComputeInstanceData ( cfg , cluster_info , i_list ) <EOL> self . in_data = data <EOL> @ staticmethod <EOL> def _ComputeNodeGroupData ( cluster , ginfo ) : <EOL> """<STR_LIT>""" <EOL> ng = dict ( ( guuid , { <EOL> "<STR_LIT:name>" : gdata . name , <EOL> "<STR_LIT>" : gdata . alloc_policy , <EOL> "<STR_LIT>" : [ net_uuid for net_uuid , _ in gdata . networks . items ( ) ] , <EOL> "<STR_LIT>" : gmi . CalculateGroupIPolicy ( cluster , gdata ) , <EOL> "<STR_LIT>" : list ( gdata . GetTags ( ) ) , <EOL> } ) <EOL> for guuid , gdata in ginfo . items ( ) ) <EOL> return ng <EOL> @ staticmethod <EOL> def _ComputeBasicNodeData ( cfg , node_cfg ) : <EOL> """<STR_LIT>""" <EOL> node_results = dict ( ( ninfo . name , { <EOL> "<STR_LIT>" : list ( ninfo . GetTags ( ) ) , <EOL> "<STR_LIT>" : ninfo . primary_ip , <EOL> "<STR_LIT>" : ninfo . secondary_ip , <EOL> "<STR_LIT>" : ninfo . offline , <EOL> "<STR_LIT>" : ninfo . drained , <EOL> "<STR_LIT>" : ninfo . master_candidate , <EOL> "<STR_LIT>" : ninfo . group , <EOL> "<STR_LIT>" : ninfo . master_capable , <EOL> "<STR_LIT>" : ninfo . vm_capable , <EOL> "<STR_LIT>" : cfg . GetNdParams ( ninfo ) , <EOL> "<STR_LIT>" : cfg . GetFilledHvStateParams ( ninfo ) <EOL> } ) <EOL> for ninfo in node_cfg . values ( ) ) <EOL> return node_results <EOL> @ staticmethod <EOL> def _GetAttributeFromHypervisorNodeData ( hv_info , node_name , attr ) : <EOL> """<STR_LIT>""" <EOL> if attr not in hv_info : <EOL> raise errors . OpExecError ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( node_name , attr ) ) <EOL> value = hv_info [ attr ] <EOL> if not isinstance ( value , int ) : <EOL> raise errors . OpExecError ( "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> ( node_name , attr , value ) ) <EOL> return value <EOL> @ staticmethod <EOL> def _ComputeStorageDataFromSpaceInfoByTemplate ( <EOL> space_info , node_name , disk_template ) : <EOL> """<STR_LIT>""" <EOL> storage_type = constants . MAP_DISK_TEMPLATE_STORAGE_TYPE [ disk_template ] <EOL> if storage_type not in constants . STS_REPORT : <EOL> total_disk = total_spindles = <NUM_LIT:0> <EOL> free_disk = free_spindles = <NUM_LIT:0> <EOL> else : <EOL> template_space_info = utils . storage . LookupSpaceInfoByDiskTemplate ( <EOL> space_info , disk_template ) <EOL> if not template_space_info : <EOL> raise errors . OpExecError ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( node_name , disk_template ) ) <EOL> total_disk = template_space_info [ "<STR_LIT>" ] <EOL> free_disk = template_space_info [ "<STR_LIT>" ] <EOL> total_spindles = <NUM_LIT:0> <EOL> free_spindles = <NUM_LIT:0> <EOL> if disk_template in constants . DTS_LVM : <EOL> lvm_pv_info = utils . storage . LookupSpaceInfoByStorageType ( <EOL> space_info , constants . ST_LVM_PV ) <EOL> if lvm_pv_info : <EOL> total_spindles = lvm_pv_info [ "<STR_LIT>" ] <EOL> free_spindles = lvm_pv_info [ "<STR_LIT>" ] <EOL> return ( total_disk , free_disk , total_spindles , free_spindles ) <EOL> @ staticmethod <EOL> def _ComputeStorageDataFromSpaceInfo ( space_info , node_name , has_lvm ) : <EOL> """<STR_LIT>""" <EOL> if has_lvm : <EOL> lvm_vg_info = utils . storage . LookupSpaceInfoByStorageType ( <EOL> space_info , constants . ST_LVM_VG ) <EOL> if not lvm_vg_info : <EOL> raise errors . OpExecError ( "<STR_LIT>" <EOL> % ( node_name ) ) <EOL> total_disk = lvm_vg_info [ "<STR_LIT>" ] <EOL> free_disk = lvm_vg_info [ "<STR_LIT>" ] <EOL> lvm_pv_info = utils . storage . LookupSpaceInfoByStorageType ( <EOL> space_info , constants . ST_LVM_PV ) <EOL> if not lvm_pv_info : <EOL> raise errors . OpExecError ( "<STR_LIT>" <EOL> % ( node_name ) ) <EOL> total_spindles = lvm_pv_info [ "<STR_LIT>" ] <EOL> free_spindles = lvm_pv_info [ "<STR_LIT>" ] <EOL> else : <EOL> total_disk = free_disk = <NUM_LIT:0> <EOL> total_spindles = free_spindles = <NUM_LIT:0> <EOL> return ( total_disk , free_disk , total_spindles , free_spindles ) <EOL> @ staticmethod <EOL> def _ComputeInstanceMemory ( instance_list , node_instances_info , node_uuid , <EOL> input_mem_free ) : <EOL> """<STR_LIT>""" <EOL> i_p_mem = i_p_up_mem = <NUM_LIT:0> <EOL> mem_free = input_mem_free <EOL> for iinfo , beinfo in instance_list : <EOL> if iinfo . primary_node == node_uuid : <EOL> i_p_mem += beinfo [ constants . BE_MAXMEM ] <EOL> if iinfo . name not in node_instances_info [ node_uuid ] . payload : <EOL> i_used_mem = <NUM_LIT:0> <EOL> else : <EOL> i_used_mem = int ( node_instances_info [ node_uuid ] <EOL> . payload [ iinfo . name ] [ "<STR_LIT>" ] ) <EOL> i_mem_diff = beinfo [ constants . BE_MAXMEM ] - i_used_mem <EOL> if iinfo . admin_state == constants . ADMINST_UP and not iinfo . forthcoming : <EOL> mem_free -= max ( <NUM_LIT:0> , i_mem_diff ) <EOL> i_p_up_mem += beinfo [ constants . BE_MAXMEM ] <EOL> return ( i_p_mem , i_p_up_mem , mem_free ) <EOL> def _ComputeDynamicNodeData ( self , node_cfg , node_data , node_iinfo , i_list , <EOL> node_results , disk_template ) : <EOL> """<STR_LIT>""" <EOL> node_results = dict ( node_results ) <EOL> for nuuid , nresult in node_data . items ( ) : <EOL> ninfo = node_cfg [ nuuid ] <EOL> assert ninfo . name in node_results , "<STR_LIT>" % ninfo . name <EOL> if not ninfo . offline : <EOL> nresult . Raise ( "<STR_LIT>" % ninfo . name ) <EOL> node_iinfo [ nuuid ] . Raise ( "<STR_LIT>" % <EOL> ninfo . name ) <EOL> ( _ , space_info , ( hv_info , ) ) = nresult . payload <EOL> mem_free = self . _GetAttributeFromHypervisorNodeData ( hv_info , ninfo . name , <EOL> "<STR_LIT>" ) <EOL> ( i_p_mem , i_p_up_mem , mem_free ) = self . _ComputeInstanceMemory ( <EOL> i_list , node_iinfo , nuuid , mem_free ) <EOL> ( total_disk , free_disk , total_spindles , free_spindles ) = self . _ComputeStorageDataFromSpaceInfoByTemplate ( <EOL> space_info , ninfo . name , disk_template ) <EOL> pnr_dyn = { <EOL> "<STR_LIT>" : self . _GetAttributeFromHypervisorNodeData ( <EOL> hv_info , ninfo . name , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : self . _GetAttributeFromHypervisorNodeData ( <EOL> hv_info , ninfo . name , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : mem_free , <EOL> "<STR_LIT>" : total_disk , <EOL> "<STR_LIT>" : free_disk , <EOL> "<STR_LIT>" : total_spindles , <EOL> "<STR_LIT>" : free_spindles , <EOL> "<STR_LIT>" : self . _GetAttributeFromHypervisorNodeData ( <EOL> hv_info , ninfo . name , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : self . _GetAttributeFromHypervisorNodeData ( <EOL> hv_info , ninfo . name , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : i_p_mem , <EOL> "<STR_LIT>" : i_p_up_mem , <EOL> } <EOL> pnr_dyn . update ( node_results [ ninfo . name ] ) <EOL> node_results [ ninfo . name ] = pnr_dyn <EOL> return node_results <EOL> @ staticmethod <EOL> def _ComputeInstanceData ( cfg , cluster_info , i_list ) : <EOL> """<STR_LIT>""" <EOL> instance_data = { } <EOL> for iinfo , beinfo in i_list : <EOL> nic_data = [ ] <EOL> for nic in iinfo . nics : <EOL> filled_params = cluster_info . SimpleFillNIC ( nic . nicparams ) <EOL> nic_dict = { <EOL> "<STR_LIT>" : nic . mac , <EOL> "<STR_LIT>" : nic . ip , <EOL> "<STR_LIT>" : filled_params [ constants . NIC_MODE ] , <EOL> "<STR_LIT>" : filled_params [ constants . NIC_LINK ] , <EOL> } <EOL> if filled_params [ constants . NIC_MODE ] == constants . NIC_MODE_BRIDGED : <EOL> nic_dict [ "<STR_LIT>" ] = filled_params [ constants . NIC_LINK ] <EOL> nic_data . append ( nic_dict ) <EOL> inst_disks = cfg . GetInstanceDisks ( iinfo . uuid ) <EOL> inst_disktemplate = cfg . GetInstanceDiskTemplate ( iinfo . uuid ) <EOL> pir = { <EOL> "<STR_LIT>" : list ( iinfo . GetTags ( ) ) , <EOL> "<STR_LIT>" : iinfo . admin_state , <EOL> "<STR_LIT>" : beinfo [ constants . BE_VCPUS ] , <EOL> "<STR_LIT>" : beinfo [ constants . BE_MAXMEM ] , <EOL> "<STR_LIT>" : beinfo [ constants . BE_SPINDLE_USE ] , <EOL> "<STR_LIT>" : iinfo . os , <EOL> "<STR_LIT>" : [ cfg . GetNodeName ( iinfo . primary_node ) ] + <EOL> cfg . GetNodeNames ( <EOL> cfg . GetInstanceSecondaryNodes ( iinfo . uuid ) ) , <EOL> "<STR_LIT>" : nic_data , <EOL> "<STR_LIT>" : [ { constants . IDISK_TYPE : dsk . dev_type , <EOL> constants . IDISK_SIZE : dsk . size , <EOL> constants . IDISK_MODE : dsk . mode , <EOL> constants . IDISK_SPINDLES : dsk . spindles } <EOL> for dsk in inst_disks ] , <EOL> "<STR_LIT>" : inst_disktemplate , <EOL> "<STR_LIT>" : iinfo . disks_active , <EOL> "<STR_LIT>" : iinfo . hypervisor , <EOL> } <EOL> pir [ "<STR_LIT>" ] = gmi . ComputeDiskSize ( pir [ "<STR_LIT>" ] ) <EOL> instance_data [ iinfo . name ] = pir <EOL> return instance_data <EOL> def _BuildInputData ( self , req ) : <EOL> """<STR_LIT>""" <EOL> request = req . GetRequest ( self . cfg ) <EOL> disk_template = None <EOL> if request . get ( "<STR_LIT>" ) is not None : <EOL> disk_template = request [ "<STR_LIT>" ] <EOL> elif isinstance ( req , IAReqRelocate ) : <EOL> disk_template = self . cfg . GetInstanceDiskTemplate ( self . req . inst_uuid ) <EOL> self . _ComputeClusterData ( disk_template = disk_template ) <EOL> request [ "<STR_LIT:type>" ] = req . MODE <EOL> if isinstance ( self . req , IAReqInstanceAlloc ) : <EOL> node_whitelist = self . req . node_whitelist <EOL> else : <EOL> node_whitelist = None <EOL> if node_whitelist is not None : <EOL> request [ "<STR_LIT>" ] = node_whitelist <EOL> self . in_data [ "<STR_LIT>" ] = request <EOL> self . in_text = serializer . Dump ( self . in_data ) <EOL> logging . debug ( "<STR_LIT>" , self . in_text ) <EOL> def Run ( self , name , validate = True , call_fn = None ) : <EOL> """<STR_LIT>""" <EOL> if call_fn is None : <EOL> call_fn = self . rpc . call_iallocator_runner <EOL> ial_params = self . cfg . GetDefaultIAllocatorParameters ( ) <EOL> for ial_param in self . req . GetExtraParams ( ) . items ( ) : <EOL> ial_params [ ial_param [ <NUM_LIT:0> ] ] = ial_param [ <NUM_LIT:1> ] <EOL> result = call_fn ( self . cfg . GetMasterNode ( ) , name , self . in_text , ial_params ) <EOL> result . Raise ( "<STR_LIT>" ) <EOL> self . out_text = result . payload <EOL> if validate : <EOL> self . _ValidateResult ( ) <EOL> def _ValidateResult ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> rdict = serializer . Load ( self . out_text ) <EOL> except Exception , err : <EOL> raise errors . OpExecError ( "<STR_LIT>" % str ( err ) ) <EOL> if not isinstance ( rdict , dict ) : <EOL> raise errors . OpExecError ( "<STR_LIT>" ) <EOL> if "<STR_LIT>" in rdict and "<STR_LIT:result>" not in rdict : <EOL> rdict [ "<STR_LIT:result>" ] = rdict [ "<STR_LIT>" ] <EOL> del rdict [ "<STR_LIT>" ] <EOL> for key in "<STR_LIT:success>" , "<STR_LIT:info>" , "<STR_LIT:result>" : <EOL> if key not in rdict : <EOL> raise errors . OpExecError ( "<STR_LIT>" <EOL> "<STR_LIT>" % key ) <EOL> setattr ( self , key , rdict [ key ] ) <EOL> self . req . ValidateResult ( self , self . result ) <EOL> self . out_data = rdict </s>
