<div>package javaapplication1;</div><div><br></div><div><br></div><div><br></div><div>/**</div><div> *</div><div> * @author ubuntu</div><div> */</div><div><br></div><div>import java.util.logging.Level;</div><div>import java.util.logging.Logger;</div>
<div>import org.opennebula.client.*;</div><div>import org.opennebula.client.vm.*;</div><div><br></div><div> </div><div>public class JavaApplication1 {</div><div><br></div><div>// First of all, a Client object has to be created.</div>
<div>// Here the client will try to connect to OpenNebula using the default</div><div>// options: the auth. file will be assumed to be at $ONE_AUTH, and the</div><div>// endpoint will be set to the environment variable $ONE_XMLRPC.</div>
<div>static Client oneClient;</div><div> </div><div>public static void main(String args[])</div><div>{</div><div>try</div><div>{</div><div> oneClient = new Client();</div><div> </div><div> // This VM template is a valid one, but it will probably fail to run</div>
<div> // if we try to deploy it; the path for the image is unlikely to</div><div> // exist.</div><div> String vmTemplate =</div><div> "NAME = vm_from_java CPU = 0.1 MEMORY = 64\n"</div>
<div> + "DISK = [\n"</div><div> + "\tsource = \"/home/ubuntu/ubuntu-10.04.4-desktop-i386.iso\",\n"</div><div> + "\ttarget = \"hda\",\n"</div><div>
+ "\treadonly = \"no\" ]\n"</div><div> + "FEATURES = [ acpi=\"no\" ]";</div><div> </div><div> System.out.print("Trying to allocate the virtual machine... ");</div>
<div> OneResponse rc = VirtualMachine.allocate(oneClient, vmTemplate);</div><div> </div><div> if( rc.isError() )</div><div> {</div><div> System.out.println( "failed!");</div><div> throw new Exception( rc.getErrorMessage() );</div>
<div> }</div><div> </div><div> // The response message is the new VM's ID</div><div> int newVMID = Integer.parseInt(rc.getMessage());</div><div> System.out.println("ok, ID " + newVMID + ".");</div>
<div> </div><div> // We can create a representation for the new VM, using the returned</div><div> // VM-ID</div><div> VirtualMachine vm = new VirtualMachine(newVMID, oneClient);</div><div> </div><div> // Let's hold the VM, so the scheduler won't try to deploy it</div>
<div> System.out.print("Trying to hold the new VM... ");</div><div> rc = vm.hold();</div><div> </div><div> if(rc.isError())</div><div> {</div><div> System.out.println("failed!");</div>
<div> throw new Exception( rc.getErrorMessage() );</div><div> }</div><div> </div><div> // And now we can request its information.</div><div> rc = <a href="http://vm.info">vm.info</a>();</div><div> </div><div>
if(rc.isError())</div><div> throw new Exception( rc.getErrorMessage() );</div><div> </div><div> System.out.println();</div><div> System.out.println(</div><div> "This is the information OpenNebula stores for the new VM:");</div>
<div> System.out.println(rc.getMessage() + "\n");</div><div> </div><div> // This VirtualMachine object has some helpers, so we can access its</div><div> // attributes easily (remember to load the data first using the info</div>
<div> // method).</div><div> System.out.println("The new VM " +</div><div> vm.getName() + " has status: " + vm.status());</div><div> </div><div> // And we can also use xpath expressions</div>
<div> System.out.println("The path of the disk is");</div><div> System.out.println( "\t" + vm.xpath("template/disk/source") );</div><div> </div><div> // We have also some useful helpers for the actions you can perform</div>
<div> // on a virtual machine, like cancel or finalize:</div><div> </div><div> rc = vm.finalizeVM();</div><div> System.out.println("\nTrying to finalize (delete) the VM " +</div><div> vm.getId() + "...");</div>
<div> </div><div>}</div><div>catch (Exception e)</div><div>{</div><div> System.out.println(e.getMessage());</div><div>}</div><div>}</div><div>}</div><div><br></div><div>after executing this in root but it is giving an error that "ONE_AUTH file not present..</div>
<div>plz tell me I am doing right or wrong because I just installed netbeans on that system and added org.opennebula.client.jar and running above apps.</div><div>how it will interact with opennebula???</div>-- <br>----------------------------<br>
Regards,<br>Bhupendra Kumar Teli<br>M. Tech(IT)<br>11536007<br>IIT Roorkee<br>+91-8439869004<br>