Skip to content

Commit

Permalink
New method to get the pool through the xml-rpc interface. Some work t…
Browse files Browse the repository at this point in the history
…o have XML format and plain text for the objects.

 


git-svn-id: http://svn.opennebula.org/one/trunk@521 3034c82b-c49b-4eb3-8279-a7acafdc01c0
  • Loading branch information
ruben committed May 22, 2009
1 parent 0710354 commit f7aef4a
Show file tree
Hide file tree
Showing 9 changed files with 371 additions and 32 deletions.
24 changes: 24 additions & 0 deletions include/RequestManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,30 @@ class RequestManager : public ActionListener
private:
VirtualMachinePool * vmpool;
};


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

class VirtualMachinePoolInfo: public xmlrpc_c::method
{
public:
VirtualMachinePoolInfo(
VirtualMachinePool * _vmpool):
vmpool(_vmpool)
{
_signature="A:si";
_help="Returns the virtual machine pool";
};

~VirtualMachinePoolInfo(){};

void execute(
xmlrpc_c::paramList const& paramList,
xmlrpc_c::value * const retval);

private:
VirtualMachinePool * vmpool;
};

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

Expand Down
12 changes: 10 additions & 2 deletions include/Template.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,16 @@ class Template
* </template>
* The name of the root element is set when the Template object is created
* @param xml string that hold the xml template representation
* @return a reference to the generated string
*/
string& to_xml(string& xml) const;

/**
* Writes the template in a plain text string
* @param str string that hold the template representation
* @return a reference to the generated string
*/
void to_xml(string& xml) const;
string& to_str(string& str) const;

/**
* Sets a new attribute, the attribute MUST BE ALLOCATED IN THE HEAP, and
Expand Down Expand Up @@ -148,7 +156,7 @@ class Template
string& name,
int& value) const;

friend ostream& operator<<(ostream& os, Template& t);
friend ostream& operator<<(ostream& os, const Template& t);

protected:
/**
Expand Down
42 changes: 38 additions & 4 deletions include/VirtualMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
using namespace std;

extern "C" int vm_select_cb (void * _vm, int num,char ** values, char ** names);
extern "C" int vm_dump_cb (void * _oss, int num,char ** values, char ** names);

/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
Expand Down Expand Up @@ -116,8 +117,24 @@ class VirtualMachine : public PoolObjectSQL
/**
* Function to write a Virtual Machine in an output stream
*/
friend ostream& operator<<(ostream& os, VirtualMachine& vm);

friend ostream& operator<<(ostream& os, const VirtualMachine& vm);

/**
* Function to print the VirtualMachine object into a string in
* plain text
* @param str the resulting string
* @return a reference to the generated string
*/
string& to_str(string& str) const;

/**
* Function to print the VirtualMachine object into a string in
* XML format
* @param xml the resulting XML string
* @return a reference to the generated string
*/
string& to_xml(string& xml) const;

// ------------------------------------------------------------------------
// Dynamic Info
// ------------------------------------------------------------------------
Expand Down Expand Up @@ -702,6 +719,12 @@ class VirtualMachine : public PoolObjectSQL
int num,
char ** values,
char ** names);

friend int vm_dump_cb (
void * _vm,
int num,
char ** values,
char ** names);

// *************************************************************************
// Virtual Machine Attributes
Expand Down Expand Up @@ -820,8 +843,8 @@ class VirtualMachine : public PoolObjectSQL
/**
* Function to unmarshall a VM object, an associated classes.
* @param num the number of columns read from the DB
* @para names the column names
* @para vaues the column values
* @param names the column names
* @param vaues the column values
* @return 0 on success
*/
int unmarshall(int num, char **names, char ** values);
Expand Down Expand Up @@ -981,6 +1004,17 @@ class VirtualMachine : public PoolObjectSQL
*/
virtual int update(SqliteDB * db);

/**
* Dumps the contect of a set of VirtualMachine objects in the given stream
* using XML format
* @param db pointer to the db
* @param oss the output stream
* @param where string to filter the VirtualMachine objects
* @return 0 on success
*/
static int dump(SqliteDB * db, ostringstream& oss, const string&
where);

/**
* Deletes a VM from the database and all its associated information:
* - History records
Expand Down
22 changes: 22 additions & 0 deletions include/VirtualMachinePool.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,29 @@ class VirtualMachinePool : public PoolSQL
{
VirtualMachine::bootstrap(db);
};

/**
* 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
*
* @return 0 on success
*/
int dump(ostringstream& oss, const string& where)
{
int rc;

oss << "<VM_POOL>";

rc = VirtualMachine::dump(db,oss,where);

oss << "</VM_POOL>";

return rc;
}

private:
/**
* Generate context file to be sourced upon VM booting
Expand Down
4 changes: 4 additions & 0 deletions src/rm/RequestManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ void RequestManager::register_xml_methods()

xmlrpc_c::methodPtr vm_info(new
RequestManager::VirtualMachineInfo(vmpool));

xmlrpc_c::methodPtr vm_pool_info(new
RequestManager::VirtualMachinePoolInfo(vmpool));

xmlrpc_c::methodPtr host_allocate(new
RequestManager::HostAllocate(hpool));
Expand Down Expand Up @@ -257,6 +260,7 @@ void RequestManager::register_xml_methods()
RequestManagerRegistry.addMethod("one.vmaction", vm_action);
RequestManagerRegistry.addMethod("one.vmmigrate", vm_migrate);
RequestManagerRegistry.addMethod("one.vmget_info", vm_info);
RequestManagerRegistry.addMethod("one.vmget_pool_info", vm_pool_info);

/* Host related methods*/

Expand Down
85 changes: 85 additions & 0 deletions src/rm/RequestManagerPoolInfo.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2009, Distributed Systems Architecture Group, Universidad */
/* Complutense de Madrid (dsa-research.org) */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
/* not use this file except in compliance with the License. You may obtain */
/* a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/* -------------------------------------------------------------------------- */

#include "RequestManager.h"
#include "Nebula.h"

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

void RequestManager::VirtualMachinePoolInfo::execute(
xmlrpc_c::paramList const& paramList,
xmlrpc_c::value * const retval)
{
string session;

// <vid> of the vid to retrieve the information for
int vid, rc;

ostringstream oss;

/* -- RPC specific vars -- */
vector<xmlrpc_c::value> arrayData;
xmlrpc_c::value_array * arrayresult;

Nebula::log("ReM",Log::DEBUG,"VirtualMachinePoolInfo method invoked");

// Get the parameters
//TODO the session id to validate with the SessionManager
session = xmlrpc_c::value_string(paramList.getString(0));
vid = xmlrpc_c::value_int (paramList.getInt(1));

// Perform the allocation in the vmpool
rc = VirtualMachinePoolInfo::vmpool->dump(oss,"");

if ( rc != 0 )
{
goto error_dump;
}

// All nice, return the vm info to the client
arrayData.push_back(xmlrpc_c::value_boolean(true)); // SUCCESS

arrayData.push_back(xmlrpc_c::value_string(oss.str()));
arrayresult = new xmlrpc_c::value_array(arrayData);
// Copy arrayresult into retval mem space
*retval = *arrayresult;
// and get rid of the original
delete arrayresult;

return;

error_dump:
oss << "Error getting the pool info";
goto error_common;

error_common:

arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE
arrayData.push_back(xmlrpc_c::value_string(oss.str()));

Nebula::log("ReM",Log::ERROR,oss);

xmlrpc_c::value_array arrayresult_error(arrayData);

*retval = arrayresult_error;

return;
}

/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
1 change: 1 addition & 0 deletions src/rm/SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ source_files=[
'RequestManagerDeploy.cc',
'RequestManagerMigrate.cc',
'RequestManagerInfo.cc',
'RequestManagerPoolInfo.cc',
'RequestManagerHostAllocate.cc',
'RequestManagerHostDelete.cc',
'RequestManagerHostInfo.cc',
Expand Down
27 changes: 21 additions & 6 deletions src/template/Template.cc
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ void Template::get(
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

void Template::to_xml(string& xml) const
string& Template::to_xml(string& xml) const
{
multimap<string,Attribute *>::const_iterator it;
ostringstream oss;
Expand All @@ -324,25 +324,40 @@ void Template::to_xml(string& xml) const
oss << "</" << xml_root << ">";

xml = oss.str();
}

return xml;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

ostream& operator << (ostream& os, Template& t)
string& Template::to_str(string& str) const
{
multimap<string,Attribute *>::iterator it;
ostringstream os;
multimap<string,Attribute *>::const_iterator it;
string * s;

for ( it = t.attributes.begin(); it!=t.attributes.end(); it++)
for ( it = attributes.begin(); it!=attributes.end(); it++)
{
s = it->second->marshall(",");

os << endl << "\t" << it->first << t.separator << *s;
os << endl << "\t" << it->first << separator << *s;

delete s;
}

str = os.str();
return str;
}

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

ostream& operator << (ostream& os, const Template& t)
{
string str;

os << t.to_str(str);

return os;
}

Expand Down
Loading

0 comments on commit f7aef4a

Please sign in to comment.