1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

Merge branch 'feature-377'

This commit is contained in:
Ruben S. Montero 2010-11-13 00:17:54 +01:00
commit 9c16a3ca0c
6 changed files with 31 additions and 13 deletions

View File

@ -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_*/

View File

@ -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;

View File

@ -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" ]

View File

@ -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");
}

View File

@ -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;

View File

@ -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.");
}