diff --git a/share/etc/oned.conf b/share/etc/oned.conf index 400a37a48f..0444c6fb61 100644 --- a/share/etc/oned.conf +++ b/share/etc/oned.conf @@ -24,9 +24,6 @@ # SCRIPTS_REMOTE_DIR: Remote path to store the monitoring and VM management # scripts. # -# PORT: Port where oned will listen for xmlrpc calls. -# LISTEN_ADDRESS: Host IP to listen on for xmlrpc calls (default: all IPs). -# # DB: Configuration attributes for the database backend # backend : can be sqlite or mysql (default is sqlite) # server : (mysql) host name or an IP address for the MySQL server @@ -71,9 +68,6 @@ MONITORING_INTERVAL_DB_UPDATE = 0 SCRIPTS_REMOTE_DIR=/var/tmp/one -PORT = 2633 - -LISTEN_ADDRESS = "0.0.0.0" DB = [ BACKEND = "sqlite" ] @@ -92,6 +86,23 @@ VNC_PORTS = [ # RESERVED = "6800, 6801, 6810:6820, 9869" ] +#******************************************************************************* +# Server network and connection +#------------------------------------------------------------------------------- +# PORT: Port where oned will listen for xmlrpc calls. +# +# LISTEN_ADDRESS: Host IP to listen on for xmlrpc calls (default: all IPs). +# +# HOSTNAME: This Hostname is used by OpenNebula daemon to connect to the +# frontend during drivers operations. If this variable is not set, OpenNebula +# will auto detect it. It can be in FQDN format, hostname or an IP + +PORT = 2633 + +LISTEN_ADDRESS = "0.0.0.0" + +# HOSTNAME = "one-hostname" + #******************************************************************************* # API configuration attributes #------------------------------------------------------------------------------- diff --git a/src/nebula/Nebula.cc b/src/nebula/Nebula.cc index b32ca26b16..1ca619d682 100644 --- a/src/nebula/Nebula.cc +++ b/src/nebula/Nebula.cc @@ -67,6 +67,8 @@ #include #include #include +#include +#include #include #include @@ -130,20 +132,12 @@ void Nebula::start(bool bootstrap_only) int fd; sigset_t mask; int signal; - char hn[80]; string scripts_remote_dir; SqlDB * db_backend; bool solo; SqlDB * db_ptr; - if ( gethostname(hn,79) != 0 ) - { - throw runtime_error("Error getting hostname"); - } - - hostname = hn; - // ----------------------------------------------------------- // Configuration // ----------------------------------------------------------- @@ -167,6 +161,44 @@ void Nebula::start(bool bootstrap_only) } nebula_configuration->get("SCRIPTS_REMOTE_DIR", scripts_remote_dir); + + // ----------------------------------------------------------- + // Get Hostname + // ----------------------------------------------------------- + nebula_configuration->get("HOSTNAME", hostname); + + if ( hostname.empty() ) + { + char hn[1024]; + struct addrinfo hints = {}, *addrs; + + hints.ai_family = AF_UNSPEC; + hints.ai_flags = AI_CANONNAME; + + rc = gethostname(hn, 1023); + + if ( rc != 0 ) + { + throw runtime_error("Error getting hostname" + + std::string(strerror(rc))); + } + + rc = getaddrinfo(hn, nullptr, &hints, &addrs); + + if ( rc != 0 ) + { + throw runtime_error("Error getting hostname: " + + std::string(gai_strerror(rc))); + } + + if ( addrs != nullptr && addrs->ai_canonname != nullptr ) + { + hostname = addrs->ai_canonname; + } + + freeaddrinfo(addrs); + } + // ----------------------------------------------------------- // Log system // ----------------------------------------------------------- @@ -228,6 +260,8 @@ void Nebula::start(bool bootstrap_only) throw; } + NebulaLog::log("ONE", Log::INFO, "Using hostname: " + hostname); + // ----------------------------------------------------------- // Load the OpenNebula master key and keep it in memory // -----------------------------------------------------------