diff --git a/include/MySqlDB.h b/include/MySqlDB.h index 94ff2055ab..decec7b728 100644 --- a/include/MySqlDB.h +++ b/include/MySqlDB.h @@ -44,9 +44,10 @@ class MySqlDB : public SqlDB public: MySqlDB(const string& server, + int port, const string& user, const string& password, - char * database); + char * database); ~MySqlDB(); @@ -109,6 +110,7 @@ public: MySqlDB( string server, + int port, string user, string password, char * database) @@ -127,4 +129,3 @@ public: #endif #endif /*MYSQL_DB_H_*/ - diff --git a/include/test/PoolTest.h b/include/test/PoolTest.h index 91a90654cf..c2324cbebb 100644 --- a/include/test/PoolTest.h +++ b/include/test/PoolTest.h @@ -98,7 +98,7 @@ public: { if (mysql) { - db = new MySqlDB("localhost","oneadmin","oneadmin",NULL); + db = new MySqlDB("localhost",0,"oneadmin","oneadmin",NULL); ostringstream oss1; oss1 << "DROP DATABASE IF EXISTS " << db_name; diff --git a/share/etc/oned.conf b/share/etc/oned.conf index 9216730c55..fb6afcc5e6 100644 --- a/share/etc/oned.conf +++ b/share/etc/oned.conf @@ -23,6 +23,8 @@ # 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 +# port : (mysql) port for the connection to the server. +# If set to 0, the default port is used. # user : (mysql) user's MySQL login ID # passwd : (mysql) the password for user # db_name : (mysql) the database name @@ -50,6 +52,7 @@ DB = [ backend = "sqlite" ] # Sample configuration for MySQL # DB = [ backend = "mysql", # server = "localhost", +# port = 0, # user = "oneadmin", # passwd = "oneadmin", # db_name = "opennebula" ] diff --git a/src/nebula/Nebula.cc b/src/nebula/Nebula.cc index 1f3c31f63b..6871a80ec0 100644 --- a/src/nebula/Nebula.cc +++ b/src/nebula/Nebula.cc @@ -42,11 +42,11 @@ void Nebula::start() int fd; sigset_t mask; int signal; - char hn[80]; + char hn[80]; if ( gethostname(hn,79) != 0 ) { - throw runtime_error("Error getting hostname"); + throw runtime_error("Error getting hostname"); } hostname = hn; @@ -81,9 +81,9 @@ void Nebula::start() try { - string log_fname; - int log_level_int; - Log::MessageType clevel = Log::ERROR; + string log_fname; + int log_level_int; + Log::MessageType clevel = Log::ERROR; log_fname = log_location + "oned.log"; @@ -141,6 +141,8 @@ void Nebula::start() bool db_is_sqlite = true; string server = "localhost"; + string port_str; + int port = 0; string user = "oneadmin"; string passwd = "oneadmin"; string db_name = "opennebula"; @@ -164,6 +166,18 @@ void Nebula::start() server = value; } + istringstream is; + + port_str = db->vector_value("PORT"); + + is.str(port_str); + is >> port; + + if( is.fail() ) + { + port = 0; + } + value = db->vector_value("USER"); if (!value.empty()) { @@ -194,7 +208,7 @@ void Nebula::start() { ostringstream oss; - db = new MySqlDB(server,user,passwd,0); + db = new MySqlDB(server,port,user,passwd,0); oss << "CREATE DATABASE IF NOT EXISTS " << db_name; rc = db->exec(oss); @@ -549,4 +563,3 @@ void Nebula::start() NebulaLog::log("ONE", Log::INFO, "All modules finalized, exiting.\n"); } - diff --git a/src/pool/test/pool.cc b/src/pool/test/pool.cc index f12e95cb3f..f2641c46ee 100644 --- a/src/pool/test/pool.cc +++ b/src/pool/test/pool.cc @@ -72,7 +72,7 @@ public: if (mysql) { - db = new MySqlDB("localhost","oneadmin","oneadmin",NULL); + db = new MySqlDB("localhost",0,"oneadmin","oneadmin",NULL); ostringstream oss1; oss1 << "DROP DATABASE IF EXISTS " << db_name; diff --git a/src/sql/MySqlDB.cc b/src/sql/MySqlDB.cc index 7e6ad4b257..d6697fe810 100644 --- a/src/sql/MySqlDB.cc +++ b/src/sql/MySqlDB.cc @@ -24,9 +24,10 @@ MySqlDB::MySqlDB( const string& server, + int port, const string& user, const string& password, - char * database) + char * database) { // Initialize the MySQL library @@ -37,7 +38,7 @@ MySqlDB::MySqlDB( // Connect to the server if (!mysql_real_connect(db, server.c_str(), user.c_str(), - password.c_str(), database, 0, NULL, 0)) + password.c_str(), database, port, NULL, 0)) { throw runtime_error("Could not open database."); }