capvt
(Paolo)
December 2, 2015, 10:48am
1
Hi all!!
I am trying to use XML RPC in a Java program…
for example…
if I wanted to know the hosts like the command onehost list
does…
what should I do?
I look in the guide
look the onehost
tab
and find the row
list top | one.hostpool.info | HOST:USE
then what should I do?
capvt
(Paolo)
December 2, 2015, 3:30pm
2
I’ve found the solution!!
I hope this help some newbye like me
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package onetest;
import java.net.MalformedURLException;
import java.net.URL;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
/**
*
* @author paolo
*/
public class OpenNebulaClient{
private XmlRpcClient client = new XmlRpcClient();
private XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
private String session ="oneadmin:password";
public OpenNebulaClient(String server_url){
try{
this.config.setServerURL(new URL(server_url));
this.client.setConfig(this.config);
}
catch(MalformedURLException e){
System.err.println(e);
}
}
public void getUserInfo(int id) throws XmlRpcException{
Object[] params = {session,id};
try {
Object[] result = (Object[])this.client.execute("one.user.info",params);
if(!result[0].equals(null)) {
boolean success = (Boolean)result[0];
String str_res = (String)result[1];
System.out.println("success="+success);
System.out.println("result="+str_res);
}
else{
System.out.println("success=0");
}
}
catch (XmlRpcException e) {
System.err.println(e);
//e.printStackTrace();
}
}
public static void main(String[] args){
OpenNebulaClient on_client = new OpenNebulaClient("http://localhost:2633/RPC2");
try{
on_client.getUserInfo(0);
}
catch(XmlRpcException xmlrpce){
System.err.println(xmlrpce);
}
}
}
cmartin
(Carlos Martín)
December 7, 2015, 2:26pm
3
1 Like
capvt
(Paolo)
February 6, 2016, 1:24pm
4
Thank you Carlos!
can I ask if there’s a way to use xml-rpc methods with curl command?
what is the xml equivalent of a command like “one.host.info ”?
thank you
cmartin
(Carlos Martín)
February 8, 2016, 10:00am
5
Hi,
I know for a fact that you can use curl to access an xmlrpc api, but I don’t have any examples for the OpenNebula api.
Regards