Coverage for nova/cmd/baseproxy.py: 100%

27 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-04-17 15:08 +0000

1# 

2# Copyright (C) 2014 Red Hat, Inc 

3# 

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

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

6# a copy of the License at 

7# 

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

9# 

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

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

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

13# License for the specific language governing permissions and limitations 

14# under the License. 

15# 

16 

17"""Base proxy module used to create compatible consoles 

18for OpenStack Nova.""" 

19 

20import os 

21import sys 

22 

23from oslo_log import log as logging 

24from oslo_reports import guru_meditation_report as gmr 

25from oslo_reports import opts as gmr_opts 

26 

27import nova.conf 

28from nova.conf import novnc 

29from nova.conf import remote_debug 

30from nova.console import websocketproxy 

31from nova import objects 

32from nova import version 

33 

34 

35CONF = nova.conf.CONF 

36remote_debug.register_cli_opts(CONF) 

37novnc.register_cli_opts(CONF) 

38 

39gmr_opts.set_defaults(CONF) 

40objects.register_all() 

41 

42 

43def exit_with_error(msg, errno=-1): 

44 sys.stderr.write(msg + '\n') 

45 sys.exit(errno) 

46 

47 

48def proxy(host, port, security_proxy=None): 

49 """:param host: local address to listen on 

50 :param port: local port to listen on 

51 :param security_proxy: instance of 

52 nova.console.securityproxy.base.SecurityProxy 

53 

54 Setup a proxy listening on @host:@port. If the 

55 @security_proxy parameter is not None, this instance 

56 is used to negotiate security layer with the proxy target 

57 """ 

58 

59 if CONF.ssl_only and not os.path.exists(CONF.cert): 

60 exit_with_error("SSL only and %s not found" % CONF.cert) 

61 

62 # Check to see if tty html/js/css files are present 

63 if CONF.web and not os.path.exists(CONF.web): 

64 exit_with_error("Can not find html/js files at %s." % CONF.web) 

65 

66 logging.setup(CONF, "nova") 

67 

68 gmr.TextGuruMeditation.setup_autorun(version, conf=CONF) 

69 

70 # Create and start the NovaWebSockets proxy 

71 websocketproxy.NovaWebSocketProxy( 

72 listen_host=host, 

73 listen_port=port, 

74 source_is_ipv6=CONF.source_is_ipv6, 

75 cert=CONF.cert, 

76 key=CONF.key, 

77 ssl_only=CONF.ssl_only, 

78 ssl_ciphers=CONF.console.ssl_ciphers, 

79 ssl_minimum_version=CONF.console.ssl_minimum_version, 

80 daemon=CONF.daemon, 

81 record=CONF.record, 

82 traffic=not CONF.daemon, 

83 web=CONF.web, 

84 file_only=True, 

85 RequestHandlerClass=websocketproxy.NovaProxyRequestHandler, 

86 security_proxy=security_proxy, 

87 ).start_server()