<s> """<STR_LIT>""" <EOL> import cProfile <EOL> import signal <EOL> from functools import partial <EOL> from time import clock <EOL> from twisted . python . usage import Options <EOL> from twisted . internet . endpoints import serverFromString <EOL> from twisted . python . filepath import FilePath <EOL> from twisted . application . service import MultiService <EOL> from twisted . internet . ssl import Certificate <EOL> from . httpapi import create_api_service , REST_API_PORT <EOL> from . _persistence import ConfigurationPersistenceService <EOL> from . _clusterstate import ClusterStateService <EOL> from . . common . script import ( <EOL> flocker_standard_options , FlockerScriptRunner , main_for_service , <EOL> enable_profiling , disable_profiling ) <EOL> from . _protocol import ControlAMPService <EOL> from . . ca import ( <EOL> rest_api_context_factory , ControlCredential , amp_server_context_factory , <EOL> ) <EOL> DEFAULT_CERTIFICATE_PATH = b"<STR_LIT>" <EOL> @ flocker_standard_options <EOL> class ControlOptions ( Options ) : <EOL> """<STR_LIT>""" <EOL> optParameters = [ <EOL> [ "<STR_LIT>" , "<STR_LIT:d>" , FilePath ( b"<STR_LIT>" ) , <EOL> "<STR_LIT>" , FilePath ] , <EOL> [ "<STR_LIT:port>" , "<STR_LIT:p>" , '<STR_LIT>' % ( REST_API_PORT , ) , <EOL> "<STR_LIT>" ] , <EOL> [ "<STR_LIT>" , "<STR_LIT:a>" , '<STR_LIT>' , <EOL> "<STR_LIT>" ] , <EOL> [ "<STR_LIT>" , "<STR_LIT:c>" , DEFAULT_CERTIFICATE_PATH , <EOL> ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) ] , <EOL> ] <EOL> class ControlScript ( object ) : <EOL> """<STR_LIT>""" <EOL> def main ( self , reactor , options ) : <EOL> certificates_path = FilePath ( options [ "<STR_LIT>" ] ) <EOL> ca = Certificate . loadPEM ( <EOL> certificates_path . child ( b"<STR_LIT>" ) . getContent ( ) ) <EOL> control_credential = ControlCredential . from_path ( <EOL> certificates_path , b"<STR_LIT>" ) <EOL> top_service = MultiService ( ) <EOL> persistence = ConfigurationPersistenceService ( <EOL> reactor , options [ "<STR_LIT>" ] ) <EOL> persistence . setServiceParent ( top_service ) <EOL> cluster_state = ClusterStateService ( reactor ) <EOL> cluster_state . setServiceParent ( top_service ) <EOL> api_service = create_api_service ( <EOL> persistence , cluster_state , serverFromString ( <EOL> reactor , options [ "<STR_LIT:port>" ] ) , <EOL> rest_api_context_factory ( ca , control_credential ) ) <EOL> api_service . setServiceParent ( top_service ) <EOL> amp_service = ControlAMPService ( <EOL> reactor , cluster_state , persistence , serverFromString ( <EOL> reactor , options [ "<STR_LIT>" ] ) , <EOL> amp_server_context_factory ( ca , control_credential ) ) <EOL> amp_service . setServiceParent ( top_service ) <EOL> return main_for_service ( reactor , top_service ) <EOL> def flocker_control_main ( ) : <EOL> pr = cProfile . Profile ( clock ) <EOL> signal . signal ( signal . SIGUSR1 , partial ( enable_profiling , pr ) ) <EOL> signal . signal ( signal . SIGUSR2 , partial ( disable_profiling , pr , '<STR_LIT>' ) ) <EOL> return FlockerScriptRunner ( <EOL> script = ControlScript ( ) , <EOL> options = ControlOptions ( ) <EOL> ) . main ( ) </s>
