WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-api

Re: [Xen-API] Simple Java API example

To: Stefan Berger <stefanb@xxxxxxxxxx>
Subject: Re: [Xen-API] Simple Java API example
From: Christian Smith <Christian.Smith@xxxxxxx>
Date: Mon, 09 Apr 2007 17:16:49 +0100
Cc: xen-api-bounces@xxxxxxxxxxxxxxxxxxx, xen-api@xxxxxxxxxxxxxxxxxxx
Delivery-date: Mon, 09 Apr 2007 09:16:20 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
In-reply-to: <OFFFCFCC14.22D42B93-ON852572B5.0044BE92-852572B5.00451D6C@xxxxxxxxxx>
List-help: <mailto:xen-api-request@lists.xensource.com?subject=help>
List-id: Discussion of API issues surrounding Xen <xen-api.lists.xensource.com>
List-post: <mailto:xen-api@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-api>, <mailto:xen-api-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-api>, <mailto:xen-api-request@lists.xensource.com?subject=unsubscribe>
References: <OFFFCFCC14.22D42B93-ON852572B5.0044BE92-852572B5.00451D6C@xxxxxxxxxx>
Sender: xen-api-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Thunderbird 1.5.0.10 (X11/20070221)
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@xxxxxxxxxxxxxxxxxxx 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@xxxxxxxxxxxxxxxxxxx
> http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-api


_______________________________________________
xen-api mailing list
xen-api@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-api

<Prev in Thread] Current Thread [Next in Thread>