<s> """<STR_LIT>""" <EOL> import logging <EOL> import zlib <EOL> import base64 <EOL> import pycurl <EOL> import threading <EOL> import copy <EOL> import os <EOL> from ganeti import utils <EOL> from ganeti import objects <EOL> from ganeti import http <EOL> from ganeti import serializer <EOL> from ganeti import constants <EOL> from ganeti import errors <EOL> from ganeti import netutils <EOL> from ganeti import ssconf <EOL> from ganeti import runtime <EOL> from ganeti import compat <EOL> from ganeti import rpc_defs <EOL> from ganeti import pathutils <EOL> from ganeti import vcluster <EOL> from ganeti import _generated_rpc <EOL> import ganeti . http . client <EOL> _RPC_CLIENT_HEADERS = [ <EOL> "<STR_LIT>" % http . HTTP_APP_JSON , <EOL> "<STR_LIT>" , <EOL> ] <EOL> _OFFLINE = object ( ) <EOL> def Init ( ) : <EOL> """<STR_LIT>""" <EOL> assert threading . activeCount ( ) == <NUM_LIT:1> , "<STR_LIT>" <EOL> logging . info ( "<STR_LIT>" , pycurl . version ) <EOL> pycurl . global_init ( pycurl . GLOBAL_ALL ) <EOL> def Shutdown ( ) : <EOL> """<STR_LIT>""" <EOL> pycurl . global_cleanup ( ) <EOL> def _ConfigRpcCurl ( curl ) : <EOL> noded_cert = pathutils . NODED_CERT_FILE <EOL> noded_client_cert = pathutils . NODED_CLIENT_CERT_FILE <EOL> if not os . path . exists ( noded_client_cert ) : <EOL> logging . warn ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> noded_client_cert = noded_cert <EOL> curl . setopt ( pycurl . FOLLOWLOCATION , False ) <EOL> curl . setopt ( pycurl . CAINFO , noded_cert ) <EOL> curl . setopt ( pycurl . SSL_VERIFYHOST , <NUM_LIT:0> ) <EOL> curl . setopt ( pycurl . SSL_VERIFYPEER , True ) <EOL> curl . setopt ( pycurl . SSLCERTTYPE , "<STR_LIT>" ) <EOL> curl . setopt ( pycurl . SSLCERT , noded_client_cert ) <EOL> curl . setopt ( pycurl . SSLKEYTYPE , "<STR_LIT>" ) <EOL> curl . setopt ( pycurl . SSLKEY , noded_client_cert ) <EOL> curl . setopt ( pycurl . CONNECTTIMEOUT , constants . RPC_CONNECT_TIMEOUT ) <EOL> def RunWithRPC ( fn ) : <EOL> """<STR_LIT>""" <EOL> def wrapper ( * args , ** kwargs ) : <EOL> Init ( ) <EOL> try : <EOL> return fn ( * args , ** kwargs ) <EOL> finally : <EOL> Shutdown ( ) <EOL> return wrapper <EOL> def _Compress ( _ , data ) : <EOL> """<STR_LIT>""" <EOL> if len ( data ) < <NUM_LIT> : <EOL> return ( constants . RPC_ENCODING_NONE , data ) <EOL> return ( constants . RPC_ENCODING_ZLIB_BASE64 , <EOL> base64 . b64encode ( zlib . compress ( data , <NUM_LIT:3> ) ) ) <EOL> class RpcResult ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , data = None , failed = False , offline = False , <EOL> call = None , node = None ) : <EOL> self . offline = offline <EOL> self . call = call <EOL> self . node = node <EOL> if offline : <EOL> self . fail_msg = "<STR_LIT>" <EOL> self . data = self . payload = None <EOL> elif failed : <EOL> self . fail_msg = self . _EnsureErr ( data ) <EOL> self . data = self . payload = None <EOL> else : <EOL> self . data = data <EOL> if not isinstance ( self . data , ( tuple , list ) ) : <EOL> self . fail_msg = ( "<STR_LIT>" % <EOL> type ( self . data ) ) <EOL> self . payload = None <EOL> elif len ( data ) != <NUM_LIT:2> : <EOL> self . fail_msg = ( "<STR_LIT>" <EOL> "<STR_LIT>" % len ( self . data ) ) <EOL> self . payload = None <EOL> elif not self . data [ <NUM_LIT:0> ] : <EOL> self . fail_msg = self . _EnsureErr ( self . data [ <NUM_LIT:1> ] ) <EOL> self . payload = None <EOL> else : <EOL> self . fail_msg = None <EOL> self . payload = data [ <NUM_LIT:1> ] <EOL> for attr_name in [ "<STR_LIT>" , "<STR_LIT:data>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] : <EOL> assert hasattr ( self , attr_name ) , "<STR_LIT>" % attr_name <EOL> def __repr__ ( self ) : <EOL> return ( "<STR_LIT>" % <EOL> ( self . offline , self . call , self . node , self . offline , self . fail_msg ) ) <EOL> @ staticmethod <EOL> def _EnsureErr ( val ) : <EOL> """<STR_LIT>""" <EOL> if val : <EOL> return val <EOL> else : <EOL> return "<STR_LIT>" <EOL> def Raise ( self , msg , prereq = False , ecode = None ) : <EOL> """<STR_LIT>""" <EOL> if not self . fail_msg : <EOL> return <EOL> if not msg : <EOL> msg = ( "<STR_LIT>" % <EOL> ( self . call , self . node , self . fail_msg ) ) <EOL> else : <EOL> msg = "<STR_LIT>" % ( msg , self . fail_msg ) <EOL> if prereq : <EOL> ec = errors . OpPrereqError <EOL> else : <EOL> ec = errors . OpExecError <EOL> if ecode is not None : <EOL> args = ( msg , ecode ) <EOL> else : <EOL> args = ( msg , ) <EOL> raise ec ( * args ) <EOL> def Warn ( self , msg , feedback_fn ) : <EOL> """<STR_LIT>""" <EOL> if not self . fail_msg : <EOL> return <EOL> msg = "<STR_LIT>" % ( msg , self . fail_msg ) <EOL> feedback_fn ( msg ) <EOL> def _SsconfResolver ( ssconf_ips , node_list , _ , <EOL> ssc = ssconf . SimpleStore , <EOL> nslookup_fn = netutils . Hostname . GetIP ) : <EOL> """<STR_LIT>""" <EOL> ss = ssc ( ) <EOL> family = ss . GetPrimaryIPFamily ( ) <EOL> if ssconf_ips : <EOL> iplist = ss . GetNodePrimaryIPList ( ) <EOL> ipmap = dict ( entry . split ( ) for entry in iplist ) <EOL> else : <EOL> ipmap = { } <EOL> result = [ ] <EOL> for node in node_list : <EOL> ip = ipmap . get ( node ) <EOL> if ip is None : <EOL> ip = nslookup_fn ( node , family = family ) <EOL> result . append ( ( node , ip , node ) ) <EOL> return result <EOL> class _StaticResolver : <EOL> def __init__ ( self , addresses ) : <EOL> """<STR_LIT>""" <EOL> self . _addresses = addresses <EOL> def __call__ ( self , hosts , _ ) : <EOL> """<STR_LIT>""" <EOL> assert len ( hosts ) == len ( self . _addresses ) <EOL> return zip ( hosts , self . _addresses , hosts ) <EOL> def _CheckConfigNode ( node_uuid_or_name , node , accept_offline_node ) : <EOL> """<STR_LIT>""" <EOL> if node is None : <EOL> return ( node_uuid_or_name , node_uuid_or_name , node_uuid_or_name ) <EOL> else : <EOL> if node . offline and not accept_offline_node : <EOL> ip = _OFFLINE <EOL> else : <EOL> ip = node . primary_ip <EOL> return ( node . name , ip , node_uuid_or_name ) <EOL> def _NodeConfigResolver ( single_node_fn , all_nodes_fn , node_uuids , opts ) : <EOL> """<STR_LIT>""" <EOL> accept_offline_node = ( opts is rpc_defs . ACCEPT_OFFLINE_NODE ) <EOL> assert accept_offline_node or opts is None , "<STR_LIT>" <EOL> if len ( node_uuids ) == <NUM_LIT:1> : <EOL> ( uuid , ) = node_uuids <EOL> return [ _CheckConfigNode ( uuid , single_node_fn ( uuid ) , accept_offline_node ) ] <EOL> else : <EOL> all_nodes = all_nodes_fn ( ) <EOL> return [ _CheckConfigNode ( uuid , all_nodes . get ( uuid , None ) , <EOL> accept_offline_node ) <EOL> for uuid in node_uuids ] <EOL> class _RpcProcessor : <EOL> def __init__ ( self , resolver , port , lock_monitor_cb = None ) : <EOL> """<STR_LIT>""" <EOL> self . _resolver = resolver <EOL> self . _port = port <EOL> self . _lock_monitor_cb = lock_monitor_cb <EOL> @ staticmethod <EOL> def _PrepareRequests ( hosts , port , procedure , body , read_timeout ) : <EOL> """<STR_LIT>""" <EOL> results = { } <EOL> requests = { } <EOL> assert isinstance ( body , dict ) <EOL> assert len ( body ) == len ( hosts ) <EOL> assert compat . all ( isinstance ( v , str ) for v in body . values ( ) ) <EOL> assert frozenset ( map ( lambda x : x [ <NUM_LIT:2> ] , hosts ) ) == frozenset ( body . keys ( ) ) , "<STR_LIT>" % ( hosts , body . keys ( ) ) <EOL> for ( name , ip , original_name ) in hosts : <EOL> if ip is _OFFLINE : <EOL> results [ original_name ] = RpcResult ( node = name , <EOL> offline = True , <EOL> call = procedure ) <EOL> else : <EOL> requests [ original_name ] = http . client . HttpClientRequest ( str ( ip ) , port , <EOL> http . HTTP_POST , str ( "<STR_LIT>" % procedure ) , <EOL> headers = _RPC_CLIENT_HEADERS , <EOL> post_data = body [ original_name ] , <EOL> read_timeout = read_timeout , <EOL> nicename = "<STR_LIT>" % ( name , procedure ) , <EOL> curl_config_fn = _ConfigRpcCurl ) <EOL> return ( results , requests ) <EOL> @ staticmethod <EOL> def _CombineResults ( results , requests , procedure ) : <EOL> """<STR_LIT>""" <EOL> for name , req in requests . items ( ) : <EOL> if req . success and req . resp_status_code == http . HTTP_OK : <EOL> host_result = RpcResult ( data = serializer . LoadJson ( req . resp_body ) , <EOL> node = name , call = procedure ) <EOL> else : <EOL> if req . error : <EOL> msg = req . error <EOL> else : <EOL> msg = req . resp_body <EOL> logging . error ( "<STR_LIT>" , procedure , name , msg ) <EOL> host_result = RpcResult ( data = msg , failed = True , node = name , <EOL> call = procedure ) <EOL> results [ name ] = host_result <EOL> return results <EOL> def __call__ ( self , nodes , procedure , body , read_timeout , resolver_opts , <EOL> _req_process_fn = None ) : <EOL> """<STR_LIT>""" <EOL> assert read_timeout is not None , "<STR_LIT>" % procedure <EOL> if _req_process_fn is None : <EOL> _req_process_fn = http . client . ProcessRequests <EOL> ( results , requests ) = self . _PrepareRequests ( self . _resolver ( nodes , resolver_opts ) , self . _port , <EOL> procedure , body , read_timeout ) <EOL> _req_process_fn ( requests . values ( ) , lock_monitor_cb = self . _lock_monitor_cb ) <EOL> assert not frozenset ( results ) . intersection ( requests ) <EOL> return self . _CombineResults ( results , requests , procedure ) <EOL> class _RpcClientBase : <EOL> def __init__ ( self , resolver , encoder_fn , lock_monitor_cb = None , <EOL> _req_process_fn = None ) : <EOL> """<STR_LIT>""" <EOL> proc = _RpcProcessor ( resolver , <EOL> netutils . GetDaemonPort ( constants . NODED ) , <EOL> lock_monitor_cb = lock_monitor_cb ) <EOL> self . _proc = compat . partial ( proc , _req_process_fn = _req_process_fn ) <EOL> self . _encoder = compat . partial ( self . _EncodeArg , encoder_fn ) <EOL> @ staticmethod <EOL> def _EncodeArg ( encoder_fn , node , ( argkind , value ) ) : <EOL> """<STR_LIT>""" <EOL> if argkind is None : <EOL> return value <EOL> else : <EOL> return encoder_fn ( argkind ) ( node , value ) <EOL> def _Call ( self , cdef , node_list , args ) : <EOL> """<STR_LIT>""" <EOL> ( procedure , _ , resolver_opts , timeout , argdefs , <EOL> prep_fn , postproc_fn , _ ) = cdef <EOL> if callable ( timeout ) : <EOL> read_timeout = timeout ( args ) <EOL> else : <EOL> read_timeout = timeout <EOL> if callable ( resolver_opts ) : <EOL> req_resolver_opts = resolver_opts ( args ) <EOL> else : <EOL> req_resolver_opts = resolver_opts <EOL> if len ( args ) != len ( argdefs ) : <EOL> raise errors . ProgrammerError ( "<STR_LIT>" ) <EOL> if prep_fn is None : <EOL> prep_fn = lambda _ , args : args <EOL> assert callable ( prep_fn ) <EOL> encode_args_fn = lambda node : map ( compat . partial ( self . _encoder , node ) , <EOL> zip ( map ( compat . snd , argdefs ) , args ) ) <EOL> pnbody = dict ( <EOL> ( n , <EOL> serializer . DumpJson ( prep_fn ( n , encode_args_fn ( n ) ) , <EOL> private_encoder = serializer . EncodeWithPrivateFields ) ) <EOL> for n in node_list <EOL> ) <EOL> result = self . _proc ( node_list , procedure , pnbody , read_timeout , <EOL> req_resolver_opts ) <EOL> if postproc_fn : <EOL> return dict ( map ( lambda ( key , value ) : ( key , postproc_fn ( value ) ) , <EOL> result . items ( ) ) ) <EOL> else : <EOL> return result <EOL> def _ObjectToDict ( _ , value ) : <EOL> """<STR_LIT>""" <EOL> return value . ToDict ( ) <EOL> def _ObjectListToDict ( node , value ) : <EOL> """<STR_LIT>""" <EOL> return map ( compat . partial ( _ObjectToDict , node ) , value ) <EOL> def _PrepareFileUpload ( getents_fn , node , filename ) : <EOL> """<STR_LIT>""" <EOL> statcb = utils . FileStatHelper ( ) <EOL> data = _Compress ( node , utils . ReadFile ( filename , preread = statcb ) ) <EOL> st = statcb . st <EOL> if getents_fn is None : <EOL> getents_fn = runtime . GetEnts <EOL> getents = getents_fn ( ) <EOL> virt_filename = vcluster . MakeVirtualPath ( filename ) <EOL> return [ virt_filename , data , st . st_mode , getents . LookupUid ( st . st_uid ) , <EOL> getents . LookupGid ( st . st_gid ) , st . st_atime , st . st_mtime ] <EOL> def _PrepareFinalizeExportDisks ( _ , snap_disks ) : <EOL> """<STR_LIT>""" <EOL> flat_disks = [ ] <EOL> for disk in snap_disks : <EOL> if isinstance ( disk , bool ) : <EOL> flat_disks . append ( disk ) <EOL> else : <EOL> flat_disks . append ( disk . ToDict ( ) ) <EOL> return flat_disks <EOL> def _EncodeBlockdevRename ( _ , value ) : <EOL> """<STR_LIT>""" <EOL> return [ ( d . ToDict ( ) , uid ) for d , uid in value ] <EOL> def _AddSpindlesToLegacyNodeInfo ( result , space_info ) : <EOL> """<STR_LIT>""" <EOL> lvm_pv_info = utils . storage . LookupSpaceInfoByStorageType ( <EOL> space_info , constants . ST_LVM_PV ) <EOL> if lvm_pv_info : <EOL> result [ "<STR_LIT>" ] = lvm_pv_info [ "<STR_LIT>" ] <EOL> result [ "<STR_LIT>" ] = lvm_pv_info [ "<STR_LIT>" ] <EOL> else : <EOL> result [ "<STR_LIT>" ] = <NUM_LIT:0> <EOL> result [ "<STR_LIT>" ] = <NUM_LIT:0> <EOL> def _AddStorageInfoToLegacyNodeInfoByTemplate ( <EOL> result , space_info , disk_template ) : <EOL> """<STR_LIT>""" <EOL> if utils . storage . DiskTemplateSupportsSpaceReporting ( disk_template ) : <EOL> disk_info = utils . storage . LookupSpaceInfoByDiskTemplate ( <EOL> space_info , disk_template ) <EOL> result [ "<STR_LIT:name>" ] = disk_info [ "<STR_LIT:name>" ] <EOL> result [ "<STR_LIT>" ] = disk_info [ "<STR_LIT>" ] <EOL> result [ "<STR_LIT>" ] = disk_info [ "<STR_LIT>" ] <EOL> else : <EOL> result [ "<STR_LIT>" ] = <NUM_LIT:0> <EOL> result [ "<STR_LIT>" ] = <NUM_LIT:0> <EOL> def MakeLegacyNodeInfo ( data , disk_template ) : <EOL> """<STR_LIT>""" <EOL> ( bootid , space_info , ( hv_info , ) ) = data <EOL> ret = utils . JoinDisjointDicts ( hv_info , { "<STR_LIT>" : bootid } ) <EOL> _AddSpindlesToLegacyNodeInfo ( ret , space_info ) <EOL> _AddStorageInfoToLegacyNodeInfoByTemplate ( ret , space_info , disk_template ) <EOL> return ret <EOL> def _AnnotateDParamsDRBD ( disk , ( drbd_params , data_params , meta_params ) ) : <EOL> """<STR_LIT>""" <EOL> assert disk . dev_type == constants . DT_DRBD8 <EOL> disk . params = objects . FillDict ( drbd_params , disk . params ) <EOL> ( dev_data , dev_meta ) = disk . children <EOL> dev_data . params = objects . FillDict ( data_params , dev_data . params ) <EOL> dev_meta . params = objects . FillDict ( meta_params , dev_meta . params ) <EOL> return disk <EOL> def _AnnotateDParamsGeneric ( disk , ( params , ) ) : <EOL> """<STR_LIT>""" <EOL> assert disk . dev_type != constants . DT_DRBD8 <EOL> disk . params = objects . FillDict ( params , disk . params ) <EOL> return disk <EOL> def AnnotateDiskParams ( disks , disk_params ) : <EOL> """<STR_LIT>""" <EOL> def AnnotateDisk ( disk ) : <EOL> if disk . dev_type == constants . DT_DISKLESS : <EOL> return disk <EOL> ld_params = objects . Disk . ComputeLDParams ( disk . dev_type , disk_params ) <EOL> if disk . dev_type == constants . DT_DRBD8 : <EOL> return _AnnotateDParamsDRBD ( disk , ld_params ) <EOL> else : <EOL> return _AnnotateDParamsGeneric ( disk , ld_params ) <EOL> return [ AnnotateDisk ( disk . Copy ( ) ) for disk in disks ] <EOL> def _GetExclusiveStorageFlag ( cfg , node_uuid ) : <EOL> ni = cfg . GetNodeInfo ( node_uuid ) <EOL> if ni is None : <EOL> raise errors . OpPrereqError ( "<STR_LIT>" % node_uuid , <EOL> errors . ECODE_NOENT ) <EOL> return cfg . GetNdParams ( ni ) [ constants . ND_EXCLUSIVE_STORAGE ] <EOL> def _AddExclusiveStorageFlagToLvmStorageUnits ( storage_units , es_flag ) : <EOL> """<STR_LIT>""" <EOL> result = [ ] <EOL> for ( storage_type , storage_key ) in storage_units : <EOL> if storage_type in [ constants . ST_LVM_VG ] : <EOL> result . append ( ( storage_type , storage_key , [ es_flag ] ) ) <EOL> if es_flag : <EOL> result . append ( ( constants . ST_LVM_PV , storage_key , [ es_flag ] ) ) <EOL> else : <EOL> result . append ( ( storage_type , storage_key , [ ] ) ) <EOL> return result <EOL> def GetExclusiveStorageForNodes ( cfg , node_uuids ) : <EOL> """<STR_LIT>""" <EOL> getflag = lambda n : _GetExclusiveStorageFlag ( cfg , n ) <EOL> flags = map ( getflag , node_uuids ) <EOL> return dict ( zip ( node_uuids , flags ) ) <EOL> def PrepareStorageUnitsForNodes ( cfg , storage_units , node_uuids ) : <EOL> """<STR_LIT>""" <EOL> getunit = lambda n : _AddExclusiveStorageFlagToLvmStorageUnits ( <EOL> storage_units , _GetExclusiveStorageFlag ( cfg , n ) ) <EOL> flags = map ( getunit , node_uuids ) <EOL> return dict ( zip ( node_uuids , flags ) ) <EOL> _ENCODERS = { <EOL> rpc_defs . ED_OBJECT_DICT : _ObjectToDict , <EOL> rpc_defs . ED_OBJECT_DICT_LIST : _ObjectListToDict , <EOL> rpc_defs . ED_COMPRESS : _Compress , <EOL> rpc_defs . ED_FINALIZE_EXPORT_DISKS : _PrepareFinalizeExportDisks , <EOL> rpc_defs . ED_BLOCKDEV_RENAME : _EncodeBlockdevRename , <EOL> } <EOL> class RpcRunner ( _RpcClientBase , <EOL> _generated_rpc . RpcClientDefault , <EOL> _generated_rpc . RpcClientBootstrap , <EOL> _generated_rpc . RpcClientDnsOnly , <EOL> _generated_rpc . RpcClientConfig ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , cfg , lock_monitor_cb , _req_process_fn = None , _getents = None ) : <EOL> """<STR_LIT>""" <EOL> self . _cfg = cfg <EOL> encoders = _ENCODERS . copy ( ) <EOL> encoders . update ( { <EOL> rpc_defs . ED_INST_DICT : self . _InstDict , <EOL> rpc_defs . ED_INST_DICT_HVP_BEP_DP : self . _InstDictHvpBepDp , <EOL> rpc_defs . ED_INST_DICT_OSP_DP : self . _InstDictOspDp , <EOL> rpc_defs . ED_NIC_DICT : self . _NicDict , <EOL> rpc_defs . ED_DEVICE_DICT : self . _DeviceDict , <EOL> rpc_defs . ED_DISKS_DICT_DP : self . _DisksDictDP , <EOL> rpc_defs . ED_MULTI_DISKS_DICT_DP : self . _MultiDiskDictDP , <EOL> rpc_defs . ED_SINGLE_DISK_DICT_DP : self . _SingleDiskDictDP , <EOL> rpc_defs . ED_NODE_TO_DISK_DICT_DP : self . _EncodeNodeToDiskDictDP , <EOL> rpc_defs . ED_FILE_DETAILS : compat . partial ( _PrepareFileUpload , _getents ) , <EOL> rpc_defs . ED_IMPEXP_IO : self . _EncodeImportExportIO , <EOL> } ) <EOL> resolver = compat . partial ( _NodeConfigResolver , cfg . GetNodeInfo , <EOL> cfg . GetAllNodesInfo ) <EOL> _RpcClientBase . __init__ ( self , resolver , encoders . get , <EOL> lock_monitor_cb = lock_monitor_cb , <EOL> _req_process_fn = _req_process_fn ) <EOL> _generated_rpc . RpcClientConfig . __init__ ( self ) <EOL> _generated_rpc . RpcClientBootstrap . __init__ ( self ) <EOL> _generated_rpc . RpcClientDnsOnly . __init__ ( self ) <EOL> _generated_rpc . RpcClientDefault . __init__ ( self ) <EOL> def _NicDict ( self , _ , nic ) : <EOL> """<STR_LIT>""" <EOL> n = copy . deepcopy ( nic ) <EOL> if n . network : <EOL> net_uuid = self . _cfg . LookupNetwork ( n . network ) <EOL> if net_uuid : <EOL> nobj = self . _cfg . GetNetwork ( net_uuid ) <EOL> n . netinfo = objects . Network . ToDict ( nobj ) <EOL> return n . ToDict ( ) <EOL> def _DeviceDict ( self , _ , ( device , instance ) ) : <EOL> if isinstance ( device , objects . NIC ) : <EOL> return self . _NicDict ( None , device ) <EOL> elif isinstance ( device , objects . Disk ) : <EOL> return self . _SingleDiskDictDP ( None , ( device , instance ) ) <EOL> def _InstDict ( self , node , instance , hvp = None , bep = None , osp = None ) : <EOL> """<STR_LIT>""" <EOL> idict = instance . ToDict ( ) <EOL> cluster = self . _cfg . GetClusterInfo ( ) <EOL> idict [ "<STR_LIT>" ] = cluster . FillHV ( instance ) <EOL> idict [ "<STR_LIT>" ] = self . _cfg . GetInstanceSecondaryNodes ( instance . uuid ) <EOL> if hvp is not None : <EOL> idict [ "<STR_LIT>" ] . update ( hvp ) <EOL> idict [ "<STR_LIT>" ] = cluster . FillBE ( instance ) <EOL> if bep is not None : <EOL> idict [ "<STR_LIT>" ] . update ( bep ) <EOL> idict [ "<STR_LIT>" ] = cluster . SimpleFillOS ( instance . os , instance . osparams ) <EOL> if osp is not None : <EOL> idict [ "<STR_LIT>" ] . update ( osp ) <EOL> disks = self . _cfg . GetInstanceDisks ( instance . uuid ) <EOL> idict [ "<STR_LIT>" ] = self . _DisksDictDP ( node , ( disks , instance ) ) <EOL> for nic in idict [ "<STR_LIT>" ] : <EOL> nic [ "<STR_LIT>" ] = objects . FillDict ( <EOL> cluster . nicparams [ constants . PP_DEFAULT ] , <EOL> nic [ "<STR_LIT>" ] ) <EOL> network = nic . get ( "<STR_LIT>" , None ) <EOL> if network : <EOL> net_uuid = self . _cfg . LookupNetwork ( network ) <EOL> if net_uuid : <EOL> nobj = self . _cfg . GetNetwork ( net_uuid ) <EOL> nic [ "<STR_LIT>" ] = objects . Network . ToDict ( nobj ) <EOL> return idict <EOL> def _InstDictHvpBepDp ( self , node , ( instance , hvp , bep ) ) : <EOL> """<STR_LIT>""" <EOL> return self . _InstDict ( node , instance , hvp = hvp , bep = bep ) <EOL> def _InstDictOspDp ( self , node , ( instance , osparams ) ) : <EOL> """<STR_LIT>""" <EOL> return self . _InstDict ( node , instance , osp = osparams ) <EOL> def _DisksDictDP ( self , node , ( disks , instance ) ) : <EOL> """<STR_LIT>""" <EOL> diskparams = self . _cfg . GetInstanceDiskParams ( instance ) <EOL> ret = [ ] <EOL> for disk in AnnotateDiskParams ( disks , diskparams ) : <EOL> disk_node_uuids = disk . GetNodes ( instance . primary_node ) <EOL> node_ips = dict ( ( uuid , node . secondary_ip ) for ( uuid , node ) <EOL> in self . _cfg . GetMultiNodeInfo ( disk_node_uuids ) ) <EOL> disk . UpdateDynamicDiskParams ( node , node_ips ) <EOL> ret . append ( disk . ToDict ( include_dynamic_params = True ) ) <EOL> return ret <EOL> def _MultiDiskDictDP ( self , node , disks_insts ) : <EOL> """<STR_LIT>""" <EOL> return [ disk for disk_inst in disks_insts <EOL> for disk in self . _DisksDictDP ( node , disk_inst ) ] <EOL> def _SingleDiskDictDP ( self , node , ( disk , instance ) ) : <EOL> """<STR_LIT>""" <EOL> ( anno_disk , ) = self . _DisksDictDP ( node , ( [ disk ] , instance ) ) <EOL> return anno_disk <EOL> def _EncodeNodeToDiskDictDP ( self , node , value ) : <EOL> """<STR_LIT>""" <EOL> return dict ( ( name , [ self . _SingleDiskDictDP ( node , disk ) for disk in disks ] ) <EOL> for name , disks in value . items ( ) ) <EOL> def _EncodeImportExportIO ( self , node , ( ieio , ieioargs ) ) : <EOL> """<STR_LIT>""" <EOL> if ieio == constants . IEIO_RAW_DISK : <EOL> assert len ( ieioargs ) == <NUM_LIT:2> <EOL> return ( ieio , ( self . _SingleDiskDictDP ( node , ieioargs ) , ) ) <EOL> if ieio == constants . IEIO_SCRIPT : <EOL> assert len ( ieioargs ) == <NUM_LIT:2> <EOL> return ( ieio , ( self . _SingleDiskDictDP ( node , ieioargs [ <NUM_LIT:0> ] ) , ieioargs [ <NUM_LIT:1> ] ) ) <EOL> return ( ieio , ieioargs ) <EOL> class JobQueueRunner ( _RpcClientBase , _generated_rpc . RpcClientJobQueue ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , _context , address_list ) : <EOL> """<STR_LIT>""" <EOL> if address_list is None : <EOL> resolver = compat . partial ( _SsconfResolver , True ) <EOL> else : <EOL> resolver = _StaticResolver ( address_list ) <EOL> _RpcClientBase . __init__ ( self , resolver , _ENCODERS . get , <EOL> lock_monitor_cb = lambda _ : None ) <EOL> _generated_rpc . RpcClientJobQueue . __init__ ( self ) <EOL> class BootstrapRunner ( _RpcClientBase , <EOL> _generated_rpc . RpcClientBootstrap , <EOL> _generated_rpc . RpcClientDnsOnly ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> """<STR_LIT>""" <EOL> _RpcClientBase . __init__ ( self , compat . partial ( _SsconfResolver , True ) , <EOL> _ENCODERS . get ) <EOL> _generated_rpc . RpcClientBootstrap . __init__ ( self ) <EOL> _generated_rpc . RpcClientDnsOnly . __init__ ( self ) <EOL> class DnsOnlyRunner ( _RpcClientBase , _generated_rpc . RpcClientDnsOnly ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> """<STR_LIT>""" <EOL> _RpcClientBase . __init__ ( self , compat . partial ( _SsconfResolver , False ) , <EOL> _ENCODERS . get ) <EOL> _generated_rpc . RpcClientDnsOnly . __init__ ( self ) <EOL> class ConfigRunner ( _RpcClientBase , _generated_rpc . RpcClientConfig ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , _context , address_list , _req_process_fn = None , <EOL> _getents = None ) : <EOL> """<STR_LIT>""" <EOL> lock_monitor_cb = None <EOL> if address_list is None : <EOL> resolver = compat . partial ( _SsconfResolver , True ) <EOL> else : <EOL> resolver = _StaticResolver ( address_list ) <EOL> encoders = _ENCODERS . copy ( ) <EOL> encoders . update ( { <EOL> rpc_defs . ED_FILE_DETAILS : compat . partial ( _PrepareFileUpload , _getents ) , <EOL> } ) <EOL> _RpcClientBase . __init__ ( self , resolver , encoders . get , <EOL> lock_monitor_cb = lock_monitor_cb , <EOL> _req_process_fn = _req_process_fn ) <EOL> _generated_rpc . RpcClientConfig . __init__ ( self ) </s>
