Examples of OneResponse


Examples of org.opennebula.client.OneResponse

     *
     * @see Host#info(Client, int)
     */
    public OneResponse info()
    {
        OneResponse response = info(client, id);
        super.processInfo(response);
        return response;
    }
View Full Code Here

Examples of org.opennebula.client.OneResponse

            System.out.println("Virtual Machine Template:\n" + vmTemplate);
            System.out.println();

            System.out.print("Trying to allocate the virtual machine... ");
            OneResponse rc = VirtualMachine.allocate(oneClient, vmTemplate);

            if( rc.isError() )
            {
                System.out.println( "failed!");
                throw new Exception( rc.getErrorMessage() );
            }

            // The response message is the new VM's ID
            int newVMID = Integer.parseInt(rc.getMessage());
            System.out.println("ok, ID " + newVMID + ".");

            // We can create a representation for the new VM, using the returned
            // VM-ID
            VirtualMachine vm = new VirtualMachine(newVMID, oneClient);

            // Let's hold the VM, so the scheduler won't try to deploy it
            System.out.print("Trying to hold the new VM... ");
            rc = vm.hold();

            if(rc.isError())
            {
                System.out.println("failed!");
                throw new Exception( rc.getErrorMessage() );
            }
            else
                System.out.println("ok.");

            // And now we can request its information.
            rc = vm.info();

            if(rc.isError())
                throw new Exception( rc.getErrorMessage() );

            System.out.println();
            System.out.println(
                    "This is the information OpenNebula stores for the new VM:");
            System.out.println(rc.getMessage() + "\n");

            // This VirtualMachine object has some helpers, so we can access its
            // attributes easily (remember to load the data first using the info
            // method).
            System.out.println("The new VM " +
                    vm.getName() + " has status: " + vm.status());

            // And we can also use xpath expressions
            System.out.println("The path of the disk is");
            System.out.println( "\t" + vm.xpath("template/disk/source") );

            // Let's delete the VirtualMachine object.
            vm = null;

            // The reference is lost, but we can ask OpenNebula about the VM
            // again. This time however, we are going to use the VM pool
            VirtualMachinePool vmPool = new VirtualMachinePool(oneClient);
            // Remember that we have to ask the pool to retrieve the information
            // from OpenNebula
            rc = vmPool.info();

            if(rc.isError())
                throw new Exception( rc.getErrorMessage() );

            System.out.println(
                    "\nThese are all the Virtual Machines in the pool:");
            for ( VirtualMachine vmachine : vmPool )
            {
                System.out.println("\tID :" + vmachine.getId() +
                                   ", Name :" + vmachine.getName() );

                // Check if we have found the VM we are looking for
                if ( vmachine.getId().equals( ""+newVMID ) )
                {
                    vm = vmachine;
                }
            }

            // We have also some useful helpers for the actions you can perform
            // on a virtual machine, like cancel:
            rc = vm.cancel();
            System.out.println("\nTrying to cancel the VM " + vm.getId() +
                                " (should fail)...");

            // This is all the information you can get from the OneResponse:
            System.out.println("\tOpenNebula response");
            System.out.println("\t  Error:  " + rc.isError());
            System.out.println("\t  Msg:    " + rc.getMessage());
            System.out.println("\t  ErrMsg: " + rc.getErrorMessage());

            rc = vm.finalizeVM();
            System.out.println("\nTrying to finalize (delete) the VM " +
                                vm.getId() + "...");

            System.out.println("\tOpenNebula response");
            System.out.println("\t  Error:  " + rc.isError());
            System.out.println("\t  Msg:    " + rc.getMessage());
            System.out.println("\t  ErrMsg: " + rc.getErrorMessage());


        }
        catch (Exception e)
        {
View Full Code Here

Examples of org.opennebula.client.OneResponse

        // We will create a user pool and query some information.
        // The info method retrieves and saves internally the information
        // from OpenNebula.
        UserPool    userpool = new UserPool(oneClient);
        OneResponse rc       = userpool.info();

        // The response can be an error, in which case we have access to a
        // human-readable error message.
        if (rc.isError())
        {
            System.out.println(rc.getErrorMessage());
            return;
        }

        // Let's find out the current state of the users pool
        printUserPool(userpool);

        // Now we will try to allocate a new user
        System.out.println("Allocating new user (javaUser,javaPassword)...");
        rc = User.allocate(oneClient, "javaUser", "javaPassword");

        if (rc.isError())
        {
            System.out.println(rc.getErrorMessage());
            return;
        }

        // If the allocation was successful, then the response message contains
        // the new user's ID.
        int userID = Integer.parseInt( rc.getMessage() );
        System.out.println("The allocation request returned this ID: " + userID);

        // We can create a representation for the new user, using the returned
        // user-ID
        User javaUser = new User(userID, oneClient);

        // And request its information
        rc = javaUser.info();

        // Alternatively we could have requested the user's info with the
        // static info method:
        // rc = User.info(oneClient, userID);
        // and processed the xml returned in the message of the OneResponse.

        if (rc.isError())
        {
            System.out.println(rc.getErrorMessage());
            return;
        }

        // This is how the info returned looks like...
        System.out.println("Info for " + javaUser.xpath("name") + "...");
        System.out.println(rc.getMessage());

        // Wait a second... what was that xpath method for?
        // Now that we have the user's info loaded, we can use xpath expressions
        // without parsing and initializing any xml, as simple as
        // String name = javaUser.xpath("name");

        // The user pool information is now outdated, so we need to call the
        // info method again
        userpool.info();
        printUserPool(userpool);

        // Let's delete this new user, using its ID
        System.out.println("Deleting " + javaUser.getName() + "...");
        rc = javaUser.delete();

        if (rc.isError())
        {
            System.out.println(rc.getErrorMessage());
            return;
        }

        // Now the pool information is outdated again, it is time to reload it.
        userpool.info();
View Full Code Here

Examples of org.opennebula.client.OneResponse

     * @return If successful the message contains the string
     * with the information returned by OpenNebula.
     */
    public OneResponse info()
    {
        OneResponse response =
                xmlrpcInfo(client, infoMethod, filter, -1, -1, type());
        processInfo(response);
        return response;
    }
View Full Code Here

Examples of org.opennebula.client.OneResponse

     * @return If successful the message contains the string
     * with the information returned by OpenNebula.
     */
    public OneResponse infoAll()
    {
        OneResponse response =
                xmlrpcInfo(client, infoMethod, ALL, -1, -1, type());
        processInfo(response);
        return response;
    }
View Full Code Here

Examples of org.opennebula.client.OneResponse

     * @return If successful the message contains the string
     * with the information returned by OpenNebula.
     */
    public OneResponse infoMine()
    {
        OneResponse response =
                xmlrpcInfo(client, infoMethod, MINE, -1, -1, type());
        processInfo(response);
        return response;
    }
View Full Code Here

Examples of org.opennebula.client.OneResponse

     * @return If successful the message contains the string
     * with the information returned by OpenNebula.
     */
    public OneResponse infoGroup()
    {
        OneResponse response =
                xmlrpcInfo(client, infoMethod, MINE_GROUP, -1, -1, type());
        processInfo(response);
        return response;
    }
View Full Code Here

Examples of org.opennebula.client.OneResponse

     * @return If successful the message contains the string
     * with the information returned by OpenNebula.
     */
    public OneResponse info(int filter, int startId, int endId)
    {
        OneResponse response =
                xmlrpcInfo(client, infoMethod, filter, startId, endId, type());
        processInfo(response);
        return response;
    }
View Full Code Here

Examples of org.opennebula.client.OneResponse

     * @return If successful the message contains the string
     * with the information returned by OpenNebula.
     */
    public OneResponse info()
    {
        OneResponse response = info(client, id);
        super.processInfo(response);
        return response;
    }
View Full Code Here

Examples of org.opennebula.client.OneResponse

     * @return If successful the message contains the string
     * with the information returned by OpenNebula.
     */
    public OneResponse info()
    {
        OneResponse response = info(client, id);
        super.processInfo(response);
        return response;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.