From 33e01f53b16726cb5db74d99242c03f12123b542 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Wed, 10 Nov 2010 18:44:13 +0100 Subject: [PATCH] Feature #377: MySQL port is now defined in oned.conf --- include/MySqlDB.h | 2 ++ include/test/PoolTest.h | 2 +- share/etc/oned.conf | 3 +++ src/nebula/Nebula.cc | 16 +++++++++++++++- src/pool/test/pool.cc | 2 +- src/sql/MySqlDB.cc | 3 ++- 6 files changed, 24 insertions(+), 4 deletions(-) diff --git a/include/MySqlDB.h b/include/MySqlDB.h index 94ff2055ab..f0d1e1d302 100644 --- a/include/MySqlDB.h +++ b/include/MySqlDB.h @@ -44,6 +44,7 @@ class MySqlDB : public SqlDB public: MySqlDB(const string& server, + const int& port, const string& user, const string& password, char * database); @@ -109,6 +110,7 @@ public: MySqlDB( string server, + int port, string user, string password, char * database) 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 35dfd523e1..94da223341 100644 --- a/share/etc/oned.conf +++ b/share/etc/oned.conf @@ -19,6 +19,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 @@ -44,6 +46,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..74a1a87974 100644 --- a/src/nebula/Nebula.cc +++ b/src/nebula/Nebula.cc @@ -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); 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..f390e1f461 100644 --- a/src/sql/MySqlDB.cc +++ b/src/sql/MySqlDB.cc @@ -24,6 +24,7 @@ MySqlDB::MySqlDB( const string& server, + const int& port, const string& user, const string& password, char * database) @@ -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."); }