<s> """<STR_LIT>""" <EOL> import os <EOL> import sys <EOL> import copy <EOL> import threading <EOL> import lxml . etree <EOL> import Bcfg2 . Server <EOL> import Bcfg2 . Options <EOL> from Bcfg2 . Compat import Queue , Empty , Full , cPickle <EOL> from Bcfg2 . Server . Plugin . base import Plugin <EOL> from Bcfg2 . Server . Plugin . exceptions import PluginInitError , MetadataRuntimeError , MetadataConsistencyError <EOL> class Generator ( object ) : <EOL> """<STR_LIT>""" <EOL> def HandlesEntry ( self , entry , metadata ) : <EOL> """<STR_LIT>""" <EOL> return False <EOL> def HandleEntry ( self , entry , metadata ) : <EOL> """<STR_LIT>""" <EOL> return entry <EOL> class Structure ( object ) : <EOL> """<STR_LIT>""" <EOL> def BuildStructures ( self , metadata ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> class Metadata ( object ) : <EOL> """<STR_LIT>""" <EOL> def viz ( self , hosts , bundles , key , only_client , colors ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def set_version ( self , client , version ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def set_profile ( self , client , profile , address ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def resolve_client ( self , address , cleanup_cache = False ) : <EOL> """<STR_LIT>""" <EOL> return address [ <NUM_LIT:1> ] <EOL> def AuthenticateConnection ( self , cert , user , password , address ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def get_initial_metadata ( self , client_name ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def merge_additional_data ( self , imd , source , data ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def merge_additional_groups ( self , imd , groups ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def update_client_list ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> class Connector ( object ) : <EOL> """<STR_LIT>""" <EOL> def get_additional_groups ( self , metadata ) : <EOL> """<STR_LIT>""" <EOL> return list ( ) <EOL> def get_additional_data ( self , metadata ) : <EOL> """<STR_LIT>""" <EOL> return dict ( ) <EOL> class Probing ( object ) : <EOL> """<STR_LIT>""" <EOL> def GetProbes ( self , metadata ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def ReceiveData ( self , metadata , datalist ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> class Statistics ( Plugin ) : <EOL> """<STR_LIT>""" <EOL> create = False <EOL> def process_statistics ( self , client , xdata ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> class Threaded ( object ) : <EOL> """<STR_LIT>""" <EOL> def start_threads ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> class ThreadedStatistics ( Statistics , Threaded , threading . Thread ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , core ) : <EOL> Statistics . __init__ ( self , core ) <EOL> Threaded . __init__ ( self ) <EOL> threading . Thread . __init__ ( self ) <EOL> self . terminate = core . terminate <EOL> self . work_queue = Queue ( <NUM_LIT> ) <EOL> self . pending_file = os . path . join ( Bcfg2 . Options . setup . repository , "<STR_LIT>" , <EOL> "<STR_LIT>" % self . name ) <EOL> self . daemon = False <EOL> def start_threads ( self ) : <EOL> self . start ( ) <EOL> def _save ( self ) : <EOL> """<STR_LIT>""" <EOL> pending_data = [ ] <EOL> try : <EOL> while not self . work_queue . empty ( ) : <EOL> ( metadata , xdata ) = self . work_queue . get_nowait ( ) <EOL> data = lxml . etree . tostring ( xdata , <EOL> xml_declaration = False ) . decode ( "<STR_LIT>" ) <EOL> pending_data . append ( ( metadata . hostname , data ) ) <EOL> except Empty : <EOL> pass <EOL> try : <EOL> savefile = open ( self . pending_file , '<STR_LIT:w>' ) <EOL> cPickle . dump ( pending_data , savefile ) <EOL> savefile . close ( ) <EOL> self . logger . info ( "<STR_LIT>" % self . name ) <EOL> except ( IOError , TypeError ) : <EOL> err = sys . exc_info ( ) [ <NUM_LIT:1> ] <EOL> self . logger . warning ( "<STR_LIT>" % err ) <EOL> def _load ( self ) : <EOL> """<STR_LIT>""" <EOL> if not os . path . exists ( self . pending_file ) : <EOL> return True <EOL> pending_data = [ ] <EOL> try : <EOL> savefile = open ( self . pending_file , '<STR_LIT:r>' ) <EOL> pending_data = cPickle . load ( savefile ) <EOL> savefile . close ( ) <EOL> except ( IOError , cPickle . UnpicklingError ) : <EOL> err = sys . exc_info ( ) [ <NUM_LIT:1> ] <EOL> self . logger . warning ( "<STR_LIT>" % err ) <EOL> return False <EOL> for ( pmetadata , pdata ) in pending_data : <EOL> if self . terminate . isSet ( ) : <EOL> return False <EOL> try : <EOL> while True : <EOL> try : <EOL> metadata = self . core . build_metadata ( pmetadata ) <EOL> break <EOL> except MetadataRuntimeError : <EOL> pass <EOL> self . terminate . wait ( <NUM_LIT:5> ) <EOL> if self . terminate . isSet ( ) : <EOL> return False <EOL> self . work_queue . put_nowait ( <EOL> ( metadata , <EOL> lxml . etree . XML ( pdata , parser = Bcfg2 . Server . XMLParser ) ) ) <EOL> except Full : <EOL> self . logger . warning ( "<STR_LIT>" ) <EOL> break <EOL> except lxml . etree . LxmlError : <EOL> lxml_error = sys . exc_info ( ) [ <NUM_LIT:1> ] <EOL> self . logger . error ( "<STR_LIT>" % <EOL> lxml_error ) <EOL> except MetadataConsistencyError : <EOL> self . logger . error ( "<STR_LIT>" <EOL> "<STR_LIT>" % pmetadata ) <EOL> try : <EOL> os . unlink ( self . pending_file ) <EOL> except OSError : <EOL> self . logger . error ( "<STR_LIT>" % <EOL> self . pending_file ) <EOL> self . logger . info ( "<STR_LIT>" % self . name ) <EOL> return True <EOL> def run ( self ) : <EOL> if not self . _load ( ) : <EOL> return <EOL> while not self . terminate . isSet ( ) and self . work_queue is not None : <EOL> try : <EOL> ( client , xdata ) = self . work_queue . get ( block = True , timeout = <NUM_LIT:2> ) <EOL> except Empty : <EOL> continue <EOL> except : <EOL> self . logger . error ( "<STR_LIT>" % <EOL> sys . exc_info ( ) [ <NUM_LIT:1> ] ) <EOL> continue <EOL> self . handle_statistic ( client , xdata ) <EOL> if self . work_queue is not None and not self . work_queue . empty ( ) : <EOL> self . _save ( ) <EOL> def process_statistics ( self , metadata , data ) : <EOL> try : <EOL> self . work_queue . put_nowait ( ( metadata , copy . copy ( data ) ) ) <EOL> except Full : <EOL> self . logger . warning ( "<STR_LIT>" % <EOL> self . name ) <EOL> def handle_statistic ( self , metadata , data ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> class PullSource ( object ) : <EOL> def GetExtra ( self , client ) : <EOL> return [ ] <EOL> def GetCurrentEntry ( self , client , e_type , e_name ) : <EOL> raise NotImplementedError <EOL> class PullTarget ( object ) : <EOL> def AcceptChoices ( self , entry , metadata ) : <EOL> raise NotImplementedError <EOL> def AcceptPullData ( self , specific , new_entry , verbose ) : <EOL> raise NotImplementedError <EOL> class Decision ( object ) : <EOL> """<STR_LIT>""" <EOL> def GetDecisions ( self , metadata , mode ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> class StructureValidator ( object ) : <EOL> """<STR_LIT>""" <EOL> def validate_structures ( self , metadata , structures ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> class GoalValidator ( object ) : <EOL> """<STR_LIT>""" <EOL> def validate_goals ( self , metadata , config ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> class Version ( Plugin ) : <EOL> """<STR_LIT>""" <EOL> create = False <EOL> options = Plugin . options + [ <EOL> Bcfg2 . Options . PathOption ( cf = ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> default = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) ] <EOL> __vcs_metadata_path__ = None <EOL> __rmi__ = Plugin . __rmi__ + [ '<STR_LIT>' ] <EOL> def __init__ ( self , core ) : <EOL> Plugin . __init__ ( self , core ) <EOL> if self . __vcs_metadata_path__ : <EOL> self . vcs_path = os . path . join ( Bcfg2 . Options . setup . vcs_root , <EOL> self . __vcs_metadata_path__ ) <EOL> if not os . path . exists ( self . vcs_path ) : <EOL> raise PluginInitError ( "<STR_LIT>" % self . vcs_path ) <EOL> else : <EOL> self . vcs_path = None <EOL> __init__ . __doc__ = Plugin . __init__ . __doc__ + """<STR_LIT>""" <EOL> def get_revision ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> class ClientRunHooks ( object ) : <EOL> """<STR_LIT>""" <EOL> def start_client_run ( self , metadata ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def end_client_run ( self , metadata ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def end_statistics ( self , metadata ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class ClientACLs ( object ) : <EOL> """<STR_LIT>""" <EOL> def check_acl_ip ( self , address , rmi ) : <EOL> """<STR_LIT>""" <EOL> return True <EOL> def check_acl_metadata ( self , metadata , rmi ) : <EOL> """<STR_LIT>""" <EOL> return True <EOL> class TemplateDataProvider ( object ) : <EOL> """<STR_LIT>""" <EOL> def get_template_data ( self , entry , metadata , template ) : <EOL> """<STR_LIT>""" <EOL> return dict ( ) <EOL> def get_xml_template_data ( self , structfile , metadata ) : <EOL> """<STR_LIT>""" <EOL> return dict ( ) </s>
