<s> """<STR_LIT>""" <EOL> import json <EOL> import copy <EOL> from ovs . extensions . db . etcd . configuration import EtcdConfiguration <EOL> from ovs . extensions . generic . remote import Remote <EOL> from ovs . log . logHandler import LogHandler <EOL> from volumedriver . storagerouter import storagerouterclient <EOL> from volumedriver . storagerouter . storagerouterclient import ClusterContact <EOL> from volumedriver . storagerouter . storagerouterclient import DTLMode <EOL> from volumedriver . storagerouter . storagerouterclient import LocalStorageRouterClient as LSRClient <EOL> from volumedriver . storagerouter . storagerouterclient import MDSClient <EOL> from volumedriver . storagerouter . storagerouterclient import MDSNodeConfig <EOL> from volumedriver . storagerouter . storagerouterclient import ReadCacheBehaviour <EOL> from volumedriver . storagerouter . storagerouterclient import ReadCacheMode <EOL> from volumedriver . storagerouter . storagerouterclient import Statistics <EOL> from volumedriver . storagerouter . storagerouterclient import StorageRouterClient as SRClient <EOL> from volumedriver . storagerouter . storagerouterclient import VolumeInfo <EOL> logger = LogHandler . get ( '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> storagerouterclient . Logger . setupLogging ( LogHandler . load_path ( '<STR_LIT>' ) ) <EOL> storagerouterclient . Logger . enableLogging ( ) <EOL> client_vpool_cache = { } <EOL> client_storagedriver_cache = { } <EOL> mdsclient_service_cache = { } <EOL> class StorageDriverClient ( object ) : <EOL> """<STR_LIT>""" <EOL> VOLDRV_DTL_SYNC = '<STR_LIT>' <EOL> VOLDRV_DTL_ASYNC = '<STR_LIT>' <EOL> VOLDRV_NO_CACHE = '<STR_LIT>' <EOL> VOLDRV_CACHE_ON_READ = '<STR_LIT>' <EOL> VOLDRV_CONTENT_BASED = '<STR_LIT>' <EOL> VOLDRV_CACHE_ON_WRITE = '<STR_LIT>' <EOL> VOLDRV_LOCATION_BASED = '<STR_LIT>' <EOL> VOLDRV_DTL_MANUAL_MODE = '<STR_LIT>' <EOL> VOLDRV_DTL_AUTOMATIC_MODE = '<STR_LIT>' <EOL> VOLDRV_DTL_TRANSPORT_TCP = '<STR_LIT>' <EOL> VOLDRV_DTL_TRANSPORT_RSOCKET = '<STR_LIT>' <EOL> FRAMEWORK_DTL_SYNC = '<STR_LIT>' <EOL> FRAMEWORK_DTL_ASYNC = '<STR_LIT>' <EOL> FRAMEWORK_DTL_NO_SYNC = '<STR_LIT>' <EOL> FRAMEWORK_NO_CACHE = '<STR_LIT:none>' <EOL> FRAMEWORK_CACHE_ON_READ = '<STR_LIT>' <EOL> FRAMEWORK_CONTENT_BASED = '<STR_LIT>' <EOL> FRAMEWORK_CACHE_ON_WRITE = '<STR_LIT>' <EOL> FRAMEWORK_LOCATION_BASED = '<STR_LIT>' <EOL> FRAMEWORK_DTL_TRANSPORT_TCP = '<STR_LIT>' <EOL> FRAMEWORK_DTL_TRANSPORT_RSOCKET = '<STR_LIT>' <EOL> METADATA_CACHE_PAGE_SIZE = <NUM_LIT> * <NUM_LIT> <EOL> DEFAULT_METADATA_CACHE_SIZE = <NUM_LIT> * METADATA_CACHE_PAGE_SIZE <EOL> VDISK_CACHE_MAP = { FRAMEWORK_NO_CACHE : ReadCacheBehaviour . NO_CACHE , <EOL> FRAMEWORK_CACHE_ON_READ : ReadCacheBehaviour . CACHE_ON_READ , <EOL> FRAMEWORK_CACHE_ON_WRITE : ReadCacheBehaviour . CACHE_ON_WRITE } <EOL> VPOOL_CACHE_MAP = { FRAMEWORK_NO_CACHE : VOLDRV_NO_CACHE , <EOL> FRAMEWORK_CACHE_ON_READ : VOLDRV_CACHE_ON_READ , <EOL> FRAMEWORK_CACHE_ON_WRITE : VOLDRV_CACHE_ON_WRITE } <EOL> VDISK_DEDUPE_MAP = { FRAMEWORK_CONTENT_BASED : ReadCacheMode . CONTENT_BASED , <EOL> FRAMEWORK_LOCATION_BASED : ReadCacheMode . LOCATION_BASED } <EOL> VPOOL_DEDUPE_MAP = { FRAMEWORK_CONTENT_BASED : VOLDRV_CONTENT_BASED , <EOL> FRAMEWORK_LOCATION_BASED : VOLDRV_LOCATION_BASED } <EOL> VDISK_DTL_MODE_MAP = { FRAMEWORK_DTL_SYNC : DTLMode . SYNCHRONOUS , <EOL> FRAMEWORK_DTL_ASYNC : DTLMode . ASYNCHRONOUS , <EOL> FRAMEWORK_DTL_NO_SYNC : None } <EOL> VPOOL_DTL_MODE_MAP = { FRAMEWORK_DTL_SYNC : VOLDRV_DTL_SYNC , <EOL> FRAMEWORK_DTL_ASYNC : VOLDRV_DTL_ASYNC , <EOL> FRAMEWORK_DTL_NO_SYNC : None } <EOL> VPOOL_DTL_TRANSPORT_MAP = { FRAMEWORK_DTL_TRANSPORT_TCP : VOLDRV_DTL_TRANSPORT_TCP , <EOL> FRAMEWORK_DTL_TRANSPORT_RSOCKET : VOLDRV_DTL_TRANSPORT_RSOCKET } <EOL> REVERSE_CACHE_MAP = { VOLDRV_NO_CACHE : FRAMEWORK_NO_CACHE , <EOL> VOLDRV_CACHE_ON_READ : FRAMEWORK_CACHE_ON_READ , <EOL> VOLDRV_CACHE_ON_WRITE : FRAMEWORK_CACHE_ON_WRITE , <EOL> ReadCacheBehaviour . NO_CACHE : FRAMEWORK_NO_CACHE , <EOL> ReadCacheBehaviour . CACHE_ON_READ : FRAMEWORK_CACHE_ON_READ , <EOL> ReadCacheBehaviour . CACHE_ON_WRITE : FRAMEWORK_CACHE_ON_WRITE } <EOL> REVERSE_DEDUPE_MAP = { VOLDRV_CONTENT_BASED : FRAMEWORK_CONTENT_BASED , <EOL> VOLDRV_LOCATION_BASED : FRAMEWORK_LOCATION_BASED , <EOL> ReadCacheMode . CONTENT_BASED : FRAMEWORK_CONTENT_BASED , <EOL> ReadCacheMode . LOCATION_BASED : FRAMEWORK_LOCATION_BASED } <EOL> REVERSE_DTL_MODE_MAP = { VOLDRV_DTL_SYNC : FRAMEWORK_DTL_SYNC , <EOL> VOLDRV_DTL_ASYNC : FRAMEWORK_DTL_ASYNC , <EOL> DTLMode . SYNCHRONOUS : FRAMEWORK_DTL_SYNC , <EOL> DTLMode . ASYNCHRONOUS : FRAMEWORK_DTL_ASYNC } <EOL> REVERSE_DTL_TRANSPORT_MAP = { VOLDRV_DTL_TRANSPORT_TCP : FRAMEWORK_DTL_TRANSPORT_TCP , <EOL> VOLDRV_DTL_TRANSPORT_RSOCKET : FRAMEWORK_DTL_TRANSPORT_RSOCKET } <EOL> CLUSTER_SIZES = [ <NUM_LIT:4> , <NUM_LIT:8> , <NUM_LIT:16> , <NUM_LIT:32> , <NUM_LIT:64> ] <EOL> TLOG_MULTIPLIER_MAP = { <NUM_LIT:4> : <NUM_LIT:16> , <EOL> <NUM_LIT:8> : <NUM_LIT:8> , <EOL> <NUM_LIT:16> : <NUM_LIT:4> , <EOL> <NUM_LIT:32> : <NUM_LIT:2> , <EOL> <NUM_LIT:64> : <NUM_LIT:1> , <EOL> <NUM_LIT> : <NUM_LIT:1> } <EOL> DTL_STATUS = { '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:10> , <EOL> '<STR_LIT>' : <NUM_LIT:10> , <EOL> '<STR_LIT>' : <NUM_LIT:20> , <EOL> '<STR_LIT>' : <NUM_LIT:30> } <EOL> EMPTY_STATISTICS = staticmethod ( lambda : Statistics ( ) ) <EOL> EMPTY_INFO = staticmethod ( lambda : VolumeInfo ( ) ) <EOL> STAT_SUMS = { '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] } <EOL> STAT_KEYS = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> STAT_KEYS . extend ( STAT_SUMS . keys ( ) ) <EOL> def __init__ ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> @ staticmethod <EOL> def load ( vpool ) : <EOL> """<STR_LIT>""" <EOL> key = vpool . identifier <EOL> if key not in client_vpool_cache : <EOL> cluster_contacts = [ ] <EOL> for storagedriver in vpool . storagedrivers [ : <NUM_LIT:3> ] : <EOL> cluster_contacts . append ( ClusterContact ( str ( storagedriver . cluster_ip ) , storagedriver . ports [ <NUM_LIT:1> ] ) ) <EOL> client = SRClient ( str ( vpool . guid ) , cluster_contacts ) <EOL> client_vpool_cache [ key ] = client <EOL> return client_vpool_cache [ key ] <EOL> class MetadataServerClient ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> @ staticmethod <EOL> def load ( service ) : <EOL> """<STR_LIT>""" <EOL> if service . storagerouter is None : <EOL> raise ValueError ( '<STR_LIT>' . format ( service . name ) ) <EOL> key = service . guid <EOL> if key not in mdsclient_service_cache : <EOL> try : <EOL> client = MDSClient ( MDSNodeConfig ( address = str ( service . storagerouter . ip ) , port = service . ports [ <NUM_LIT:0> ] ) ) <EOL> mdsclient_service_cache [ key ] = client <EOL> except RuntimeError as ex : <EOL> logger . error ( '<STR_LIT>' . format ( service . storagerouter . ip , ex ) ) <EOL> return None <EOL> return mdsclient_service_cache [ key ] <EOL> class StorageDriverConfiguration ( object ) : <EOL> """<STR_LIT>""" <EOL> parameters = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , ] <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , ] , <EOL> '<STR_LIT>' : [ ] <EOL> } , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , ] <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , ] , <EOL> '<STR_LIT>' : [ ] <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , ] <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , ] , <EOL> '<STR_LIT>' : [ ] <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , ] , <EOL> '<STR_LIT>' : [ ] <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , ] <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , ] <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , ] <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , ] , <EOL> '<STR_LIT>' : [ ] <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , ] <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , ] , <EOL> '<STR_LIT>' : [ ] <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , ] , <EOL> '<STR_LIT>' : [ ] <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , ] , <EOL> '<STR_LIT>' : [ ] <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , ] <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , ] <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , ] <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , ] <EOL> } , <EOL> } , <EOL> } <EOL> def __init__ ( self , config_type , vpool_guid , storagedriver_id ) : <EOL> """<STR_LIT>""" <EOL> def make_configure ( sct ) : <EOL> """<STR_LIT>""" <EOL> return lambda ** kwargs : self . _add ( sct , ** kwargs ) <EOL> if config_type != '<STR_LIT>' : <EOL> raise RuntimeError ( '<STR_LIT>' ) <EOL> self . config_type = config_type <EOL> self . configuration = { } <EOL> self . path = '<STR_LIT>' . format ( vpool_guid , storagedriver_id ) <EOL> self . remote_path = '<STR_LIT>' . format ( self . path . format ( '<STR_LIT>' ) ) . strip ( '<STR_LIT:/>' ) <EOL> self . is_new = True <EOL> self . dirty_entries = [ ] <EOL> self . params = copy . deepcopy ( StorageDriverConfiguration . parameters ) <EOL> backend_connection_manager = '<STR_LIT>' <EOL> self . params [ self . config_type ] [ backend_connection_manager ] [ '<STR_LIT>' ] . append ( '<STR_LIT>' ) <EOL> for section in self . params [ self . config_type ] : <EOL> setattr ( self , '<STR_LIT>' . format ( section ) , make_configure ( section ) ) <EOL> def load ( self ) : <EOL> """<STR_LIT>""" <EOL> self . configuration = { } <EOL> if EtcdConfiguration . dir_exists ( self . path . format ( '<STR_LIT>' ) ) : <EOL> self . is_new = False <EOL> for key in self . params [ self . config_type ] : <EOL> if EtcdConfiguration . exists ( self . path . format ( key ) ) : <EOL> self . configuration [ key ] = json . loads ( EtcdConfiguration . get ( self . path . format ( key ) , raw = True ) ) <EOL> else : <EOL> logger . debug ( '<STR_LIT>' . format ( self . path . format ( '<STR_LIT>' ) ) ) <EOL> self . dirty_entries = [ ] <EOL> def save ( self , client = None , reload_config = True ) : <EOL> """<STR_LIT>""" <EOL> self . _validate ( ) <EOL> for key in self . configuration : <EOL> contents = json . dumps ( self . configuration [ key ] , indent = <NUM_LIT:4> ) <EOL> EtcdConfiguration . set ( self . path . format ( key ) , contents , raw = True ) <EOL> if self . config_type == '<STR_LIT>' and reload_config is True : <EOL> if len ( self . dirty_entries ) > <NUM_LIT:0> : <EOL> if client is None : <EOL> logger . info ( '<STR_LIT>' ) <EOL> changes = LSRClient ( self . remote_path ) . update_configuration ( self . remote_path ) <EOL> else : <EOL> logger . info ( '<STR_LIT>' . format ( client . ip ) ) <EOL> with Remote ( client . ip , [ LSRClient ] ) as remote : <EOL> changes = copy . deepcopy ( remote . LocalStorageRouterClient ( self . remote_path ) . update_configuration ( self . remote_path ) ) <EOL> for change in changes : <EOL> if change [ '<STR_LIT>' ] not in self . dirty_entries : <EOL> raise RuntimeError ( '<STR_LIT>' . format ( change [ '<STR_LIT>' ] ) ) <EOL> logger . info ( '<STR_LIT>' . format ( change [ '<STR_LIT>' ] , change [ '<STR_LIT>' ] , change [ '<STR_LIT>' ] ) ) <EOL> self . dirty_entries . remove ( change [ '<STR_LIT>' ] ) <EOL> logger . info ( '<STR_LIT>' ) <EOL> if len ( self . dirty_entries ) > <NUM_LIT:0> : <EOL> logger . warning ( '<STR_LIT>' . format ( '<STR_LIT:U+002CU+0020>' . join ( self . dirty_entries ) ) ) <EOL> else : <EOL> logger . debug ( '<STR_LIT>' ) <EOL> self . is_new = False <EOL> self . dirty_entries = [ ] <EOL> def clean ( self ) : <EOL> """<STR_LIT>""" <EOL> for section , entries in self . params [ self . config_type ] . iteritems ( ) : <EOL> if section in self . configuration : <EOL> section_configuration = copy . deepcopy ( self . configuration [ section ] ) <EOL> for param in section_configuration : <EOL> if param not in entries [ '<STR_LIT>' ] and param not in entries [ '<STR_LIT>' ] : <EOL> del self . configuration [ section ] [ param ] <EOL> @ staticmethod <EOL> def build_filesystem_by_hypervisor ( hypervisor_type ) : <EOL> """<STR_LIT>""" <EOL> if hypervisor_type == '<STR_LIT>' : <EOL> return { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ { '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' } , <EOL> { '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' } ] } <EOL> if hypervisor_type == '<STR_LIT>' : <EOL> return { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ { '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' } ] } <EOL> return { } <EOL> def _validate ( self ) : <EOL> """<STR_LIT>""" <EOL> backend_connection_manager = '<STR_LIT>' <EOL> backend_type = '<STR_LIT>' <EOL> if self . configuration . get ( backend_connection_manager , { } ) . get ( backend_type , '<STR_LIT>' ) != '<STR_LIT>' : <EOL> if '<STR_LIT>' in self . params [ self . config_type ] [ backend_connection_manager ] [ '<STR_LIT>' ] : <EOL> self . params [ self . config_type ] [ backend_connection_manager ] [ '<STR_LIT>' ] . remove ( '<STR_LIT>' ) <EOL> self . params [ self . config_type ] [ backend_connection_manager ] [ '<STR_LIT>' ] . append ( '<STR_LIT>' ) <EOL> errors = [ ] <EOL> for section , entries in self . params [ self . config_type ] . iteritems ( ) : <EOL> if section not in self . configuration : <EOL> if len ( entries [ '<STR_LIT>' ] ) > <NUM_LIT:0> : <EOL> errors . append ( '<STR_LIT>' . format ( section ) ) <EOL> else : <EOL> for param in entries [ '<STR_LIT>' ] : <EOL> if param not in self . configuration [ section ] : <EOL> errors . append ( '<STR_LIT>' . format ( section , param ) ) <EOL> for param in self . configuration [ section ] : <EOL> if param not in entries [ '<STR_LIT>' ] and param not in entries [ '<STR_LIT>' ] : <EOL> errors . append ( '<STR_LIT>' . format ( section , param ) ) <EOL> if errors : <EOL> raise RuntimeError ( '<STR_LIT>' . format ( '<STR_LIT>' . join ( errors ) ) ) <EOL> def _add ( self , section , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> sparams = self . params [ self . config_type ] [ section ] <EOL> errors = [ ] <EOL> for item in kwargs : <EOL> if item not in sparams [ '<STR_LIT>' ] and item not in sparams [ '<STR_LIT>' ] : <EOL> errors . append ( item ) <EOL> if errors : <EOL> raise RuntimeError ( '<STR_LIT>' . format ( '<STR_LIT>' . join ( errors ) ) ) <EOL> for item , value in kwargs . iteritems ( ) : <EOL> if section not in self . configuration : <EOL> self . configuration [ section ] = { } <EOL> if item not in self . configuration [ section ] or self . configuration [ section ] [ item ] != value : <EOL> self . dirty_entries . append ( item ) <EOL> self . configuration [ section ] [ item ] = value <EOL> class GaneshaConfiguration ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> config_dir = EtcdConfiguration . get ( '<STR_LIT>' ) <EOL> self . _config_corefile = '<STR_LIT:/>' . join ( [ config_dir , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . _config_exportfile = '<STR_LIT:/>' . join ( [ config_dir , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def generate_config ( self , target_file , params ) : <EOL> """<STR_LIT>""" <EOL> with open ( self . _config_corefile , '<STR_LIT:r>' ) as core_config_file : <EOL> config = core_config_file . read ( ) <EOL> with open ( self . _config_exportfile , '<STR_LIT:r>' ) as export_section_file : <EOL> config += export_section_file . read ( ) <EOL> for key , value in params . iteritems ( ) : <EOL> print '<STR_LIT>' . format ( key , value ) <EOL> config = config . replace ( key , value ) <EOL> with open ( target_file , '<STR_LIT:wb>' ) as config_out : <EOL> config_out . write ( config ) </s>
