1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-11 05:17:41 +03:00

Updated OneClient API, solved minor bugs when reading the template. Added a C Wrapper to ease the implementation of the libvirt driver

git-svn-id: http://svn.opennebula.org/one/trunk@135 3034c82b-c49b-4eb3-8279-a7acafdc01c0
This commit is contained in:
Rubén S. Montero 2008-10-10 23:24:47 +00:00
parent 67bb553001
commit 8be041503e
3 changed files with 227 additions and 12 deletions

View File

@ -21,8 +21,9 @@
#include <xmlrpc-c/base.hpp>
#include <xmlrpc-c/client_simple.hpp>
#include <string>
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
@ -249,4 +250,30 @@ private:
int host_available(int hid, bool enable, string& error);
};
extern "C"
{
void c_oneStart();
int c_oneDeploy(int vmid, int hid);
int c_oneMigrate(int vmid, int hid, int flag);
int c_oneAllocate(char* vm_template);
int c_oneAction(int vmid,char* action);
int c_oneShutdown(int vmid);
int c_oneSuspend(int vmid);
int c_oneStop(int vmid);
int c_oneResume(int vmid);
int c_oneVmInfo(int vmid, char* ret_info,int leng);
void c_oneFree();
}
#endif /*ONECLIENT_H_*/

View File

@ -22,24 +22,34 @@
int OneClient::allocate(string template_file, int& vmid, string& error)
{
try {
ifstream file;
try{
string str_template="";
file.exceptions (ifstream::failbit | ifstream::badbit );
ifstream file;
char c;
file.open(template_file.c_str());
if ( file.good() == false )
{
error = "Could not open file\n";
return -1;
}
file.get(c);
while (file.good())
{
str_template += file.get();
str_template+=c;
file.get(c);
}
file.close();
xmlrpc_c::value result;
this->call(url,
xmlrpc_c::value result;
this->call(url,
"one.vmallocate",
"ss",
&result,

View File

@ -0,0 +1,178 @@
#include "OneClient.h"
#include <iostream>
using namespace std;
/* ************************************************************************** */
OneClient* client=0;
/* ************************************************************************** */
void c_oneStart()
{
client=new OneClient("localhost",60222);
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void c_oneFree()
{
if(client)
delete client;
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int c_oneDeploy(int vmid, int hid)
{
string info;
if(!client)
return -1;
if(client->deploy(vmid,hid,info) <0)
{
cerr<<info<<endl;
return -1;
}
return 0;
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int c_oneMigrate(int vmid, int hid, int flag)
{
string info;
if (!client)
return -1;
if(client->migrate(vmid,hid,(bool)flag,info) <0)
{
cerr<<info<<endl;
return -1;
}
return 0;
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int c_oneAllocate(char* vm_template)
{
string info;
int vmid;
if (!client)
return -1;
if( (client->allocate(vm_template,vmid, info)) <0)
{
cerr<<info<<endl;
return -1;
}
return vmid;
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int c_oneShutdown(int vmid)
{
string info;
if (!client)
return -1;
if(client->shutdown(vmid,info) <0)
{
cerr<<info<<endl;
return -1;
}
return 0;
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int c_oneSuspend(int vmid)
{
string info;
if (!client)
return -1;
if (client->suspend(vmid,info) <0)
{
cerr<<info<<endl;
return -1;
}
return 0;
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int c_oneStop(int vmid)
{
string info;
if (!client)
return -1;
if (client->stop(vmid,info) <0)
{
cerr<<info<<endl;
return -1;
}
return 0;
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int c_oneResume(int vmid)
{
string info;
if (!client)
return -1;
if( client->resume(vmid,info) <0)
{
cerr<<info<<endl;
return -1;
}
return 0;
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int c_oneVmInfo(int vmid, char* ret_info,int leng)
{
string info;
string error;
if (!client || !ret_info)
return -1;
if(client->info(vmid,info,error) <0)
{
cerr<<error<<endl;
return -1;
}
strncpy(ret_info,info.c_str(),leng-1);
return 0;
};