1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-11 04:58:16 +03:00

F #3076: create one.vmpool.infoextended

* Add new function dump_extended
    * Add new API call one.vmpool.infoextended (ruby, JAVA, golang)
    * Add parameter --extended in the CLI for onevm

Co-authored-by: Alejandro Huertas <ahuertas@opennebula.systems>
This commit is contained in:
Ruben S. Montero 2019-03-29 12:43:59 +01:00
parent 01209ed63f
commit 2ed170be68
No known key found for this signature in database
GPG Key ID: A0CEA6FA880A1D87
11 changed files with 243 additions and 73 deletions

View File

@ -197,10 +197,27 @@ public:
*
* @return 0 on success
*/
virtual int dump(string& oss, const string& where,
const string& limit, bool desc) = 0;
/**
* Dumps the pool in extended XML format
* A filter and limit can be also added to the query
* @param oss the output stream to dump the pool contents
* @param where filter for the objects, defaults to all
* @param limit parameters used for pagination
* @param desc descending order of pool elements
*
* @return 0 on success
*/
virtual int dump_extended(string& oss,
const string& where,
const string& limit,
bool desc)
{
return dump(oss, where, limit, desc);
}
// -------------------------------------------------------------------------
// Function to generate dump filters
// -------------------------------------------------------------------------

View File

@ -59,12 +59,18 @@ public:
string& where_str);
protected:
/*
* True to gather full info
*/
bool extended;
RequestManagerPoolInfoFilter(const string& method_name,
const string& help,
const string& signature)
:Request(method_name,signature,help)
{
leader_only = false;
extended = false;
};
~RequestManagerPoolInfoFilter(){};
@ -120,6 +126,17 @@ public:
auth_object = PoolObjectSQL::VM;
};
VirtualMachinePoolInfo(const string& method_name,
const string& help,
const string& signature)
:RequestManagerPoolInfoFilter(method_name, help, signature)
{
Nebula& nd = Nebula::instance();
pool = nd.get_vmpool();
auth_object = PoolObjectSQL::VM;
};
~VirtualMachinePoolInfo(){};
/* -------------------------------------------------------------------- */
@ -131,6 +148,24 @@ public:
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class VirtualMachinePoolInfoExtended : public VirtualMachinePoolInfo
{
public:
VirtualMachinePoolInfoExtended():
VirtualMachinePoolInfo("one.vmpool.infoextended",
"Returns the virtual machine instances pool in extended format",
"A:siiiis")
{
extended = true;
};
~VirtualMachinePoolInfoExtended(){};
};
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class VirtualMachinePoolAccounting : public RequestManagerPoolInfoFilter
{
public:

View File

@ -288,6 +288,25 @@ public:
limit, desc);
};
/**
* Dumps the VM pool in extended 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 limit parameters used for pagination
* @param desc descending order of pool elements
*
* @return 0 on success
*/
int dump_extended(string& oss, const string& where, const string& limit,
bool desc)
{
return PoolSQL::dump(oss, "VM_POOL", "body", VirtualMachine::table, where,
limit, desc);
};
/**
* Dumps the VM accounting information in XML format. A filter can be also
* added to the query as well as a time frame.

View File

@ -391,6 +391,12 @@ EOT
:description => 'Overwrite the file'
}
EXTENDED={
:name => 'extended',
:large => '--extended',
:description => 'Show info extended (it only works with xml output)'
}
TEMPLATE_OPTIONS_VM = [TEMPLATE_NAME_VM] + TEMPLATE_OPTIONS + [DRY]
CAPACITY_OPTIONS_VM = [TEMPLATE_OPTIONS[0], TEMPLATE_OPTIONS[1],
@ -399,7 +405,7 @@ EOT
UPDATECONF_OPTIONS_VM = TEMPLATE_OPTIONS[6..15] + [TEMPLATE_OPTIONS[2],
TEMPLATE_OPTIONS[17], TEMPLATE_OPTIONS[18]]
OPTIONS = XML, NUMERIC, KILOBYTES
OPTIONS = XML, EXTENDED, NUMERIC, KILOBYTES
class OneHelper
attr_accessor :client
@ -593,7 +599,7 @@ EOT
size = $stdout.winsize[0] - 1
# ----------- First page, check if pager is needed -------------
rc = pool.get_page(size, 0)
rc = pool.get_page(size, 0, false)
ps = ""
return -1, rc.message if OpenNebula.is_error?(rc)
@ -621,7 +627,7 @@ EOT
options[:noheader] = true
loop do
rc = pool.get_page(size, current)
rc = pool.get_page(size, current, false)
return -1, rc.message if OpenNebula.is_error?(rc)
@ -670,7 +676,8 @@ EOT
size = $stdout.winsize[0] - 1
# ----------- First page, check if pager is needed -------------
rc = pool.get_page(size, 0)
extended = options.include?(:extended) && options[:extended]
rc = pool.get_page(size, 0, extended)
ps = ""
return -1, rc.message if OpenNebula.is_error?(rc)
@ -698,7 +705,7 @@ EOT
current = size
loop do
rc = pool.get_page(size, current)
rc = pool.get_page(size, current, extended)
return -1, rc.message if OpenNebula.is_error?(rc)

View File

@ -1054,7 +1054,8 @@ CommandParser::CmdParser.new(ARGV) do
table = helper.format_pool(options)
pool = OpenNebula::VirtualMachinePool.new(OneVMHelper.get_client)
rc = pool.info_search(:query => options[:search])
rc = pool.info_search(:query => options[:search],
:extended => options[:extended])
if !rc.nil?
puts rc.message

View File

@ -617,6 +617,17 @@ func NewVMPool(args ...int) (*VMPool, error) {
return vmPool, nil
}
// InfoExtended connects to OpenNebula and fetches the whole VM_POOL information
func (vmpool *VMPool) InfoExtended(filter_flag, start_id, end_id, state int) error {
response, err := client.Call("one.vmpool.infoextended", filter_flag,
start_id, end_id,state)
if err != nil {
return err
}
*vmpool = VMPool{}
return xml.Unmarshal([]byte(response.Body()), vmpool)
}
// Monitoring returns all the virtual machine monitoring records
// filter flag:
// -4: Resources belonging to the user's primary group

View File

@ -31,9 +31,10 @@ import org.w3c.dom.Node;
*/
public class VirtualMachinePool extends Pool implements Iterable<VirtualMachine>{
private static final String ELEMENT_NAME = "VM";
private static final String INFO_METHOD = "vmpool.info";
private static final String MONITORING = "vmpool.monitoring";
private static final String ELEMENT_NAME = "VM";
private static final String INFO_METHOD = "vmpool.info";
private static final String INFO_EXTENDED_METHOD = "vmpool.infoextended";
private static final String MONITORING = "vmpool.monitoring";
/**
* Flag for Virtual Machines in any state.
@ -111,6 +112,27 @@ public class VirtualMachinePool extends Pool implements Iterable<VirtualMachine>
return client.call(INFO_METHOD, filter, -1, -1, NOT_DONE);
}
/**
* Retrieves all of the Virtual Machines in the pool.
*
* @param client XML-RPC Client.
* @param filter Filter flag to use. Possible values:
* <ul>
* <li>{@link Pool#ALL}: All Virtual Machines</li>
* <li>{@link Pool#MINE}: Connected user's Virtual Machines</li>
* <li>{@link Pool#MINE_GROUP}: Connected user's Virtual Machines, and the ones in
* his group</li>
* <li>{@link Pool#GROUP}: User's primary group Virtual Machines</li>
* <li>&gt;= 0 UID User's Virtual Machines</li>
* </ul>
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public static OneResponse info_extended(Client client, int filter)
{
return client.call(INFO_EXTENDED_METHOD, filter, -1, -1, NOT_DONE);
}
/**
* Retrieves all the Virtual Machines in the pool.
*
@ -246,6 +268,23 @@ public class VirtualMachinePool extends Pool implements Iterable<VirtualMachine>
return response;
}
/**
* Loads the xml representation of all the
* Virtual Machines in the pool. The filter used is the one set in
* the constructor.
*
* @see VirtualMachinePool#info(Client, int)
*
* @return If successful the message contains the string
* with the information returned by OpenNebula.
*/
public OneResponse info_extended()
{
OneResponse response = info_extended(client, filter);
processInfo(response);
return response;
}
/**
* Loads the xml representation of all the Virtual Machines in the pool.
*

View File

@ -64,6 +64,10 @@ module OpenNebula
alias_method :info!, :info
def info_extended(xml_method)
return xmlrpc_info(xml_info)
end
def info_all(xml_method, *args)
return xmlrpc_info(xml_method, INFO_ALL, -1, -1, *args)
end
@ -232,13 +236,20 @@ module OpenNebula
# > 0 => page size
# current first element of the page
# hash:: return page as a hash
def get_page(size, current)
def get_page(size, current, extended = false)
rc = nil
if PAGINATED_POOLS.include?(@pool_name)
if PAGINATED_POOLS.include?(@pool_name)
pool_name = @pool_name.delete('_').downcase
if extended && pool_name == "vmpool"
method = "#{pool_name}.infoextended"
else
method = "#{pool_name}.info"
end
size = OpenNebula.pool_page_size if (!size || size == 0)
rc = @client.call("#{@pool_name.delete('_').downcase}.info",
@user_id, current, -size, -1)
rc = @client.call(method, @user_id, current, -size, -1)
initialize_xml(rc, @pool_name)
else

View File

@ -26,6 +26,7 @@ module OpenNebula
VM_POOL_METHODS = {
:info => "vmpool.info",
:info_extended => "vmpool.infoextended",
:monitoring => "vmpool.monitoring",
:accounting => "vmpool.accounting",
:showback => "vmpool.showback",
@ -62,57 +63,70 @@ module OpenNebula
# No arguments, returns the not-in-done VMs for the user
# [user_id, start_id, end_id]
# [user_id, start_id, end_id, state]
alias_method :info!, :info
def info(*args)
case args.size
when 0
info_filter(VM_POOL_METHODS[:info],
@user_id,
-1,
-1,
INFO_NOT_DONE)
when 1
info_filter(VM_POOL_METHODS[:info],
args[0],
-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])
when 0
info_filter(VM_POOL_METHODS[:info],
@user_id,
-1,
-1,
INFO_NOT_DONE)
when 1
info_filter(VM_POOL_METHODS[:info],
args[0],
-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
# Define info methods shortcuts for different filters
# info_all()
# info_all!()
# info_all_extended
# info_all_extended!()
# info_mine()
# info_mine!()
# info_mine_extended
# info_mine_extended!()
# info_group()
# info_group!()
# info_group_extended
# info_group_extended!()
# info_primary_group()
# info_primary_group!()
# info_primary_group_extended
# info_primary_group_extended!()
%w[mine all group primary_group].each do |ifilter|
const_name = "OpenNebula::Pool::INFO_#{ifilter.upcase}"
def info_mine()
return info_filter(VM_POOL_METHODS[:info],
INFO_MINE,
-1,
-1,
INFO_NOT_DONE)
end
define_method("info_#{ifilter}") do
info_filter(VM_POOL_METHODS[:info],
Object.const_get(const_name), -1, -1,INFO_NOT_DONE)
end
def info_group()
return info_filter(VM_POOL_METHODS[:info],
INFO_GROUP,
-1,
-1,
INFO_NOT_DONE)
define_method("info_#{ifilter}_extended") do
info_filter(VM_POOL_METHODS[:info_extended],
Object.const_get(const_name), -1, -1,
INFO_NOT_DONE)
end
alias_method "info_#{ifilter}!".to_sym, "info_#{ifilter}".to_sym
alias_method "info_#{ifilter}_extended!".to_sym, "info_#{ifilter}_extended".to_sym
end
def info_search(args = {})
@ -121,21 +135,24 @@ module OpenNebula
:start_id => -1,
:end_id => -1,
:state => INFO_NOT_DONE,
:query => ""
:query => "",
:extended => false
}.merge!(args)
return info_filter(VM_POOL_METHODS[:info],
default_args[:who],
default_args[:start_id],
default_args[:end_id],
default_args[:state],
default_args[:query])
if args[:extended]
method = VM_POOL_METHODS[:info_extended]
else
method = VM_POOL_METHODS[:info]
end
info_filter(method,
default_args[:who],
default_args[:start_id],
default_args[:end_id],
default_args[:state],
default_args[:query])
end
alias_method :info!, :info
alias_method :info_all!, :info_all
alias_method :info_mine!, :info_mine
alias_method :info_group!, :info_group
# Retrieves the monitoring data for all the VMs in the pool
#

View File

@ -483,6 +483,7 @@ void RequestManager::register_xml_methods()
xmlrpc_c::methodPtr hostpool_info(new HostPoolInfo());
xmlrpc_c::methodPtr datastorepool_info(new DatastorePoolInfo());
xmlrpc_c::methodPtr vm_pool_info(new VirtualMachinePoolInfo());
xmlrpc_c::methodPtr vm_pool_info_extended(new VirtualMachinePoolInfoExtended());
xmlrpc_c::methodPtr template_pool_info(new TemplatePoolInfo());
xmlrpc_c::methodPtr vnpool_info(new VirtualNetworkPoolInfo());
xmlrpc_c::methodPtr vntemplate_pool_info(new VirtualNetworkTemplatePoolInfo());
@ -601,6 +602,7 @@ void RequestManager::register_xml_methods()
RequestManagerRegistry.addMethod("one.vm.diskresize", vm_disk_resize);
RequestManagerRegistry.addMethod("one.vmpool.info", vm_pool_info);
RequestManagerRegistry.addMethod("one.vmpool.infoextended", vm_pool_info_extended);
RequestManagerRegistry.addMethod("one.vmpool.accounting", vm_pool_acct);
RequestManagerRegistry.addMethod("one.vmpool.monitoring", vm_pool_monitoring);
RequestManagerRegistry.addMethod("one.vmpool.showback", vm_pool_showback);

View File

@ -514,8 +514,20 @@ void RequestManagerPoolInfoFilter::dump(
Nebula::instance().get_configuration_attribute(att.uid, att.gid,
"API_LIST_ORDER", desc);
rc = pool->dump(str, where_string, limit_clause,
one_util::toupper(desc) == "DESC");
if ( extended )
{
rc = pool->dump_extended(str,
where_string,
limit_clause,
one_util::toupper(desc) == "DESC");
}
else
{
rc = pool->dump(str,
where_string,
limit_clause,
one_util::toupper(desc) == "DESC");
}
if ( rc != 0 )
{
@ -580,7 +592,7 @@ void VirtualNetworkPoolInfo::request_execute(
std::string pool_oss;
std::string desc;
Nebula::instance().get_configuration_attribute(att.uid, att.gid,
Nebula::instance().get_configuration_attribute(att.uid, att.gid,
"API_LIST_ORDER", desc);
int rc = pool->dump(pool_oss, where_string.str(), limit_clause.str(),
@ -617,4 +629,3 @@ void MarketPlacePoolInfo::request_execute(
{
dump(att, ALL, -1, -1, "", "");
}