mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-30 22:50:10 +03:00
one.vmpool.info xml-rpc method now has 2 more parameters
The method keeps compatibility, and can be called with 2 or 4 parameters It now returns the the extended info upon request, reading only the vm_pool table in the DB if the Histoy and username are not needed The last parameter allows filtering by VM status
This commit is contained in:
parent
f59095c6d5
commit
90a58ce066
@ -478,7 +478,7 @@ private:
|
||||
vmpool(_vmpool),
|
||||
upool(_upool)
|
||||
{
|
||||
_signature="A:si";
|
||||
_signature="A:sibi";
|
||||
_help="Returns the virtual machine pool";
|
||||
};
|
||||
|
||||
|
@ -1057,6 +1057,18 @@ protected:
|
||||
* @return 0 on success
|
||||
*/
|
||||
static int dump(ostringstream& oss, int num, char ** values, char ** names);
|
||||
|
||||
/**
|
||||
* Dumps the contect of a set of VirtualMachine objects in the given stream
|
||||
* using XML format
|
||||
* @param oss the output stream
|
||||
* @param num the number of columns read from the DB
|
||||
* @param names the column names
|
||||
* @param vaues the column values
|
||||
* @return 0 on success
|
||||
*/
|
||||
static int dump_extended( ostringstream& oss,
|
||||
int num, char ** values, char ** names);
|
||||
};
|
||||
|
||||
#endif /*VIRTUAL_MACHINE_H_*/
|
||||
|
@ -132,7 +132,24 @@ public:
|
||||
*
|
||||
* @return 0 on success
|
||||
*/
|
||||
int dump(ostringstream& oss, const string& where);
|
||||
int dump(ostringstream& oss, const string& where)
|
||||
{
|
||||
return dump(oss, true, -1, where);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps the VM pool in XML format. A filter can be also added to the query
|
||||
* Also the hostname where the VirtualMachine is running is added to the
|
||||
* pool
|
||||
* @param oss the output stream to dump the pool contents
|
||||
* @param where filter for the objects, defaults to all
|
||||
* @param extended condition to include history and username data
|
||||
* @param state include only VMs in this state. -1 means any state,
|
||||
* except DONE
|
||||
*
|
||||
* @return 0 on success
|
||||
*/
|
||||
int dump(ostringstream& oss, bool extended, int state, const string& where);
|
||||
|
||||
private:
|
||||
/**
|
||||
@ -153,6 +170,17 @@ private:
|
||||
* @return 0 on success
|
||||
*/
|
||||
int dump_cb(void * _oss, int num, char **values, char **names);
|
||||
|
||||
/**
|
||||
* Callback function to get output the vm pool in XML format
|
||||
* (VirtualMachinePool::dump)
|
||||
* @param num the number of columns read from the DB
|
||||
* @param names the column names
|
||||
* @param vaues the column values
|
||||
* @return 0 on success
|
||||
*/
|
||||
int dump_extended_cb(void * _oss, int num, char **values, char **names);
|
||||
|
||||
};
|
||||
|
||||
#endif /*VIRTUAL_MACHINE_POOL_H_*/
|
||||
|
@ -30,6 +30,9 @@ void RequestManager::VirtualMachinePoolInfo::execute(
|
||||
|
||||
int filter_flag;
|
||||
int rc;
|
||||
int state;
|
||||
|
||||
bool extended;
|
||||
|
||||
ostringstream oss;
|
||||
ostringstream where_string;
|
||||
@ -37,11 +40,25 @@ void RequestManager::VirtualMachinePoolInfo::execute(
|
||||
/* -- RPC specific vars -- */
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
|
||||
const string method_name = "VirtualMachinePoolInfo";
|
||||
|
||||
NebulaLog::log("ReM",Log::DEBUG,"VirtualMachinePoolInfo method invoked");
|
||||
|
||||
switch (paramList.size())
|
||||
{
|
||||
case 2:
|
||||
extended = true;
|
||||
state = -1;
|
||||
break;
|
||||
case 4:
|
||||
extended = xmlrpc_c::value_boolean(paramList.getBoolean(2));
|
||||
state = xmlrpc_c::value_int (paramList.getInt(3));
|
||||
break;
|
||||
default:
|
||||
paramList.verifyEnd(4);
|
||||
}
|
||||
|
||||
// Get the parameters
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
filter_flag = xmlrpc_c::value_int (paramList.getInt(1));
|
||||
@ -68,7 +85,7 @@ void RequestManager::VirtualMachinePoolInfo::execute(
|
||||
where_string << "UID=" << filter_flag;
|
||||
}
|
||||
|
||||
rc = VirtualMachinePoolInfo::vmpool->dump(oss,where_string.str());
|
||||
rc = VirtualMachinePoolInfo::vmpool->dump(oss, extended, state, where_string.str());
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
@ -109,4 +126,4 @@ error_common:
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -634,7 +634,60 @@ error_deploy:
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualMachine::dump(ostringstream& oss,int num,char **values,char **names)
|
||||
int VirtualMachine::dump( ostringstream& oss,
|
||||
int num,
|
||||
char **values,
|
||||
char **names)
|
||||
{
|
||||
if ((!values[OID])||
|
||||
(!values[UID])||
|
||||
(!values[NAME]) ||
|
||||
(!values[LAST_POLL])||
|
||||
(!values[STATE])||
|
||||
(!values[LCM_STATE])||
|
||||
(!values[STIME])||
|
||||
(!values[ETIME])||
|
||||
(!values[DEPLOY_ID])||
|
||||
(!values[MEMORY])||
|
||||
(!values[CPU])||
|
||||
(!values[NET_TX])||
|
||||
(!values[NET_RX])||
|
||||
(!values[LAST_SEQ])||
|
||||
(!values[TEMPLATE])||
|
||||
(num != LIMIT))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
oss <<
|
||||
"<VM>" <<
|
||||
"<ID>" << values[OID] << "</ID>" <<
|
||||
"<UID>" << values[UID] << "</UID>" <<
|
||||
"<NAME>" << values[NAME] << "</NAME>" <<
|
||||
"<LAST_POLL>"<< values[LAST_POLL]<< "</LAST_POLL>"<<
|
||||
"<STATE>" << values[STATE] << "</STATE>" <<
|
||||
"<LCM_STATE>"<< values[LCM_STATE]<< "</LCM_STATE>"<<
|
||||
"<STIME>" << values[STIME] << "</STIME>" <<
|
||||
"<ETIME>" << values[ETIME] << "</ETIME>" <<
|
||||
"<DEPLOY_ID>"<< values[DEPLOY_ID]<< "</DEPLOY_ID>"<<
|
||||
"<MEMORY>" << values[MEMORY] << "</MEMORY>" <<
|
||||
"<CPU>" << values[CPU] << "</CPU>" <<
|
||||
"<NET_TX>" << values[NET_TX] << "</NET_TX>" <<
|
||||
"<NET_RX>" << values[NET_RX] << "</NET_RX>" <<
|
||||
"<LAST_SEQ>" << values[LAST_SEQ] << "</LAST_SEQ>" <<
|
||||
values[TEMPLATE];
|
||||
oss << "</VM>";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualMachine::dump_extended( ostringstream& oss,
|
||||
int num,
|
||||
char **values,
|
||||
char **names)
|
||||
{
|
||||
if ((!values[OID])||
|
||||
(!values[UID])||
|
||||
|
@ -239,27 +239,63 @@ int VirtualMachinePool::dump_cb(void * _oss,int num,char **values,char **names)
|
||||
return VirtualMachine::dump(*oss, num, values, names);
|
||||
}
|
||||
|
||||
int VirtualMachinePool::dump_extended_cb(
|
||||
void * _oss,int num,char **values,char **names)
|
||||
{
|
||||
ostringstream * oss;
|
||||
|
||||
oss = static_cast<ostringstream *>(_oss);
|
||||
|
||||
return VirtualMachine::dump_extended(*oss, num, values, names);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualMachinePool::dump(ostringstream& oss, const string& where)
|
||||
int VirtualMachinePool::dump( ostringstream& oss,
|
||||
bool extended,
|
||||
int state,
|
||||
const string& where)
|
||||
{
|
||||
int rc;
|
||||
ostringstream cmd;
|
||||
|
||||
oss << "<VM_POOL>";
|
||||
|
||||
set_callback(
|
||||
static_cast<Callbackable::Callback>(&VirtualMachinePool::dump_cb),
|
||||
static_cast<void *>(&oss));
|
||||
if(extended)
|
||||
{
|
||||
set_callback(
|
||||
static_cast<Callbackable::Callback>(
|
||||
&VirtualMachinePool::dump_extended_cb),
|
||||
static_cast<void *>(&oss));
|
||||
|
||||
cmd << "SELECT " << VirtualMachine::table << ".*, user_pool.user_name, "
|
||||
|
||||
cmd << "SELECT " << VirtualMachine::table << ".*, user_pool.user_name, "
|
||||
<< History::table << ".* 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"
|
||||
<< " WHERE " << VirtualMachine::table << ".state <> 6";
|
||||
<< "AS user_pool ON " << VirtualMachine::table << ".uid = user_pool.oid";
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
set_callback(
|
||||
static_cast<Callbackable::Callback>(&VirtualMachinePool::dump_cb),
|
||||
static_cast<void *>(&oss));
|
||||
|
||||
cmd << "SELECT * FROM " << VirtualMachine::table;
|
||||
}
|
||||
|
||||
if ( state != -1 )
|
||||
{
|
||||
cmd << " WHERE " << VirtualMachine::table << ".state = " << state;
|
||||
}
|
||||
else
|
||||
{
|
||||
cmd << " WHERE " << VirtualMachine::table << ".state <> 6";
|
||||
}
|
||||
|
||||
if ( !where.empty() )
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user