Skip to content

Commit

Permalink
F OpenNebula#3076: create one.vmpool.infoextended
Browse files Browse the repository at this point in the history
    * Add new function dump_extended
    * Add new API call one.vmpool.infoextended
    * Add parameter --extended in the CLI
  • Loading branch information
Alejandro Huertas committed Mar 27, 2019
1 parent 73ff19b commit b0cb3bf
Show file tree
Hide file tree
Showing 10 changed files with 280 additions and 96 deletions.
19 changes: 18 additions & 1 deletion include/PoolSQL.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,27 @@ class PoolSQL: public Hookable
*
* @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
// -------------------------------------------------------------------------
Expand Down
39 changes: 38 additions & 1 deletion include/RequestManagerPoolInfoFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,13 @@ class RequestManagerPoolInfoFilter: public Request
int start_id,
int end_id,
const string& and_clause,
const string& or_clause);
const string& or_clause,
bool extended);

void pool_filter(xmlrpc_c::paramList const& paramList,
RequestAttributes& att,
PoolSQL* pool,
bool extended);
};

/* ------------------------------------------------------------------------- */
Expand Down Expand Up @@ -131,6 +137,37 @@ class VirtualMachinePoolInfo : public RequestManagerPoolInfoFilter
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */

class VirtualMachinePoolInfoExtended : 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)*/

/* -------------------------------------------------------------------- */

VirtualMachinePoolInfoExtended():
RequestManagerPoolInfoFilter("one.vmpool.infoextended",
"Returns the virtual machine instances pool",
"A:siiiis")
{
Nebula& nd = Nebula::instance();
pool = nd.get_vmpool();
auth_object = PoolObjectSQL::VM;
};

~VirtualMachinePoolInfoExtended(){};

/* -------------------------------------------------------------------- */

void request_execute(
xmlrpc_c::paramList const& paramList, RequestAttributes& att);
};

/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */

class VirtualMachinePoolAccounting : public RequestManagerPoolInfoFilter
{
public:
Expand Down
19 changes: 19 additions & 0 deletions include/VirtualMachinePool.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,25 @@ class VirtualMachinePool : public PoolSQL
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.
Expand Down
13 changes: 10 additions & 3 deletions src/cli/one_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,12 @@ module OpenNebulaHelper
: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],
Expand All @@ -399,7 +405,7 @@ module OpenNebulaHelper
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
Expand Down Expand Up @@ -670,7 +676,8 @@ def list_pool_xml(pool, options, filter_flag)
size = $stdout.winsize[0] - 1

# ----------- First page, check if pager is needed -------------
rc = pool.get_page(size, 0)
extended = options.include? :extended
rc = pool.get_page(size, 0, extended)
ps = ""

return -1, rc.message if OpenNebula.is_error?(rc)
Expand Down Expand Up @@ -698,7 +705,7 @@ def list_pool_xml(pool, options, filter_flag)
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)

Expand Down
3 changes: 2 additions & 1 deletion src/cli/onevm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 42 additions & 3 deletions src/oca/java/src/org/opennebula/client/vm/VirtualMachinePool.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@
*/
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.
Expand Down Expand Up @@ -111,6 +112,27 @@ public static OneResponse info(Client client, int filter)
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.
*
Expand Down Expand Up @@ -246,6 +268,23 @@ public OneResponse info()
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.
*
Expand Down
19 changes: 15 additions & 4 deletions src/oca/ruby/opennebula/pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ def info(xml_method)

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
Expand Down Expand Up @@ -232,13 +236,20 @@ def info_paginated(size)
# > 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
Expand Down
20 changes: 18 additions & 2 deletions src/oca/ruby/opennebula/virtual_machine_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class VirtualMachinePool < Pool

VM_POOL_METHODS = {
:info => "vmpool.info",
:info_extended => "vmpool.infoextended",
:monitoring => "vmpool.monitoring",
:accounting => "vmpool.accounting",
:showback => "vmpool.showback",
Expand Down Expand Up @@ -91,6 +92,14 @@ def info(*args)
end
end

def info_extended()
return info_filter(VM_POOL_METHODS[:info_extended],
@user_id,
-1,
-1,
INFO_NOT_DONE)
end

def info_all()
return info_filter(VM_POOL_METHODS[:info],
INFO_ALL,
Expand Down Expand Up @@ -121,10 +130,17 @@ def info_search(args = {})
:start_id => -1,
:end_id => -1,
:state => INFO_NOT_DONE,
:query => ""
:query => "",
:extended => false
}.merge!(args)

return info_filter(VM_POOL_METHODS[:info],
if args[:extended]
method = VM_POOL_METHODS[:info_extended]
else
method = VM_POOL_METHODS[:info]
end

return info_filter(method,
default_args[:who],
default_args[:start_id],
default_args[:end_id],
Expand Down
2 changes: 2 additions & 0 deletions src/rm/RequestManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit b0cb3bf

Please sign in to comment.