Skip to content

Commit

Permalink
mgr: use ipv4 default when ipv6 was disabled
Browse files Browse the repository at this point in the history
Fixes: https://tracker.ceph.com/issues/40023
Signed-off-by: kungf <yang.wang@easystack.cn>
  • Loading branch information
kungf committed May 27, 2019
1 parent b97022c commit a84f092
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
2 changes: 2 additions & 0 deletions ceph.spec.in
Expand Up @@ -434,6 +434,7 @@ Requires: ceph-base = %{_epoch_prefix}%{version}-%{release}
Requires: python%{_python_buildid}-bcrypt
Requires: python%{_python_buildid}-pecan
Requires: python%{_python_buildid}-six
Requires: python%{_python_buildid}-netifaces
%if 0%{?fedora} || 0%{?rhel}
Requires: python%{_python_buildid}-cherrypy
Requires: python%{_python_buildid}-werkzeug
Expand Down Expand Up @@ -468,6 +469,7 @@ BuildArch: noarch
Group: System/Filesystems
%endif
Requires: ceph-mgr = %{_epoch_prefix}%{version}-%{release}
Requires: python%{_python_buildid}-netifaces
%if 0%{?fedora} || 0%{?rhel}
Requires: python%{_python_buildid}-cherrypy
Requires: python%{_python_buildid}-ipaddress
Expand Down
7 changes: 4 additions & 3 deletions src/pybind/mgr/dashboard/module.py
Expand Up @@ -14,7 +14,7 @@
import time
from uuid import uuid4
from OpenSSL import crypto, SSL
from mgr_module import MgrModule, MgrStandbyModule, Option
from mgr_module import MgrModule, MgrStandbyModule, Option, DEFAULT_ADDR

try:
import cherrypy
Expand Down Expand Up @@ -125,7 +125,8 @@ def _configure(self):
:returns our URI
"""
server_addr = self.get_localized_module_option('server_addr', '::')
server_addr = self.get_localized_module_option('server_addr',
DEFAULT_ADDR)
ssl = self.get_localized_module_option('ssl', True)
if not ssl:
server_port = self.get_localized_module_option('server_port', 8080)
Expand Down Expand Up @@ -295,7 +296,7 @@ class Module(MgrModule, CherryPyConfig):
PLUGIN_MANAGER.hook.register_commands()

MODULE_OPTIONS = [
Option(name='server_addr', type='str', default='::'),
Option(name='server_addr', type='str', default=DEFAULT_ADDR),
Option(name='server_port', type='int', default=8080),
Option(name='ssl_server_port', type='int', default=8443),
Option(name='jwt_token_ttl', type='int', default=28800),
Expand Down
18 changes: 18 additions & 0 deletions src/pybind/mgr/mgr_module.py
Expand Up @@ -2,6 +2,7 @@

import logging
import json
import netifaces
import six
import threading
from collections import defaultdict, namedtuple
Expand Down Expand Up @@ -40,6 +41,23 @@
"creating",
"unknown"]

def is_ipv6_enabled():
"""
Check whether IPv6 is enabled.
:return: Return True if IPv6 is enabled, otherwise False.
:rtype: bool
"""
interfaces = netifaces.interfaces()
for i in interfaces:
if netifaces.ifaddresses(i).has_key(netifaces.AF_INET6):
return True;
return False

if is_ipv6_enabled():
DEFAULT_ADDR = '::'
else:
DEFAULT_ADDR = '0.0.0.0'


class CPlusPlusHandler(logging.Handler):
def __init__(self, module_inst):
Expand Down
7 changes: 4 additions & 3 deletions src/pybind/mgr/prometheus/module.py
Expand Up @@ -8,14 +8,14 @@
import socket
import threading
import time
from mgr_module import MgrModule, MgrStandbyModule, CommandResult, PG_STATES
from mgr_module import MgrModule, MgrStandbyModule, CommandResult, PG_STATES, \
DEFAULT_ADDR
from rbd import RBD

# Defaults for the Prometheus HTTP server. Can also set in config-key
# see https://github.com/prometheus/prometheus/wiki/Default-port-allocations
# for Prometheus exporter port registry

DEFAULT_ADDR = '::'
DEFAULT_PORT = 9283

# When the CherryPy server in 3.2.2 (and later) starts it attempts to verify
Expand Down Expand Up @@ -1028,7 +1028,8 @@ def __init__(self, *args, **kwargs):
self.shutdown_event = threading.Event()

def serve(self):
server_addr = self.get_localized_module_option('server_addr', '::')
server_addr = self.get_localized_module_option('server_addr',
DEFAULT_ADDR)
server_port = self.get_localized_module_option(
'server_port', DEFAULT_PORT)
self.log.info("server_addr: %s server_port: %s" %
Expand Down

0 comments on commit a84f092

Please sign in to comment.