Coverage for watcher/cmd/api.py: 91%

20 statements  

« prev     ^ index     » next       coverage.py v7.8.2, created at 2025-06-17 12:22 +0000

1# -*- encoding: utf-8 -*- 

2# 

3# Copyright 2013 Hewlett-Packard Development Company, L.P. 

4# All Rights Reserved. 

5# 

6# Licensed under the Apache License, Version 2.0 (the "License"); you may 

7# not use this file except in compliance with the License. You may obtain 

8# a copy of the License at 

9# 

10# http://www.apache.org/licenses/LICENSE-2.0 

11# 

12# Unless required by applicable law or agreed to in writing, software 

13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 

14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 

15# License for the specific language governing permissions and limitations 

16# under the License. 

17 

18"""Starter script for the Watcher API service.""" 

19 

20import sys 

21 

22from oslo_config import cfg 

23from oslo_log import log 

24 

25from watcher.api import scheduling 

26from watcher.common import service 

27from watcher import conf 

28 

29LOG = log.getLogger(__name__) 

30CONF = conf.CONF 

31 

32 

33def main(): 

34 service.prepare_service(sys.argv, CONF) 

35 

36 host, port = cfg.CONF.api.host, cfg.CONF.api.port 

37 protocol = "http" if not CONF.api.enable_ssl_api else "https" 

38 # Build and start the WSGI app 

39 server = service.WSGIService('watcher-api', CONF.api.enable_ssl_api) 

40 

41 if host == '127.0.0.1': 

42 LOG.info('serving on 127.0.0.1:%(port)s, ' 

43 'view at %(protocol)s://127.0.0.1:%(port)s', 

44 dict(protocol=protocol, port=port)) 

45 else: 

46 LOG.info('serving on %(protocol)s://%(host)s:%(port)s', 

47 dict(protocol=protocol, host=host, port=port)) 

48 

49 api_schedule = scheduling.APISchedulingService() 

50 api_schedule.start() 

51 

52 launcher = service.launch(CONF, server, workers=server.workers) 

53 launcher.wait()