<s> """<STR_LIT>""" <EOL> import sys <EOL> from eliot import FileDestination <EOL> from twisted . internet . defer import DeferredList , inlineCallbacks <EOL> from twisted . python . usage import UsageError <EOL> from twisted . python . filepath import FilePath <EOL> from flocker . provision . _ca import Certificates <EOL> from flocker . provision . _common import Cluster <EOL> from . acceptance import ( <EOL> capture_journal , <EOL> capture_upstart , <EOL> configure_eliot_logging_for_acceptance , <EOL> get_default_volume_size , <EOL> make_managed_nodes , <EOL> save_backend_configuration , <EOL> ) <EOL> from . cluster_setup import ( <EOL> RunOptions as SetupOptions , <EOL> make_client , <EOL> save_environment , <EOL> save_managed_config , <EOL> wait_for_nodes , <EOL> ) <EOL> class RunOptions ( SetupOptions ) : <EOL> optParameters = [ <EOL> [ '<STR_LIT>' , None , '<STR_LIT>' , <EOL> "<STR_LIT>" ] , <EOL> [ '<STR_LIT>' , None , None , <EOL> "<STR_LIT>" ] , <EOL> [ '<STR_LIT>' , None , None , <EOL> "<STR_LIT>" ] , <EOL> [ '<STR_LIT>' , None , None , <EOL> "<STR_LIT>" ] , <EOL> [ '<STR_LIT>' , None , <NUM_LIT:1> , <EOL> "<STR_LIT>" , int ] , <EOL> [ '<STR_LIT>' , None , None , <EOL> "<STR_LIT>" , int ] , <EOL> ] <EOL> synopsis = '<STR_LIT>' <EOL> def __init__ ( self , top_level ) : <EOL> """<STR_LIT>""" <EOL> super ( RunOptions , self ) . __init__ ( top_level ) <EOL> self . _remove_options ( [ '<STR_LIT>' ] ) <EOL> def _remove_options ( self , to_remove ) : <EOL> """<STR_LIT>""" <EOL> self . longOpt = [ opt for opt in self . longOpt if opt not in to_remove ] <EOL> def postOptions ( self ) : <EOL> if not self [ '<STR_LIT>' ] : <EOL> raise UsageError ( "<STR_LIT>" ) <EOL> if self . get ( '<STR_LIT>' ) is None : <EOL> raise UsageError ( "<STR_LIT>" ) <EOL> if self . get ( '<STR_LIT>' ) is None : <EOL> raise UsageError ( "<STR_LIT>" ) <EOL> super ( RunOptions , self ) . postOptions ( ) <EOL> def _check_cert_directory ( self ) : <EOL> cert_path = FilePath ( self [ '<STR_LIT>' ] ) <EOL> self [ '<STR_LIT>' ] = cert_path <EOL> if not cert_path . exists ( ) : <EOL> raise UsageError ( "<STR_LIT>" . format ( cert_path . path ) ) <EOL> if not cert_path . isdir ( ) : <EOL> raise UsageError ( "<STR_LIT>" . format ( cert_path . path ) ) <EOL> @ inlineCallbacks <EOL> def main ( reactor , args , base_path , top_level ) : <EOL> """<STR_LIT>""" <EOL> configure_eliot_logging_for_acceptance ( ) <EOL> options = RunOptions ( top_level = top_level ) <EOL> try : <EOL> options . parseOptions ( args ) <EOL> except UsageError as e : <EOL> sys . stderr . write ( "<STR_LIT>" % ( base_path . basename ( ) , e ) ) <EOL> sys . stderr . write ( "<STR_LIT:\n>" ) <EOL> sys . stderr . write ( str ( options ) ) <EOL> raise SystemExit ( <NUM_LIT:1> ) <EOL> existing_nodes = make_managed_nodes ( <EOL> options [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> options [ '<STR_LIT>' ] , <EOL> ) <EOL> [ control_node ] = [ <EOL> node for node in existing_nodes <EOL> if node . address == options [ '<STR_LIT>' ] <EOL> ] <EOL> dataset_backend_config_file = save_backend_configuration ( <EOL> options . dataset_backend ( ) , <EOL> options . dataset_backend_configuration ( ) , <EOL> ) <EOL> cluster = Cluster ( <EOL> all_nodes = list ( existing_nodes ) , <EOL> control_node = control_node , <EOL> agent_nodes = list ( existing_nodes ) , <EOL> dataset_backend = options . dataset_backend ( ) , <EOL> default_volume_size = get_default_volume_size ( <EOL> options . dataset_backend_configuration ( ) <EOL> ) , <EOL> certificates = Certificates ( options [ '<STR_LIT>' ] ) , <EOL> dataset_backend_config_file = dataset_backend_config_file , <EOL> ) <EOL> flocker_client = make_client ( reactor , cluster ) <EOL> existing_count = len ( existing_nodes ) <EOL> yield wait_for_nodes ( reactor , flocker_client , existing_count ) <EOL> if options [ '<STR_LIT>' ] is None : <EOL> options [ '<STR_LIT>' ] = existing_count <EOL> print ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" . format ( <EOL> options [ '<STR_LIT>' ] , <EOL> existing_count , <EOL> options [ '<STR_LIT>' ] , <EOL> ) <EOL> ) <EOL> runner = options . runner <EOL> cleanup_id = reactor . addSystemEventTrigger ( '<STR_LIT>' , '<STR_LIT>' , <EOL> runner . stop_cluster , reactor ) <EOL> from flocker . common . script import eliot_logging_service <EOL> log_writer = eliot_logging_service ( <EOL> destination = FileDestination ( <EOL> file = open ( "<STR_LIT>" % ( base_path . basename ( ) , ) , "<STR_LIT:a>" ) <EOL> ) , <EOL> reactor = reactor , <EOL> capture_stdout = False ) <EOL> log_writer . startService ( ) <EOL> reactor . addSystemEventTrigger ( <EOL> '<STR_LIT>' , '<STR_LIT>' , log_writer . stopService ) <EOL> control_node = options [ '<STR_LIT>' ] <EOL> if options [ '<STR_LIT>' ] in ( '<STR_LIT>' , ) : <EOL> remote_logs_file = open ( "<STR_LIT>" , "<STR_LIT:a>" ) <EOL> capture_journal ( reactor , control_node , remote_logs_file ) <EOL> elif options [ '<STR_LIT>' ] in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> remote_logs_file = open ( "<STR_LIT>" , "<STR_LIT:a>" ) <EOL> capture_upstart ( reactor , control_node , remote_logs_file ) <EOL> yield runner . ensure_keys ( reactor ) <EOL> deferreds = runner . extend_cluster ( <EOL> reactor , <EOL> cluster , <EOL> options [ '<STR_LIT>' ] , <EOL> options [ '<STR_LIT>' ] , <EOL> options [ '<STR_LIT>' ] , <EOL> ) <EOL> results = yield DeferredList ( deferreds ) <EOL> failed_count = <NUM_LIT:0> <EOL> for ( success , value ) in results : <EOL> if not success : <EOL> failed_count = failed_count + <NUM_LIT:1> <EOL> if failed_count : <EOL> print "<STR_LIT>" . format ( failed_count ) <EOL> yield wait_for_nodes ( <EOL> reactor , <EOL> flocker_client , <EOL> len ( cluster . agent_nodes ) , <EOL> ) <EOL> save_managed_config ( options [ '<STR_LIT>' ] , options [ '<STR_LIT>' ] , cluster ) <EOL> save_environment ( <EOL> options [ '<STR_LIT>' ] , cluster , options . package_source ( ) <EOL> ) <EOL> reactor . removeSystemEventTrigger ( cleanup_id ) </s>
