import errno
import logging
import os
-import socket
import ssl
import sys
import tempfile
else:
server_port = self.get_localized_module_option('ssl_server_port', 8443) # type: ignore
+ if server_addr == '::':
+ server_addr = self.get_mgr_ip() # type: ignore
if server_addr is None:
raise ServerConfigException(
'no server_addr configured; '
uri = "{0}://{1}:{2}{3}/".format(
'https' if use_ssl else 'http',
- socket.getfqdn(server_addr if server_addr != '::' else ''),
+ server_addr,
server_port,
self.url_prefix
)
from enum import IntEnum
import rados
import re
+import socket
import sys
import time
from ceph_argparse import CephArgtype
def get_active_uri(self) -> str:
return self._ceph_get_active_uri()
+ def get_mgr_ip(self) -> str:
+ hostname = socket.gethostname()
+ try:
+ r = socket.getaddrinfo(hostname, None, flags=socket.AI_CANONNAME,
+ type=socket.SOCK_STREAM)
+ # pick first v4 IP, if present, as long as it is not 127.0.{0,1}.1
+ for a in r:
+ if a[4][0] in ['127.0.1.1', '127.0.0.1']:
+ continue
+ if a[0] == socket.AF_INET:
+ return a[4][0]
+ except socket.gaierror as e:
+ pass
+ return hostname
+
def get_localized_module_option(self, key: str, default: OptionValue = None) -> OptionValue:
r = self._ceph_get_module_option(key, self.get_mgr_id())
if r is None:
def get_ceph_conf_path(self) -> str:
return self._ceph_get_ceph_conf_path()
+ def get_mgr_ip(self) -> str:
+ hostname = socket.gethostname()
+ try:
+ r = socket.getaddrinfo(hostname, None, flags=socket.AI_CANONNAME,
+ type=socket.SOCK_STREAM)
+ # pick first v4 IP, if present, as long as it is not 127.0.{0,1}.1
+ for a in r:
+ if a[4][0] in ['127.0.1.1', '127.0.0.1']:
+ continue
+ if a[0] == socket.AF_INET:
+ return a[4][0]
+ except socket.gaierror as e:
+ pass
+ return hostname
+
def get_ceph_option(self, key: str) -> OptionValue:
return self._ceph_get_option(key)
import math
import os
import re
-import socket
import threading
import time
from mgr_module import CLIReadCommand, MgrModule, MgrStandbyModule, PG_STATES, Option, ServiceInfoT
# Publish the URI that others may use to access the service we're
# about to start serving
- self.set_uri('http://{0}:{1}/'.format(
- socket.getfqdn() if server_addr in ['::', '0.0.0.0'] else server_addr,
- server_port
- ))
+ if server_addr in ['::', '0.0.0.0']:
+ server_addr = self.get_mgr_ip()
+ self.set_uri('http://{0}:{1}/'.format(server_addr, server_port))
cherrypy.config.update({
'server.socket_host': server_addr,