<s> """<STR_LIT>""" <EOL> from oslo . config import cfg <EOL> from rack import exception <EOL> from rack . openstack . common . gettextutils import _ <EOL> from rack . openstack . common import importutils <EOL> from rack . openstack . common import log as logging <EOL> from rack . openstack . common import service <EOL> from rack import utils <EOL> from rack import wsgi <EOL> LOG = logging . getLogger ( __name__ ) <EOL> service_opts = [ <EOL> cfg . StrOpt ( '<STR_LIT>' , <EOL> default = "<STR_LIT>" , <EOL> help = '<STR_LIT>' ) , <EOL> cfg . IntOpt ( '<STR_LIT>' , <EOL> default = <NUM_LIT> , <EOL> help = '<STR_LIT>' ) , <EOL> cfg . IntOpt ( '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> ] <EOL> CONF = cfg . CONF <EOL> CONF . register_opts ( service_opts ) <EOL> CONF . import_opt ( '<STR_LIT:host>' , '<STR_LIT>' ) <EOL> class WSGIService ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name , loader = None , use_ssl = False , max_url_len = None ) : <EOL> """<STR_LIT>""" <EOL> self . name = name <EOL> self . manager = self . _get_manager ( ) <EOL> self . loader = loader or wsgi . Loader ( ) <EOL> self . app = self . loader . load_app ( name ) <EOL> self . host = getattr ( CONF , '<STR_LIT>' % name , "<STR_LIT>" ) <EOL> self . port = getattr ( CONF , '<STR_LIT>' % name , <NUM_LIT:0> ) <EOL> self . workers = ( getattr ( CONF , '<STR_LIT>' % name , None ) or <EOL> utils . cpu_count ( ) ) <EOL> if self . workers and self . workers < <NUM_LIT:1> : <EOL> worker_name = '<STR_LIT>' % name <EOL> msg = ( _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) % <EOL> { '<STR_LIT>' : worker_name , <EOL> '<STR_LIT>' : str ( self . workers ) } ) <EOL> raise exception . InvalidInput ( msg ) <EOL> self . use_ssl = use_ssl <EOL> self . server = wsgi . Server ( name , <EOL> self . app , <EOL> host = self . host , <EOL> port = self . port , <EOL> use_ssl = self . use_ssl , <EOL> max_url_len = max_url_len ) <EOL> self . port = self . server . port <EOL> self . backdoor_port = None <EOL> def _get_manager ( self ) : <EOL> """<STR_LIT>""" <EOL> fl = '<STR_LIT>' % self . name <EOL> if fl not in CONF : <EOL> return None <EOL> manager_class_name = CONF . get ( fl , None ) <EOL> if not manager_class_name : <EOL> return None <EOL> manager_class = importutils . import_class ( manager_class_name ) <EOL> return manager_class ( ) <EOL> def start ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . manager : <EOL> self . manager . init_host ( ) <EOL> self . manager . pre_start_hook ( ) <EOL> if self . backdoor_port is not None : <EOL> self . manager . backdoor_port = self . backdoor_port <EOL> self . server . start ( ) <EOL> if self . manager : <EOL> self . manager . post_start_hook ( ) <EOL> def stop ( self ) : <EOL> """<STR_LIT>""" <EOL> self . server . stop ( ) <EOL> def wait ( self ) : <EOL> """<STR_LIT>""" <EOL> self . server . wait ( ) <EOL> def process_launcher ( ) : <EOL> return service . ProcessLauncher ( ) <EOL> _launcher = None <EOL> def serve ( server , workers = None ) : <EOL> global _launcher <EOL> if _launcher : <EOL> raise RuntimeError ( _ ( '<STR_LIT>' ) ) <EOL> _launcher = service . launch ( server , workers = workers ) <EOL> def wait ( ) : <EOL> _launcher . wait ( ) </s>
