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 28, 2019
1 parent 73ff19b commit d583239
Show file tree
Hide file tree
Showing 11 changed files with 223 additions and 18 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
49 changes: 49 additions & 0 deletions include/RequestManagerPoolInfoFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,18 @@ class RequestManagerPoolInfoFilter: public Request
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(){};
Expand Down Expand Up @@ -120,10 +126,53 @@ class VirtualMachinePoolInfo : public RequestManagerPoolInfoFilter
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(){};

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

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

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

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

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

class VirtualMachinePoolInfoExtended : public VirtualMachinePoolInfo
{
public:

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

~VirtualMachinePoolInfoExtended(){};

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

void request_execute(
xmlrpc_c::paramList const& paramList, RequestAttributes& att);
};
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
11 changes: 11 additions & 0 deletions src/oca/go/src/goca/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 d583239

Please sign in to comment.