|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-API] Simple Java API example
Hi Stefan,I have gotten you example to list the UUID's of all VM's successfully but im having issues trying to get information on specific VM's. Im sure its something im overlooking but when I run the code below I get the following errors returned:
EPERMDENIED
Session Invalid
My code is below. Thanks for your help.
-Christian
package rpcexample;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
public class RPCExample {
private static XmlRpcClientConfigImpl config;
private static XmlRpcClient client;
/**
* @param args
*/
public static void main(String[] args) {
URL url = null;
try {
url = new URL("http://my-ip:9363");
} catch (MalformedURLException e) {
System.out.println("Malformed URL?");
System.exit(-1);
}
config = new XmlRpcClientConfigImpl();
config.setServerURL(url);
client = new XmlRpcClient();
client.setConfig(config);
String username = "any";
String password = "any";
Object[] params = new Object[]{username, password};
HashMap<String, String> result = null;
try {
result = (HashMap)
client.execute("session.login_with_password", params);
} catch (XmlRpcException e) {
System.out.println("Could not open session");
System.exit(-1);
}
String status = result.get("Status");
if (status.compareTo("Success") == 0) {
String uuid = result.get("Value");
params = new Object[]{uuid};
try {
result = (HashMap) client.execute("VM.get_all", params);
} catch (XmlRpcException e) {
System.out.println("Could not get VMs' UUIDs");
System.exit(-1);
}
Object res = result.get("Value");
if (res.getClass() == Object[].class) {
Object[] arr = (Object[])res;
int i;
for (i = 0; i < arr.length; i++) {
//System.out.println("VM UUID: " +(String)arr[i]);
vm(arr[i]);
}
}
}
}
public static void vm(Object vm){
Object[] params;
HashMap<String, String> result = null;
System.out.println("UUID: " + (String)vm);
params = new Object[]{vm};
try {
result = (HashMap)client.execute("VM.get_memory_actual",
params);
String status = result.get("Status");
if(status.compareTo("Failure") == 0){
Object res = result.get("ErrorDescription");
if( res.getClass() == Object[].class ){
Object[] arr = (Object[])res;
for(int i = 0; i < arr.length; i++){
System.out.println("\tDescrip: " + (String)arr[i]);
}
}
}else {
System.out.println("\tResult: " + result);
}
} catch (XmlRpcException ex) {
System.out.println("Could not get actual memory!");
}
}
}
Stefan Berger wrote:
_______________________________________________ xen-api mailing list xen-api@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-api
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |