[one-users] Java example on opennebula
rajesh kannan
asrajeshkannan at gmail.com
Tue Oct 16 21:04:22 PDT 2012
Pls Help me
Give me any changes on this program
Still i Had problem
Trying to allocate the virtual machine... failed!
[VirtualMachineAllocate] User couldn't be authenticated, aborting call.
import java.lang.*;
import java.io.*;
import org.opennebula.client.Client;
import org.opennebula.client.vm.VirtualMachine;
import org.opennebula.client.OneResponse;
import org.apache.xmlrpc.XmlRpcException;
public class vmcre
{
public static void main(String args[])
{
try
{
Client oneClient = new Client("$ONE_AUTH","$ONE_XMLRPC");
//or
//Client oneClient = new Client("oneadmin:rajesh","$ONE_XMLRPC");
//or
//Client oneClient = new
Client("/var/lib/one/.one/one_auth","http://localhost:2633/RPC2");
String vmTemplate =
"NAME = vm_from_java CPU = 0.1 MEMORY = 64\n"
+ "DISK = [\n"
+ "\tsource = \"/var/lib/one/ttylinux.img\",\n"
+ "\ttarget = \"hda\",\n"
+ "\treadonly = \"no\" ]\n"
+ "FEATURES = [ acpi=\"no\" ]";
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() );
}
int newVMID = Integer.parseInt(rc.getMessage());
System.out.println("ok, ID " + newVMID + ".");
VirtualMachine vm = new VirtualMachine(newVMID, oneClient);
System.out.print("Trying to hold the new VM... ");
rc = vm.hold();
if(rc.isError())
{
System.out.println("failed!");
throw new Exception( rc.getErrorMessage() );
}
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");
System.out.println("The new VM " +
vm.getName() + " has status: " + vm.status());
System.out.println("The path of the disk is");
System.out.println( "\t" + vm.xpath("template/disk/source") );
rc = vm.finalizeVM();
System.out.println("\nTrying to finalize (delete) the VM " +
vm.getId() + "...");
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
}
Regards
A S RAJESH KANNAN
ANNA UNIVERSITY,CEG
M.TECH(IT)
More information about the Users
mailing list