1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-12 09:17:41 +03:00

Merge branch 'bug-419'

This commit is contained in:
Ruben S. Montero 2011-02-01 16:46:39 +01:00
commit bcb7e774de
19 changed files with 72 additions and 39 deletions

View File

@ -103,6 +103,8 @@ private:
static const char * db_names;
static const char * extended_db_names;
static const char * db_bootstrap;
void non_persistent_data();

View File

@ -479,6 +479,8 @@ protected:
LIMIT = 11
};
static const char * extended_db_names;
static const char * db_names;
static const char * db_bootstrap;

View File

@ -1013,6 +1013,8 @@ protected:
static const char * db_names;
static const char * extended_db_names;
static const char * db_bootstrap;
/**

View File

@ -365,6 +365,8 @@ protected:
static const char * db_names;
static const char * extended_db_names;
static const char * db_bootstrap;
/**

View File

@ -52,8 +52,8 @@ Host::~Host(){}
const char * Host::table = "host_pool";
const char * Host::db_names = "(oid,host_name,state,im_mad,vm_mad,"
"tm_mad,last_mon_time, cluster, template)";
const char * Host::db_names = "oid,host_name,state,im_mad,vm_mad,"
"tm_mad,last_mon_time, cluster, template";
const char * Host::db_bootstrap = "CREATE TABLE IF NOT EXISTS host_pool ("
"oid INTEGER PRIMARY KEY,host_name VARCHAR(256), state INTEGER,"
@ -109,7 +109,7 @@ int Host::select(SqlDB *db)
set_callback(static_cast<Callbackable::Callback>(&Host::select_cb));
oss << "SELECT * FROM " << table << " WHERE oid = " << oid;
oss << "SELECT " << db_names << " FROM " << table << " WHERE oid = " << oid;
boid = oid;
oid = -1;
@ -275,7 +275,7 @@ int Host::insert_replace(SqlDB *db, bool replace)
// Construct the SQL statement to Insert or Replace
oss <<" INTO "<< table <<" "<< db_names <<" VALUES ("
oss <<" INTO "<< table <<" ("<< db_names <<") VALUES ("
<< oid << ","
<< "'" << sql_hostname << "',"
<< state << ","

View File

@ -265,7 +265,8 @@ int HostPool::dump(ostringstream& oss, const string& where)
set_callback(static_cast<Callbackable::Callback>(&HostPool::dump_cb),
static_cast<void *>(&oss));
cmd << "SELECT * FROM " << Host::table << " JOIN " << HostShare::table
cmd << "SELECT " << Host::db_names << " , " << HostShare::db_names
<< " FROM " << Host::table << " JOIN " << HostShare::table
<< " ON " << Host::table << ".oid = " << HostShare::table << ".hid";
if ( !where.empty() )

View File

@ -56,12 +56,12 @@ HostShare::HostShare(
const char * HostShare::table = "host_shares";
const char * HostShare::db_names = "(hid,"
const char * HostShare::db_names = "hid,"
"disk_usage, mem_usage, cpu_usage,"
"max_disk, max_mem, max_cpu,"
"free_disk, free_mem, free_cpu,"
"used_disk, used_mem, used_cpu,"
"running_vms)";
"running_vms";
const char * HostShare::db_bootstrap = "CREATE TABLE IF NOT EXISTS host_shares("
"hid INTEGER PRIMARY KEY,"
@ -177,7 +177,7 @@ int HostShare::select(SqlDB * db)
set_callback(static_cast<Callbackable::Callback>(&HostShare::select_cb));
oss << "SELECT * FROM " << table << " WHERE hid = " << hsid;
oss << "SELECT "<< db_names << " FROM " << table << " WHERE hid = " << hsid;
bhsid = hsid;
hsid = -1;
@ -240,7 +240,7 @@ int HostShare::insert_replace(SqlDB *db, bool replace)
oss << "INSERT";
}
oss << " INTO " << table << " "<< db_names <<" VALUES ("
oss << " INTO " << table << " ("<< db_names <<") VALUES ("
<< hsid << ","
<< disk_usage <<","<< mem_usage <<","<< cpu_usage<< ","
<< max_disk <<","<< max_mem <<","<< max_cpu << ","

View File

@ -66,8 +66,13 @@ Image::~Image()
const char * Image::table = "image_pool";
const char * Image::db_names = "(oid, uid, name, type, public, persistent, regtime, "
"source, state, running_vms, template)";
const char * Image::db_names = "oid, uid, name, type, public, persistent, regtime, "
"source, state, running_vms, template";
const char * Image::extended_db_names = "image_pool.oid, image_pool.uid, "
"image_pool.name, image_pool.type, image_pool.public, "
"image_pool.persistent, image_pool.regtime, image_pool.source, "
"image_pool.state, image_pool.running_vms, image_pool.template";
const char * Image::db_bootstrap = "CREATE TABLE IF NOT EXISTS image_pool ("
"oid INTEGER PRIMARY KEY, uid INTEGER, name VARCHAR(128), "
@ -127,7 +132,7 @@ int Image::select(SqlDB *db)
set_callback(static_cast<Callbackable::Callback>(&Image::select_cb));
oss << "SELECT * FROM " << table << " WHERE oid = " << oid;
oss << "SELECT " << db_names << " FROM " << table << " WHERE oid = " << oid;
boid = oid;
oid = -1;
@ -332,7 +337,7 @@ int Image::insert_replace(SqlDB *db, bool replace)
// Construct the SQL statement to Insert or Replace
oss <<" INTO "<< table <<" "<< db_names <<" VALUES ("
oss <<" INTO "<< table <<" ("<< db_names <<") VALUES ("
<< oid << ","
<< uid << ","
<< "'" << sql_name << "',"

View File

@ -144,7 +144,7 @@ int ImagePool::dump(ostringstream& oss, const string& where)
set_callback(static_cast<Callbackable::Callback>(&ImagePool::dump_cb),
static_cast<void *>(&oss));
cmd << "SELECT " << Image::table << ".*, user_pool.user_name FROM "
cmd << "SELECT "<< Image::extended_db_names << ", user_pool.user_name FROM "
<< Image::table
<< " LEFT OUTER JOIN (SELECT oid, user_name FROM user_pool) "
<< "AS user_pool ON " << Image::table << ".uid = user_pool.oid";

View File

@ -50,7 +50,7 @@ User::~User(){};
const char * User::table = "user_pool";
const char * User::db_names = "(oid,user_name,password,enabled)";
const char * User::db_names = "oid,user_name,password,enabled";
const char * User::db_bootstrap = "CREATE TABLE IF NOT EXISTS user_pool ("
"oid INTEGER PRIMARY KEY, user_name VARCHAR(256), password TEXT,"
@ -91,7 +91,7 @@ int User::select(SqlDB *db)
set_callback(static_cast<Callbackable::Callback>(&User::select_cb));
oss << "SELECT * FROM " << table << " WHERE oid = " << oid;
oss << "SELECT " << db_names << " FROM " << table << " WHERE oid = " << oid;
boid = oid;
oid = -1;
@ -183,7 +183,7 @@ int User::insert_replace(SqlDB *db, bool replace)
oss << "INSERT";
}
oss << " INTO " << table << " "<< db_names <<" VALUES ("
oss << " INTO " << table << " ("<< db_names <<") VALUES ("
<< oid << ","
<< "'" << sql_username << "',"
<< "'" << sql_password << "',"

View File

@ -343,7 +343,7 @@ int UserPool::dump(ostringstream& oss, const string& where)
set_callback(static_cast<Callbackable::Callback>(&UserPool::dump_cb),
static_cast<void *>(&oss));
cmd << "SELECT * FROM " << User::table;
cmd << "SELECT " << User::db_names << " FROM " << User::table;
if ( !where.empty() )
{

View File

@ -25,8 +25,14 @@
const char * History::table = "history";
const char * History::db_names = "(vid,seq,host_name,vm_dir,hid,vm_mad,tm_mad,stime,"
"etime,pstime,petime,rstime,retime,estime,eetime,reason)";
const char * History::db_names = "vid,seq,host_name,vm_dir,hid,vm_mad,tm_mad,stime,"
"etime,pstime,petime,rstime,retime,estime,eetime,reason";
const char * History::extended_db_names =
"history.vid, history.seq, history.host_name, history.vm_dir, history.hid, "
"history.vm_mad, history.tm_mad, history.stime, history.etime, "
"history.pstime, history.petime, history.rstime, history.retime, "
"history.estime, history.eetime, history.reason";
const char * History::db_bootstrap = "CREATE TABLE IF NOT EXISTS "
"history (vid INTEGER,"
@ -212,7 +218,7 @@ int History::insert_replace(SqlDB *db, bool replace)
oss << "INSERT";
}
oss << " INTO " << table << " "<< db_names <<" VALUES ("<<
oss << " INTO " << table << " ("<< db_names <<") VALUES ("<<
oid << "," <<
seq << "," <<
"'" << sql_hostname << "',"<<
@ -359,12 +365,13 @@ int History::select(SqlDB * db)
if ( seq == -1)
{
oss << "SELECT * FROM history WHERE vid = "<< oid <<
oss << "SELECT " << db_names << " FROM history WHERE vid = "<< oid <<
" AND seq=(SELECT MAX(seq) FROM history WHERE vid = " << oid << ")";
}
else
{
oss << "SELECT * FROM history WHERE vid = "<< oid <<" AND seq = "<< seq;
oss << "SELECT " << db_names << " FROM history WHERE vid = " << oid
<< " AND seq = " << seq;
}
set_callback(static_cast<Callbackable::Callback>(&History::select_cb));

View File

@ -95,8 +95,14 @@ VirtualMachine::~VirtualMachine()
const char * VirtualMachine::table = "vm_pool";
const char * VirtualMachine::db_names =
"(oid,uid,name,last_poll, state,lcm_state,stime,etime,deploy_id"
",memory,cpu,net_tx,net_rx,last_seq, template)";
"oid,uid,name,last_poll, state,lcm_state,stime,etime,deploy_id"
",memory,cpu,net_tx,net_rx,last_seq, template";
const char * VirtualMachine::extended_db_names =
"vm_pool.oid, vm_pool.uid, vm_pool.name, vm_pool.last_poll, vm_pool.state, "
"vm_pool.lcm_state, vm_pool.stime, vm_pool.etime, vm_pool.deploy_id, "
"vm_pool.memory, vm_pool.cpu, vm_pool.net_tx, vm_pool.net_rx, "
"vm_pool.last_seq, vm_pool.template";
const char * VirtualMachine::db_bootstrap = "CREATE TABLE IF NOT EXISTS "
"vm_pool ("
@ -174,7 +180,7 @@ int VirtualMachine::select(SqlDB * db)
set_callback(
static_cast<Callbackable::Callback>(&VirtualMachine::select_cb));
oss << "SELECT * FROM " << table << " WHERE oid = " << oid;
oss << "SELECT " << db_names << " FROM " << table << " WHERE oid = " << oid;
boid = oid;
oid = -1;
@ -598,7 +604,7 @@ int VirtualMachine::insert_replace(SqlDB *db, bool replace)
oss << "INSERT";
}
oss << " INTO " << table << " "<< db_names <<" VALUES ("
oss << " INTO " << table << " ("<< db_names <<") VALUES ("
<< oid << ","
<< uid << ","
<< "'" << sql_name << "',"

View File

@ -278,13 +278,14 @@ int VirtualMachinePool::dump( ostringstream& oss,
&VirtualMachinePool::dump_extended_cb),
static_cast<void *>(&oss));
cmd << "SELECT " << VirtualMachine::table << ".*, user_pool.user_name, "
<< History::table << ".* FROM " << VirtualMachine::table
cmd << "SELECT " << VirtualMachine::extended_db_names
<< ", user_pool.user_name, "
<< History::extended_db_names << " FROM " << VirtualMachine::table
<< " LEFT OUTER JOIN " << History::table << " ON "
<< VirtualMachine::table << ".oid = " << History::table << ".vid AND "
<< History::table << ".seq = " << VirtualMachine::table
<< ".last_seq LEFT OUTER JOIN (SELECT oid,user_name FROM user_pool) "
<< "AS user_pool ON " << VirtualMachine::table << ".uid = user_pool.oid";
<< "AS user_pool ON "<< VirtualMachine::table << ".uid = user_pool.oid";
}
else
{
@ -292,7 +293,8 @@ int VirtualMachinePool::dump( ostringstream& oss,
static_cast<Callbackable::Callback>(&VirtualMachinePool::dump_cb),
static_cast<void *>(&oss));
cmd << "SELECT * FROM " << VirtualMachine::table;
cmd << "SELECT " << VirtualMachine::db_names << " FROM "
<< VirtualMachine::table;
}
if ( state != -1 )

View File

@ -72,7 +72,7 @@ int FixedLeases::add(const string& ip, const string& mac, int vid, bool used)
goto error_mac;
}
oss << "INSERT INTO " << table << " "<< db_names <<" VALUES (" <<
oss << "INSERT INTO " << table << " ("<< db_names <<") VALUES (" <<
oid << "," <<
_ip << "," <<
_mac[Lease::PREFIX] << "," <<

View File

@ -248,7 +248,7 @@ string& Leases::Lease::to_xml(string& str) const
const char * Leases::table = "leases";
const char * Leases::db_names = "(oid,ip,mac_prefix,mac_suffix,vid,used)";
const char * Leases::db_names = "oid,ip,mac_prefix,mac_suffix,vid,used";
const char * Leases::db_bootstrap = "CREATE TABLE IF NOT EXISTS leases ("
"oid INTEGER, ip BIGINT, mac_prefix BIGINT, mac_suffix BIGINT,"
@ -310,7 +310,7 @@ int Leases::select(SqlDB * db)
set_callback(static_cast<Callbackable::Callback>(&Leases::select_cb));
oss << "SELECT * FROM " << table << " WHERE oid = " << oid;
oss << "SELECT " << db_names << " FROM " << table << " WHERE oid = " << oid;
rc = db->exec(oss,this);

View File

@ -136,7 +136,7 @@ int RangedLeases::add(
int rc;
//Insert the lease in the database
oss << "INSERT INTO " << table << " "<< db_names <<" VALUES ("<<
oss << "INSERT INTO " << table << " ("<< db_names <<") VALUES ("<<
oid << "," <<
ip << "," <<
mac[Lease::PREFIX] << "," <<

View File

@ -70,7 +70,11 @@ VirtualNetwork::~VirtualNetwork()
const char * VirtualNetwork::table = "network_pool";
const char * VirtualNetwork::db_names =
"(oid,uid,name,type,bridge,public,template)";
"oid,uid,name,type,bridge,public,template";
const char * VirtualNetwork::extended_db_names =
"network_pool.oid, network_pool.uid, network_pool.name, network_pool.type, "
"network_pool.bridge, network_pool.public, network_pool.template";
const char * VirtualNetwork::db_bootstrap = "CREATE TABLE IF NOT EXISTS"
" network_pool ("
@ -130,7 +134,7 @@ int VirtualNetwork::select(SqlDB * db)
set_callback(
static_cast<Callbackable::Callback>(&VirtualNetwork::select_cb));
oss << "SELECT * FROM " << table << " WHERE oid = " << oid;
oss << "SELECT " << db_names << " FROM " << table << " WHERE oid = " << oid;
boid = oid;
oid = -1;
@ -492,7 +496,7 @@ int VirtualNetwork::insert_replace(SqlDB *db, bool replace)
oss << "INSERT";
}
oss << " INTO " << table << " "<< db_names <<" VALUES ("
oss << " INTO " << table << " (" << db_names << ") VALUES ("
<< oid << ","
<< uid << ","
<< "'" << sql_name << "',"

View File

@ -171,7 +171,7 @@ int VirtualNetworkPool::dump(ostringstream& oss, const string& where)
static_cast<Callbackable::Callback>(&VirtualNetworkPool::dump_cb),
static_cast<void *>(&oss));
cmd << "SELECT " << VirtualNetwork::table << ".*,COUNT("
cmd << "SELECT " << VirtualNetwork::extended_db_names << ",COUNT("
<< Leases::table << ".used), user_pool.user_name FROM "
<< VirtualNetwork::table
<< " LEFT OUTER JOIN " << Leases::table << " ON "