mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-22 13:33:52 +03:00
Merge branch 'feature-696' into feature-687 + Filter for all groups
Conflicts: include/RequestManagerPoolInfoFilter.h src/rm/RequestManagerPoolInfoFilter.cc
This commit is contained in:
commit
d74b69e4ce
@ -66,6 +66,14 @@ public:
|
||||
};
|
||||
|
||||
~VirtualMachineInfo(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
void to_xml(PoolObjectSQL * object, string& str)
|
||||
{
|
||||
VirtualMachine * vm = static_cast<VirtualMachine *>(object);
|
||||
vm->to_xml_extended(str);
|
||||
};
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
@ -31,9 +31,12 @@ class RequestManagerPoolInfoFilter: public Request
|
||||
{
|
||||
protected:
|
||||
RequestManagerPoolInfoFilter(const string& method_name,
|
||||
const string& help)
|
||||
:Request(method_name,"A:si",help)
|
||||
{};
|
||||
const string& help,
|
||||
const string& signature)
|
||||
:Request(method_name,signature,help)
|
||||
{
|
||||
auth_op = AuthRequest::INFO_POOL;
|
||||
};
|
||||
|
||||
~RequestManagerPoolInfoFilter(){};
|
||||
|
||||
@ -54,9 +57,17 @@ protected:
|
||||
class VirtualMachinePoolInfo : public RequestManagerPoolInfoFilter
|
||||
{
|
||||
public:
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
static const int ALL_VM; /**< VMs in any state (-2) */
|
||||
static const int NOT_DONE; /**< VMs in any state expect DONE (-1)*/
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
VirtualMachinePoolInfo():
|
||||
RequestManagerPoolInfoFilter("VirtualMachinePoolInfo",
|
||||
"Returns the virtual machine instances pool")
|
||||
"Returns the virtual machine instances pool",
|
||||
"A:siii")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_vmpool();
|
||||
@ -74,7 +85,8 @@ class TemplatePoolInfo : public RequestManagerPoolInfoFilter
|
||||
public:
|
||||
TemplatePoolInfo():
|
||||
RequestManagerPoolInfoFilter("TemplatePoolInfo",
|
||||
"Returns the virtual machine template pool")
|
||||
"Returns the virtual machine template pool",
|
||||
"A:siii")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_tpool();
|
||||
@ -87,13 +99,13 @@ public:
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
class VirtualNetworkPoolInfo: public RequestManagerPoolInfoFilter
|
||||
{
|
||||
public:
|
||||
VirtualNetworkPoolInfo():
|
||||
RequestManagerPoolInfoFilter("VirtualNetworkPoolInfo",
|
||||
"Returns the virtual network pool")
|
||||
"Returns the virtual network pool",
|
||||
"A:siii")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_vnpool();
|
||||
@ -111,7 +123,8 @@ class ImagePoolInfo: public RequestManagerPoolInfoFilter
|
||||
public:
|
||||
ImagePoolInfo():
|
||||
RequestManagerPoolInfoFilter("ImagePoolInfo",
|
||||
"Returns the image pool")
|
||||
"Returns the image pool",
|
||||
"A:siii")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_ipool();
|
||||
@ -121,7 +134,6 @@ public:
|
||||
~ImagePoolInfo(){};
|
||||
};
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -124,6 +124,14 @@ public:
|
||||
*/
|
||||
string& to_xml(string& xml) const;
|
||||
|
||||
/**
|
||||
* Function to print the VirtualMachine object into a string in
|
||||
* XML format, with extended information (full history records)
|
||||
* @param xml the resulting XML string
|
||||
* @return a reference to the generated string
|
||||
*/
|
||||
string& to_xml_extended(string& xml) const;
|
||||
|
||||
/**
|
||||
* Rebuilds the object from an xml formatted string
|
||||
* @param xml_str The xml-formatted string
|
||||
@ -752,6 +760,12 @@ private:
|
||||
*/
|
||||
History * previous_history;
|
||||
|
||||
|
||||
/**
|
||||
* Complete set of history records for the VM
|
||||
*/
|
||||
vector<History *> history_records;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Logging
|
||||
// -------------------------------------------------------------------------
|
||||
@ -859,6 +873,15 @@ private:
|
||||
*/
|
||||
void parse_graphics();
|
||||
|
||||
/**
|
||||
* Function that renders the VM in XML format optinally including
|
||||
* extended information (all history records)
|
||||
* @param xml the resulting XML string
|
||||
* @param extended include additional info if true
|
||||
* @return a reference to the generated string
|
||||
*/
|
||||
string& to_xml_extended(string& xml, bool extended) const;
|
||||
|
||||
protected:
|
||||
|
||||
//**************************************************************************
|
||||
|
@ -139,22 +139,9 @@ public:
|
||||
*/
|
||||
int dump(ostringstream& oss, const string& where)
|
||||
{
|
||||
return dump(oss, -1, where);
|
||||
return PoolSQL::dump(oss, "VM_POOL", VirtualMachine::table, 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 state include only VMs in this state. -1 means any state,
|
||||
* except DONE
|
||||
*
|
||||
* @return 0 on success
|
||||
*/
|
||||
int dump(ostringstream& oss, int state, const string& where);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Factory method to produce VM objects
|
||||
|
@ -47,9 +47,26 @@ module OpenNebula
|
||||
# XML-RPC Methods for the Image Object
|
||||
#######################################################################
|
||||
|
||||
# Retrieves all or part of the Images in the pool.
|
||||
def info()
|
||||
super(IMAGE_POOL_METHODS[:info],@user_id)
|
||||
# Retrieves all or part of the VirtualMachines in the pool.
|
||||
def info(*args)
|
||||
case args.size
|
||||
when 0
|
||||
info_filter(IMAGE_POOL_METHODS[:info],@user_id,-1,-1)
|
||||
when 3
|
||||
info_filter(IMAGE_POOL_METHODS[:info],args[0],args[1],args[2])
|
||||
end
|
||||
end
|
||||
|
||||
def info_all()
|
||||
return super(IMAGE_POOL_METHODS[:info])
|
||||
end
|
||||
|
||||
def info_mine()
|
||||
return super(IMAGE_POOL_METHODS[:info])
|
||||
end
|
||||
|
||||
def info_group()
|
||||
return super(IMAGE_POOL_METHODS[:info])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -22,7 +22,6 @@ module OpenNebula
|
||||
include Enumerable
|
||||
|
||||
protected
|
||||
|
||||
#pool:: _String_ XML name of the root element
|
||||
#element:: _String_ XML name of the Pool elements
|
||||
#client:: _Client_ represents a XML-RPC connection
|
||||
@ -48,13 +47,36 @@ module OpenNebula
|
||||
#######################################################################
|
||||
# Common XML-RPC Methods for all the Pool Types
|
||||
#######################################################################
|
||||
|
||||
#Gets the pool without any filter. Host, Group and User Pools
|
||||
# xml_method:: _String_ the name of the XML-RPC method
|
||||
def info(xml_method)
|
||||
return xmlrpc_info(xml_method)
|
||||
end
|
||||
|
||||
def info_all(xml_method)
|
||||
return xmlrpc_info(xml_method,INFO_ALL,-1,-1)
|
||||
end
|
||||
|
||||
def info_mine(xml_method)
|
||||
return xmlrpc_info(xml_method,INFO_MINE,-1,-1)
|
||||
end
|
||||
|
||||
def info_group(xml_method)
|
||||
return xmlrpc_info(xml_method,INFO_GROUP,-1,-1)
|
||||
end
|
||||
|
||||
def info_filter(xml_method, who, start_id, end_id)
|
||||
return xmlrpc_info(xml_method,who, start_id, end_id)
|
||||
end
|
||||
|
||||
private
|
||||
# Calls to the corresponding info method to retreive the pool
|
||||
# representation in XML format
|
||||
# xml_method:: _String_ the name of the XML-RPC method
|
||||
# args:: _Array_ with additional arguments for the info call
|
||||
# [return] nil in case of success or an Error object
|
||||
def info(xml_method,*args)
|
||||
def xmlrpc_info(xml_method,*args)
|
||||
rc = @client.call(xml_method,*args)
|
||||
|
||||
if !OpenNebula.is_error?(rc)
|
||||
@ -66,6 +88,10 @@ module OpenNebula
|
||||
end
|
||||
|
||||
public
|
||||
# Constants for info queries (include/RequestManagerPoolInfoFilter.h)
|
||||
INFO_GROUP = -1
|
||||
INFO_ALL = -2
|
||||
INFO_MINE = -3
|
||||
|
||||
# Iterates over every PoolElement in the Pool and calls the block with a
|
||||
# a PoolElement obtained calling the factory method
|
||||
|
@ -46,10 +46,26 @@ module OpenNebula
|
||||
# ---------------------------------------------------------------------
|
||||
# XML-RPC Methods for the Template Object
|
||||
# ---------------------------------------------------------------------
|
||||
# Retrieves all or part of the VirtualMachines in the pool.
|
||||
def info(*args)
|
||||
case args.size
|
||||
when 0
|
||||
info_filter(TEMPLATE_POOL_METHODS[:info],@user_id,-1,-1)
|
||||
when 3
|
||||
info_filter(TEMPLATE_POOL_METHODS[:info],args[0],args[1],args[2])
|
||||
end
|
||||
end
|
||||
|
||||
# Retrieves all the Templates in the pool.
|
||||
def info()
|
||||
super(TEMPLATE_POOL_METHODS[:info], @user_id)
|
||||
def info_all()
|
||||
return super(TEMPLATE_POOL_METHODS[:info])
|
||||
end
|
||||
|
||||
def info_mine()
|
||||
return super(TEMPLATE_POOL_METHODS[:info])
|
||||
end
|
||||
|
||||
def info_group()
|
||||
return super(TEMPLATE_POOL_METHODS[:info])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -26,6 +26,10 @@ module OpenNebula
|
||||
:info => "vmpool.info"
|
||||
}
|
||||
|
||||
# Constants for info queries (include/RequestManagerPoolInfoFilter.h)
|
||||
INFO_NOT_DONE = -1
|
||||
INFO_ALL_VM = -2
|
||||
|
||||
#######################################################################
|
||||
# Class constructor & Pool Methods
|
||||
#######################################################################
|
||||
@ -48,8 +52,54 @@ module OpenNebula
|
||||
#######################################################################
|
||||
|
||||
# Retrieves all or part of the VirtualMachines in the pool.
|
||||
def info()
|
||||
super(VM_POOL_METHODS[:info],@user_id)
|
||||
# No arguments, returns the not-in-done VMs for the user
|
||||
# [user_id, start_id, end_id]
|
||||
# [user_id, start_id, end_id, state]
|
||||
def info(*args)
|
||||
case args.size
|
||||
when 0
|
||||
info_filter(VM_POOL_METHODS[:info],
|
||||
@user_id,
|
||||
-1,
|
||||
-1,
|
||||
INFO_NOT_DONE)
|
||||
when 3
|
||||
info_filter(VM_POOL_METHODS[:info],
|
||||
args[0],
|
||||
args[1],
|
||||
args[2],
|
||||
INFO_NOT_DONE)
|
||||
when 4
|
||||
info_filter(VM_POOL_METHODS[:info],
|
||||
args[0],
|
||||
args[1],
|
||||
args[2],
|
||||
args[3])
|
||||
end
|
||||
end
|
||||
|
||||
def info_all()
|
||||
return info_filter(VM_POOL_METHODS[:info],
|
||||
INFO_ALL,
|
||||
-1,
|
||||
-1,
|
||||
INFO_NOT_DONE)
|
||||
end
|
||||
|
||||
def info_mine()
|
||||
return info_filter(VM_POOL_METHODS[:info],
|
||||
INFO_MINE,
|
||||
-1,
|
||||
-1,
|
||||
INFO_NOT_DONE)
|
||||
end
|
||||
|
||||
def info_group()
|
||||
return info_filter(VM_POOL_METHODS[:info],
|
||||
INFO_GROUP,
|
||||
-1,
|
||||
-1,
|
||||
INFO_NOT_DONE)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -47,9 +47,26 @@ module OpenNebula
|
||||
# XML-RPC Methods for the Virtual Network Object
|
||||
#######################################################################
|
||||
|
||||
# Retrieves all or part of the VirtualNetwork in the pool.
|
||||
def info()
|
||||
super(VN_POOL_METHODS[:info],@user_id)
|
||||
# Retrieves all or part of the VirtualMachines in the pool.
|
||||
def info(*args)
|
||||
case args.size
|
||||
when 0
|
||||
info_filter(VN_POOL_METHODS[:info],@user_id,-1,-1)
|
||||
when 3
|
||||
info_filter(VN_POOL_METHODS[:info],args[0],args[1],args[2])
|
||||
end
|
||||
end
|
||||
|
||||
def info_all()
|
||||
return super(VN_POOL_METHODS[:info])
|
||||
end
|
||||
|
||||
def info_mine()
|
||||
return super(VN_POOL_METHODS[:info])
|
||||
end
|
||||
|
||||
def info_group()
|
||||
return super(VN_POOL_METHODS[:info])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,4 +1,5 @@
|
||||
$: << '../'
|
||||
$: << '../' \
|
||||
<< './'
|
||||
|
||||
require 'OpenNebula'
|
||||
require 'helpers/MockClient'
|
||||
@ -78,4 +79,4 @@ module OpenNebula
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,4 +1,5 @@
|
||||
$: << '../'
|
||||
$: << '../' \
|
||||
<< './'
|
||||
|
||||
require 'OpenNebula'
|
||||
require 'helpers/MockClient'
|
||||
@ -216,4 +217,4 @@ module OpenNebula
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -1,4 +1,5 @@
|
||||
$: << '../'
|
||||
$: << '../' \
|
||||
<< './'
|
||||
|
||||
require 'OpenNebula'
|
||||
require 'helpers/MockClient'
|
||||
@ -62,4 +63,4 @@ module OpenNebula
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,4 +1,5 @@
|
||||
$: << '../'
|
||||
$: << '../' \
|
||||
<< './'
|
||||
|
||||
require 'OpenNebula'
|
||||
require 'helpers/MockClient'
|
||||
@ -142,4 +143,4 @@ module OpenNebula
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -1,4 +1,5 @@
|
||||
$: << '../'
|
||||
$: << '../' \
|
||||
<< './'
|
||||
|
||||
require 'OpenNebula'
|
||||
require 'helpers/MockClient'
|
||||
@ -114,4 +115,4 @@ module OpenNebula
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,4 +1,5 @@
|
||||
$: << '../'
|
||||
$: << '../' \
|
||||
<< './'
|
||||
|
||||
require 'OpenNebula'
|
||||
require 'helpers/MockClient'
|
||||
@ -469,4 +470,4 @@ module OpenNebula
|
||||
@vm.name.should eql(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,4 +1,5 @@
|
||||
$: << '../'
|
||||
$: << '../' \
|
||||
<< './'
|
||||
|
||||
require 'OpenNebula'
|
||||
require 'helpers/MockClient'
|
||||
@ -84,4 +85,4 @@ module OpenNebula
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,4 +1,5 @@
|
||||
$: << '../'
|
||||
$: << '../' \
|
||||
<< './'
|
||||
|
||||
require 'OpenNebula'
|
||||
require 'helpers/MockClient'
|
||||
@ -152,4 +153,4 @@ module OpenNebula
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -27,51 +27,164 @@ const int RequestManagerPoolInfoFilter::MINE = -3;
|
||||
|
||||
const int RequestManagerPoolInfoFilter::MINE_GROUP = -1;
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
const int VirtualMachinePoolInfo::ALL_VM = -2;
|
||||
|
||||
const int VirtualMachinePoolInfo::NOT_DONE = -1;
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
void RequestManagerPoolInfoFilter::request_execute(xmlrpc_c::paramList const& paramList)
|
||||
{
|
||||
int filter_flag = xmlrpc_c::value_int(paramList.getInt(1));
|
||||
int start_id = xmlrpc_c::value_int(paramList.getInt(2));
|
||||
int end_id = xmlrpc_c::value_int(paramList.getInt(3));
|
||||
|
||||
ostringstream oss, where_string;
|
||||
set<int>::iterator it;
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
bool empty = true;
|
||||
ostringstream where_string;
|
||||
|
||||
ostringstream uid_filter;
|
||||
ostringstream state_filter;
|
||||
ostringstream id_filter;
|
||||
|
||||
string uid_str;
|
||||
string state_str;
|
||||
string id_str;
|
||||
|
||||
int rc;
|
||||
|
||||
AuthRequest::Operation request_op = AuthRequest::INFO_POOL;
|
||||
// ------------------------------------------
|
||||
// User ID filter
|
||||
// ------------------------------------------
|
||||
|
||||
if ( filter_flag < MINE )
|
||||
{
|
||||
failure_response(XML_RPC_API, request_error("Incorrect filter_flag",""));
|
||||
failure_response(XML_RPC_API,request_error("Incorrect filter_flag",""));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
switch(filter_flag)
|
||||
{
|
||||
case MINE:
|
||||
where_string << "UID=" << uid;
|
||||
request_op = AuthRequest::INFO_POOL_MINE;
|
||||
uid_filter << "uid = " << uid;
|
||||
|
||||
auth_op = AuthRequest::INFO_POOL_MINE;
|
||||
break;
|
||||
|
||||
case ALL:
|
||||
break;
|
||||
|
||||
case MINE_GROUP:
|
||||
where_string << "UID=" << uid << " OR GID=" << gid;
|
||||
request_op = AuthRequest::INFO_POOL_MINE;
|
||||
|
||||
uid_filter << "uid = " << uid << " OR gid = " << gid;
|
||||
|
||||
for ( it = group_ids.begin() ; it != group_ids.end(); it++ )
|
||||
{
|
||||
where_string << " OR gid = " << *it;
|
||||
}
|
||||
|
||||
auth_op = AuthRequest::INFO_POOL_MINE;
|
||||
break;
|
||||
|
||||
default:
|
||||
where_string << "UID=" << filter_flag;
|
||||
uid_filter << "uid = " << filter_flag;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( basic_authorization(-1, request_op) == false )
|
||||
uid_str = uid_filter.str();
|
||||
|
||||
|
||||
// ------------------------------------------
|
||||
// Resource ID filter
|
||||
// ------------------------------------------
|
||||
|
||||
if ( start_id != -1 )
|
||||
{
|
||||
id_filter << "oid >= " << start_id;
|
||||
|
||||
if ( end_id != -1 )
|
||||
{
|
||||
id_filter << " AND oid <= " << end_id;
|
||||
}
|
||||
}
|
||||
|
||||
id_str = id_filter.str();
|
||||
|
||||
// ------------ State filter for VM --------------
|
||||
if ( auth_object == AuthRequest::VM )
|
||||
{
|
||||
int state = xmlrpc_c::value_int(paramList.getInt(4));
|
||||
|
||||
if (( state < MINE ) || ( state > VirtualMachine::FAILED ))
|
||||
{
|
||||
failure_response(XML_RPC_API,
|
||||
request_error("Incorrect filter_flag, state",""));
|
||||
return;
|
||||
}
|
||||
|
||||
switch(state)
|
||||
{
|
||||
case VirtualMachinePoolInfo::ALL_VM:
|
||||
break;
|
||||
|
||||
case VirtualMachinePoolInfo::NOT_DONE:
|
||||
state_filter << "state <> " << VirtualMachine::DONE;
|
||||
break;
|
||||
|
||||
default:
|
||||
state_filter << "state = " << state;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
state_str = state_filter.str();
|
||||
|
||||
// ------------------------------------------
|
||||
// Compound WHERE clause
|
||||
// ------------------------------------------
|
||||
|
||||
if (!uid_str.empty())
|
||||
{
|
||||
where_string << "(" << uid_str << ")" ;
|
||||
empty = false;
|
||||
}
|
||||
|
||||
if (!id_str.empty())
|
||||
{
|
||||
if (!empty)
|
||||
{
|
||||
where_string << " AND ";
|
||||
}
|
||||
|
||||
where_string << "(" << id_str << ")";
|
||||
empty = false;
|
||||
}
|
||||
|
||||
if (!state_str.empty())
|
||||
{
|
||||
if (!empty)
|
||||
{
|
||||
where_string << " AND ";
|
||||
}
|
||||
|
||||
where_string << "(" << state_str << ")";
|
||||
}
|
||||
|
||||
// ------------------------------------------
|
||||
// Authorize & get the pool
|
||||
// ------------------------------------------
|
||||
|
||||
if ( basic_authorization(-1) == false )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Call the template pool dump
|
||||
|
||||
rc = pool->dump(oss,where_string.str());
|
||||
|
||||
if ( rc != 0 )
|
||||
|
@ -70,14 +70,9 @@ VirtualMachine::VirtualMachine(int id,
|
||||
|
||||
VirtualMachine::~VirtualMachine()
|
||||
{
|
||||
if ( history != 0 )
|
||||
for (unsigned int i=0 ; i < history_records.size() ; i++)
|
||||
{
|
||||
delete history;
|
||||
}
|
||||
|
||||
if ( previous_history != 0 )
|
||||
{
|
||||
delete previous_history;
|
||||
delete history_records[i];
|
||||
}
|
||||
|
||||
if ( _log != 0 )
|
||||
@ -128,18 +123,26 @@ int VirtualMachine::select(SqlDB * db)
|
||||
//Get History Records. Current history is built in from_xml() (if any).
|
||||
if( hasHistory() )
|
||||
{
|
||||
last_seq = history->seq;
|
||||
last_seq = history->seq - 1;
|
||||
|
||||
if ( last_seq > 0 )
|
||||
for (int i = last_seq; i >= 0; i--)
|
||||
{
|
||||
previous_history = new History(oid, last_seq - 1);
|
||||
History * hp;
|
||||
|
||||
rc = previous_history->select(db);
|
||||
hp = new History(oid, i);
|
||||
rc = hp->select(db);
|
||||
|
||||
if ( rc != 0)
|
||||
{
|
||||
goto error_previous_history;
|
||||
}
|
||||
|
||||
history_records[i] = hp;
|
||||
|
||||
if ( i == last_seq )
|
||||
{
|
||||
previous_history = hp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -168,6 +171,7 @@ int VirtualMachine::select(SqlDB * db)
|
||||
error_previous_history:
|
||||
ose << "Can not get previous history record (seq:" << history->seq
|
||||
<< ") for VM id: " << oid;
|
||||
|
||||
log("ONE", Log::ERROR, ose);
|
||||
return -1;
|
||||
}
|
||||
@ -560,15 +564,12 @@ void VirtualMachine::add_history(
|
||||
{
|
||||
seq = history->seq + 1;
|
||||
|
||||
if (previous_history != 0)
|
||||
{
|
||||
delete previous_history;
|
||||
}
|
||||
|
||||
previous_history = history;
|
||||
}
|
||||
|
||||
history = new History(oid,seq,hid,hostname,vm_dir,vmm_mad,tm_mad);
|
||||
|
||||
history_records.push_back(history);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -584,21 +585,18 @@ void VirtualMachine::cp_history()
|
||||
}
|
||||
|
||||
htmp = new History(oid,
|
||||
history->seq + 1,
|
||||
history->hid,
|
||||
history->hostname,
|
||||
history->vm_dir,
|
||||
history->vmm_mad_name,
|
||||
history->tm_mad_name);
|
||||
history->seq + 1,
|
||||
history->hid,
|
||||
history->hostname,
|
||||
history->vm_dir,
|
||||
history->vmm_mad_name,
|
||||
history->tm_mad_name);
|
||||
|
||||
if ( previous_history != 0 )
|
||||
{
|
||||
delete previous_history;
|
||||
}
|
||||
|
||||
previous_history = history;
|
||||
history = htmp;
|
||||
|
||||
history = htmp;
|
||||
history_records.push_back(history);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -614,18 +612,17 @@ void VirtualMachine::cp_previous_history()
|
||||
}
|
||||
|
||||
htmp = new History(oid,
|
||||
history->seq + 1,
|
||||
previous_history->hid,
|
||||
previous_history->hostname,
|
||||
previous_history->vm_dir,
|
||||
previous_history->vmm_mad_name,
|
||||
previous_history->tm_mad_name);
|
||||
|
||||
delete previous_history;
|
||||
history->seq + 1,
|
||||
previous_history->hid,
|
||||
previous_history->hostname,
|
||||
previous_history->vm_dir,
|
||||
previous_history->vmm_mad_name,
|
||||
previous_history->tm_mad_name);
|
||||
|
||||
previous_history = history;
|
||||
history = htmp;
|
||||
|
||||
history = htmp;
|
||||
history_records.push_back(history);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -1139,11 +1136,26 @@ error_yy:
|
||||
pthread_mutex_unlock(&lex_mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
string& VirtualMachine::to_xml(string& xml) const
|
||||
{
|
||||
return to_xml_extended(xml,false);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
string& VirtualMachine::to_xml_extended(string& xml) const
|
||||
{
|
||||
return to_xml_extended(xml,true);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
string& VirtualMachine::to_xml_extended(string& xml, bool extended) const
|
||||
{
|
||||
|
||||
string template_xml;
|
||||
@ -1172,7 +1184,21 @@ string& VirtualMachine::to_xml(string& xml) const
|
||||
|
||||
if ( hasHistory() )
|
||||
{
|
||||
oss << history->to_xml(history_xml);
|
||||
oss << "<HISTORY_RECORDS>";
|
||||
|
||||
if ( extended )
|
||||
{
|
||||
for (unsigned int i=0; i < history_records.size(); i++)
|
||||
{
|
||||
oss << history_records[i]->to_xml(history_xml);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
oss << history->to_xml(history_xml);
|
||||
}
|
||||
|
||||
oss << "</HISTORY_RECORDS>";
|
||||
}
|
||||
|
||||
oss << "</VM>";
|
||||
@ -1235,12 +1261,15 @@ int VirtualMachine::from_xml(const string &xml_str)
|
||||
|
||||
// Last history entry
|
||||
content.clear();
|
||||
ObjectXML::get_nodes("/VM/HISTORY", content);
|
||||
ObjectXML::get_nodes("/VM/HISTORY_RECORDS/HISTORY", content);
|
||||
|
||||
if( !content.empty() )
|
||||
{
|
||||
history = new History(oid);
|
||||
rc += history->from_xml_node(content[0]);
|
||||
|
||||
history_records.resize(history->seq + 1);
|
||||
history_records[history->seq] = history;
|
||||
}
|
||||
|
||||
if (rc != 0)
|
||||
|
@ -250,29 +250,3 @@ int VirtualMachinePool::get_pending(
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualMachinePool::dump( ostringstream& oss,
|
||||
int state,
|
||||
const string& where)
|
||||
{
|
||||
ostringstream where_oss;
|
||||
|
||||
if ( state != -1 )
|
||||
{
|
||||
where_oss << VirtualMachine::table << ".state = " << state;
|
||||
}
|
||||
else
|
||||
{
|
||||
where_oss << VirtualMachine::table << ".state <> 6";
|
||||
}
|
||||
|
||||
if ( !where.empty() )
|
||||
{
|
||||
where_oss << " AND " << where;
|
||||
}
|
||||
|
||||
return PoolSQL::dump(oss, "VM_POOL", VirtualMachine::table,where_oss.str());
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -76,8 +76,7 @@ const string xml_dump_where =
|
||||
"<VM_POOL><VM><ID>0</ID><UID>1</UID><GID>1</GID><NAME>VM one</NAME><LAST_POLL>0</LAST_POLL><STATE>1</STATE><LCM_STATE>0</LCM_STATE><STIME>0000000000</STIME><ETIME>0</ETIME><DEPLOY_ID></DEPLOY_ID><MEMORY>0</MEMORY><CPU>0</CPU><NET_TX>0</NET_TX><NET_RX>0</NET_RX><TEMPLATE><CPU><![CDATA[1]]></CPU><MEMORY><![CDATA[128]]></MEMORY><NAME><![CDATA[VM one]]></NAME><VMID><![CDATA[0]]></VMID></TEMPLATE></VM></VM_POOL>";
|
||||
|
||||
const string xml_history_dump =
|
||||
"<VM_POOL><VM><ID>0</ID><UID>0</UID><GID>1</GID><NAME>VM one</NAME><LAST_POLL>0</LAST_POLL><STATE>1</STATE><LCM_STATE>0</LCM_STATE><STIME>0000000000</STIME><ETIME>0</ETIME><DEPLOY_ID></DEPLOY_ID><MEMORY>0</MEMORY><CPU>0</CPU><NET_TX>0</NET_TX><NET_RX>0</NET_RX><TEMPLATE><CPU><![CDATA[1]]></CPU><MEMORY><![CDATA[128]]></MEMORY><NAME><![CDATA[VM one]]></NAME><VMID><![CDATA[0]]></VMID></TEMPLATE></VM><VM><ID>1</ID><UID>0</UID><GID>1</GID><NAME>Second VM</NAME><LAST_POLL>0</LAST_POLL><STATE>2</STATE><LCM_STATE>0</LCM_STATE><STIME>0000000000</STIME><ETIME>0</ETIME><DEPLOY_ID></DEPLOY_ID><MEMORY>0</MEMORY><CPU>0</CPU><NET_TX>0</NET_TX><NET_RX>0</NET_RX><TEMPLATE><CPU><![CDATA[2]]></CPU><MEMORY><![CDATA[256]]></MEMORY><NAME><![CDATA[Second VM]]></NAME><VMID><![CDATA[1]]></VMID></TEMPLATE><HISTORY><SEQ>0</SEQ><HOSTNAME>A_hostname</HOSTNAME><VM_DIR>A_vm_dir</VM_DIR><HID>0</HID><STIME>0</STIME><ETIME>0</ETIME><VMMMAD>A_vmm_mad</VMMMAD><TMMAD>A_tm_mad</TMMAD><PSTIME>0</PSTIME><PETIME>0</PETIME><RSTIME>0</RSTIME><RETIME>0</RETIME><ESTIME>0</ESTIME><EETIME>0</EETIME><REASON>0</REASON></HISTORY></VM><VM><ID>2</ID><UID>0</UID><GID>1</GID><NAME>VM one</NAME><LAST_POLL>0</LAST_POLL><STATE>2</STATE><LCM_STATE>0</LCM_STATE><STIME>0000000000</STIME><ETIME>0</ETIME><DEPLOY_ID></DEPLOY_ID><MEMORY>0</MEMORY><CPU>0</CPU><NET_TX>0</NET_TX><NET_RX>0</NET_RX><TEMPLATE><CPU><![CDATA[1]]></CPU><MEMORY><![CDATA[1024]]></MEMORY><NAME><![CDATA[VM one]]></NAME><VMID><![CDATA[2]]></VMID></TEMPLATE><HISTORY><SEQ>1</SEQ><HOSTNAME>C_hostname</HOSTNAME><VM_DIR>C_vm_dir</VM_DIR><HID>2</HID><STIME>0</STIME><ETIME>0</ETIME><VMMMAD>C_vmm_mad</VMMMAD><TMMAD>C_tm_mad</TMMAD><PSTIME>0</PSTIME><PETIME>0</PETIME><RSTIME>0</RSTIME><RETIME>0</RETIME><ESTIME>0</ESTIME><EETIME>0</EETIME><REASON>0</REASON></HISTORY></VM></VM_POOL>";
|
||||
|
||||
"<VM_POOL><VM><ID>0</ID><UID>0</UID><GID>1</GID><NAME>VM one</NAME><LAST_POLL>0</LAST_POLL><STATE>1</STATE><LCM_STATE>0</LCM_STATE><STIME>0000000000</STIME><ETIME>0</ETIME><DEPLOY_ID></DEPLOY_ID><MEMORY>0</MEMORY><CPU>0</CPU><NET_TX>0</NET_TX><NET_RX>0</NET_RX><TEMPLATE><CPU><![CDATA[1]]></CPU><MEMORY><![CDATA[128]]></MEMORY><NAME><![CDATA[VM one]]></NAME><VMID><![CDATA[0]]></VMID></TEMPLATE></VM><VM><ID>1</ID><UID>0</UID><GID>1</GID><NAME>Second VM</NAME><LAST_POLL>0</LAST_POLL><STATE>2</STATE><LCM_STATE>0</LCM_STATE><STIME>0000000000</STIME><ETIME>0</ETIME><DEPLOY_ID></DEPLOY_ID><MEMORY>0</MEMORY><CPU>0</CPU><NET_TX>0</NET_TX><NET_RX>0</NET_RX><TEMPLATE><CPU><![CDATA[2]]></CPU><MEMORY><![CDATA[256]]></MEMORY><NAME><![CDATA[Second VM]]></NAME><VMID><![CDATA[1]]></VMID></TEMPLATE><HISTORY_RECORDS><HISTORY><SEQ>0</SEQ><HOSTNAME>A_hostname</HOSTNAME><VM_DIR>A_vm_dir</VM_DIR><HID>0</HID><STIME>0</STIME><ETIME>0</ETIME><VMMMAD>A_vmm_mad</VMMMAD><TMMAD>A_tm_mad</TMMAD><PSTIME>0</PSTIME><PETIME>0</PETIME><RSTIME>0</RSTIME><RETIME>0</RETIME><ESTIME>0</ESTIME><EETIME>0</EETIME><REASON>0</REASON></HISTORY></HISTORY_RECORDS></VM><VM><ID>2</ID><UID>0</UID><GID>1</GID><NAME>VM one</NAME><LAST_POLL>0</LAST_POLL><STATE>2</STATE><LCM_STATE>0</LCM_STATE><STIME>0000000000</STIME><ETIME>0</ETIME><DEPLOY_ID></DEPLOY_ID><MEMORY>0</MEMORY><CPU>0</CPU><NET_TX>0</NET_TX><NET_RX>0</NET_RX><TEMPLATE><CPU><![CDATA[1]]></CPU><MEMORY><![CDATA[1024]]></MEMORY><NAME><![CDATA[VM one]]></NAME><VMID><![CDATA[2]]></VMID></TEMPLATE><HISTORY_RECORDS><HISTORY><SEQ>1</SEQ><HOSTNAME>C_hostname</HOSTNAME><VM_DIR>C_vm_dir</VM_DIR><HID>2</HID><STIME>0</STIME><ETIME>0</ETIME><VMMMAD>C_vmm_mad</VMMMAD><TMMAD>C_tm_mad</TMMAD><PSTIME>0</PSTIME><PETIME>0</PETIME><RSTIME>0</RSTIME><RETIME>0</RETIME><ESTIME>0</ESTIME><EETIME>0</EETIME><REASON>0</REASON></HISTORY></HISTORY_RECORDS></VM></VM_POOL>";
|
||||
|
||||
/* ************************************************************************* */
|
||||
/* ************************************************************************* */
|
||||
|
Loading…
Reference in New Issue
Block a user