Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Xen: API

Simple Java API example

 

 

Xen api RSS feed   Index | Next | Previous | View Threaded


Christian.Smith at Sun

Apr 5, 2007, 5:10 AM

Post #1 of 6 (148 views)
Permalink
Simple Java API example

Hi All,

I am trying to talk to the Xen API with Java and
'org.apache.xmlrpc.client.XmlRpcClient' (version 3). I was wondering if
someone could give me a very short example of connecting to the server
and getting a list of VM's? I have never used XML-RPC before and the
tutorials ive found dont seem to apply to this version of the xmlrpc api.

Thanks in advance,
Christian

_______________________________________________
xen-api mailing list
xen-api [at] lists
http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-api


stefanb at us

Apr 6, 2007, 5:34 AM

Post #2 of 6 (146 views)
Permalink
Re: Simple Java API example [In reply to]

This program should show all VMs' UUIDs.

I added the line

(xen-api-server (( 0.0.0.0:9363 none )))

to /etc/xen/xend-config.sxp before starting xend.

Stefan


package test;

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 Test {
private static XmlRpcClientConfigImpl config;
private static XmlRpcClient client;

/**
* @param args
*/
public static void main(String[] args) {
URL url = null;
try {
url = new URL(
"http://your.xen.machine.ip.address: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]);
}
}

}

}
}

xen-api-bounces [at] lists wrote on 04/05/2007 08:10:10 AM:

> Hi All,
>
> I am trying to talk to the Xen API with Java and
> 'org.apache.xmlrpc.client.XmlRpcClient' (version 3). I was wondering if

> someone could give me a very short example of connecting to the server
> and getting a list of VM's? I have never used XML-RPC before and the
> tutorials ive found dont seem to apply to this version of the xmlrpc
api.
>
> Thanks in advance,
> Christian
>
> _______________________________________________
> xen-api mailing list
> xen-api [at] lists
> http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-api


Christian.Smith at Sun

Apr 9, 2007, 9:16 AM

Post #3 of 6 (140 views)
Permalink
Re: Simple Java API example [In reply to]

Thanks for that Stefan, just what I was looking for :-)

Cheers,
Christian


Stefan Berger wrote:
>
> *This program should show all VMs' UUIDs.*
>
> *I added the line*
>
> *(xen-api-server (( 0.0.0.0:9363 none )))*
>
> *to /etc/xen/xend-config.sxp before starting xend.*
>
> * Stefan*
>
>
> *package* test;
>
> *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* Test {
> *private* *static* XmlRpcClientConfigImpl /config/;
> *private* *static* XmlRpcClient /client/;
>
> /**
> * *@param* args
> */
> *public* *static* *void* main(String[] args) {
> URL url = *null*;
> *try* {
> url = *new*
> URL("http://your.xen.machine.ip.address: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]);
> }
> }
>
> }
>
> }
> }
>
> xen-api-bounces [at] lists wrote on 04/05/2007 08:10:10 AM:
>
> > Hi All,
> >
> > I am trying to talk to the Xen API with Java and
> > 'org.apache.xmlrpc.client.XmlRpcClient' (version 3). I was
> wondering if
> > someone could give me a very short example of connecting to the server
> > and getting a list of VM's? I have never used XML-RPC before and the
> > tutorials ive found dont seem to apply to this version of the xmlrpc
> api.
> >
> > Thanks in advance,
> > Christian
> >
> > _______________________________________________
> > xen-api mailing list
> > xen-api [at] lists
> > http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-api


_______________________________________________
xen-api mailing list
xen-api [at] lists
http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-api


Christian.Smith at Sun

Apr 10, 2007, 1:50 AM

Post #4 of 6 (141 views)
Permalink
Re: Simple Java API example [In reply to]

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:
>
> *This program should show all VMs' UUIDs.*
>
> *I added the line*
>
> *(xen-api-server (( 0.0.0.0:9363 none )))*
>
> *to /etc/xen/xend-config.sxp before starting xend.*
>
> * Stefan*
>
>
> *package* test;
>
> *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* Test {
> *private* *static* XmlRpcClientConfigImpl /config/;
> *private* *static* XmlRpcClient /client/;
>
> /**
> * *@param* args
> */
> *public* *static* *void* main(String[] args) {
> URL url = *null*;
> *try* {
> url = *new*
> URL("http://your.xen.machine.ip.address: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]);
> }
> }
>
> }
>
> }
> }
>
> xen-api-bounces [at] lists wrote on 04/05/2007 08:10:10 AM:
>
> > Hi All,
> >
> > I am trying to talk to the Xen API with Java and
> > 'org.apache.xmlrpc.client.XmlRpcClient' (version 3). I was
> wondering if
> > someone could give me a very short example of connecting to the server
> > and getting a list of VM's? I have never used XML-RPC before and the
> > tutorials ive found dont seem to apply to this version of the xmlrpc
> api.
> >
> > Thanks in advance,
> > Christian
> >
> > _______________________________________________
> > xen-api mailing list
> > xen-api [at] lists
> > http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-api
> ------------------------------------------------------------------------
>
> _______________________________________________
> xen-api mailing list
> xen-api [at] lists
> http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-api
>


_______________________________________________
xen-api mailing list
xen-api [at] lists
http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-api


saurabh.g.garg at oracle

Apr 10, 2007, 2:18 AM

Post #5 of 6 (140 views)
Permalink
Re: Simple Java API example [In reply to]

Hi Christian,

In function vm(Object obj), the params are being constructed with uuid
(of the vm node), but no session-id which you retrieved in the main
function call... the session-id retrieved after authentication need to
be passed as a parameter in every api call then after. You can modify
your function signature to vm(Object,String) and pass on the sessionID
to this method from main.

Saurabh.

Christian Smith - Sun Microsystems - Dublin Ireland wrote:
> 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:
>>
>> *This program should show all VMs' UUIDs.*
>>
>> *I added the line*
>>
>> *(xen-api-server (( 0.0.0.0:9363 none )))*
>>
>> *to /etc/xen/xend-config.sxp before starting xend.*
>>
>> * Stefan*
>>
>>
>> *package* test;
>>
>> *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* Test {
>> *private* *static* XmlRpcClientConfigImpl /config/;
>> *private* *static* XmlRpcClient /client/;
>> /**
>> * *@param* args
>> */
>> *public* *static* *void* main(String[] args) {
>> URL url = *null*;
>> *try* {
>> url = *new*
>> URL("http://your.xen.machine.ip.address: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]);
>> }
>> }
>> }
>>
>> }
>> }
>>
>> xen-api-bounces [at] lists wrote on 04/05/2007 08:10:10 AM:
>>
>> > Hi All,
>> >
>> > I am trying to talk to the Xen API with Java and
>> > 'org.apache.xmlrpc.client.XmlRpcClient' (version 3). I was
>> wondering if
>> > someone could give me a very short example of connecting to the server
>> > and getting a list of VM's? I have never used XML-RPC before and the
>> > tutorials ive found dont seem to apply to this version of the
>> xmlrpc api.
>> >
>> > Thanks in advance,
>> > Christian
>> >
>> > _______________________________________________
>> > xen-api mailing list
>> > xen-api [at] lists
>> > http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-api
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> xen-api mailing list
>> xen-api [at] lists
>> http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-api
>>
>
>
> _______________________________________________
> xen-api mailing list
> xen-api [at] lists
> http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-api


_______________________________________________
xen-api mailing list
xen-api [at] lists
http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-api


Christian.Smith at Sun

Apr 10, 2007, 3:11 AM

Post #6 of 6 (143 views)
Permalink
Re: Simple Java API example [In reply to]

Hi Saurabh,

That did the trick, cheers :-)

Saurabh Garg wrote:
> Hi Christian,
>
> In function vm(Object obj), the params are being constructed with uuid
> (of the vm node), but no session-id which you retrieved in the main
> function call... the session-id retrieved after authentication need to
> be passed as a parameter in every api call then after. You can modify
> your function signature to vm(Object,String) and pass on the sessionID
> to this method from main.
>
> Saurabh.
>
> Christian Smith - Sun Microsystems - Dublin Ireland wrote:
>> 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:
>>>
>>> *This program should show all VMs' UUIDs.*
>>>
>>> *I added the line*
>>>
>>> *(xen-api-server (( 0.0.0.0:9363 none )))*
>>>
>>> *to /etc/xen/xend-config.sxp before starting xend.*
>>>
>>> * Stefan*
>>>
>>>
>>> *package* test;
>>>
>>> *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* Test {
>>> *private* *static* XmlRpcClientConfigImpl /config/;
>>> *private* *static* XmlRpcClient /client/; /**
>>> * *@param* args
>>> */
>>> *public* *static* *void* main(String[] args) {
>>> URL url = *null*;
>>> *try* {
>>> url = *new*
>>> URL("http://your.xen.machine.ip.address: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]);
>>> }
>>> }
>>> }
>>>
>>> }
>>> }
>>>
>>> xen-api-bounces [at] lists wrote on 04/05/2007 08:10:10 AM:
>>>
>>> > Hi All,
>>> >
>>> > I am trying to talk to the Xen API with Java and
>>> > 'org.apache.xmlrpc.client.XmlRpcClient' (version 3). I was
>>> wondering if
>>> > someone could give me a very short example of connecting to the
>>> server
>>> > and getting a list of VM's? I have never used XML-RPC before and the
>>> > tutorials ive found dont seem to apply to this version of the
>>> xmlrpc api.
>>> >
>>> > Thanks in advance,
>>> > Christian
>>> >
>>> > _______________________________________________
>>> > xen-api mailing list
>>> > xen-api [at] lists
>>> > http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-api
>>> ------------------------------------------------------------------------
>>>
>>>
>>> _______________________________________________
>>> xen-api mailing list
>>> xen-api [at] lists
>>> http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-api
>>>
>>
>>
>> _______________________________________________
>> xen-api mailing list
>> xen-api [at] lists
>> http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-api
>
>
> _______________________________________________
> xen-api mailing list
> xen-api [at] lists
> http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-api


_______________________________________________
xen-api mailing list
xen-api [at] lists
http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-api

Xen api RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.