OpenNebula
Cloud API

org.opennebula.client.vm
Class VirtualMachine

java.lang.Object
  extended by org.opennebula.client.PoolElement
      extended by org.opennebula.client.vm.VirtualMachine

public class VirtualMachine
extends PoolElement

This class represents an OpenNebula VM. It also offers static XML-RPC call wrappers.


Field Summary
 
Fields inherited from class org.opennebula.client.PoolElement
client, id, xml, xpath
 
Constructor Summary
  VirtualMachine(int id, Client client)
          Creates a new VM representation.
protected VirtualMachine(org.w3c.dom.Node xmlElement, Client client)
           
 
Method Summary
protected  OneResponse action(java.lang.String action)
          Submits an action to be performed on the virtual machine.
static OneResponse allocate(Client client, java.lang.String description)
          Allocates a new VM in OpenNebula.
 OneResponse cancel()
          Cancels the running VM.
 OneResponse deploy(int hostId)
          Initiates the instance of the VM on the target host.
 OneResponse finalizeVM()
          Deletes the VM from the pool and database.
 OneResponse hold()
          Sets the VM to hold state.
 OneResponse info()
          Loads the xml representation of the virtual machine.
static OneResponse info(Client client, int id)
          Retrieves the information of the given VM.
 int lcmState()
          Returns the LCM state of the VirtualMachine (numeric value).
 java.lang.String lcmStateStr()
          Returns the LCM state of the VirtualMachine (string value).
 OneResponse liveMigrate(int hostId)
          Performs a live migration of the virtual machine to the target host (hid).
 OneResponse migrate(int hostId)
          Migrates the virtual machine to the target host (hid).
 OneResponse migrate(int hostId, boolean live)
          Migrates the virtual machine to the target host (hid).
 OneResponse release()
          Releases a virtual machine from hold state.
 OneResponse restart()
          Resubmits the virtual machine after failure.
 OneResponse resume()
          Resumes the execution of a saved VM.
 OneResponse shutdown()
          Shuts down the already deployed VM.
 int state()
          Performs an xpath evaluation for the "state" expression.
 java.lang.String stateStr()
          Returns the VM state of the VirtualMachine (string value).
 java.lang.String status()
          Returns the short status string for the VirtualMachine.
 OneResponse stop()
          Stops the virtual machine.
 OneResponse suspend()
          Suspends the virtual machine.
 
Methods inherited from class org.opennebula.client.PoolElement
getId, getName, processInfo, xpath
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VirtualMachine

public VirtualMachine(int id,
                      Client client)
Creates a new VM representation.

Parameters:
id - The virtual machine Id (vid).
client - XML-RPC Client.

VirtualMachine

protected VirtualMachine(org.w3c.dom.Node xmlElement,
                         Client client)
See Also:
PoolElement
Method Detail

allocate

public static OneResponse allocate(Client client,
                                   java.lang.String description)
Allocates a new VM in OpenNebula.

Parameters:
client - XML-RPC Client.
description - A string containing the template of the vm.
Returns:
If successful the message contains the associated id generated for this VM.

info

public static OneResponse info(Client client,
                               int id)
Retrieves the information of the given VM.

Parameters:
client - XML-RPC Client.
id - The virtual machine id (vid) of the target instance.
Returns:
If successful the message contains the string with the information returned by OpenNebula.

info

public OneResponse info()
Loads the xml representation of the virtual machine. The info is also stored internally.

See Also:
info(Client, int)

deploy

public OneResponse deploy(int hostId)
Initiates the instance of the VM on the target host.

Parameters:
hostId - The host id (hid) of the target host where the VM will be instantiated.
Returns:
If an error occurs the error message contains the reason.

action

protected OneResponse action(java.lang.String action)
Submits an action to be performed on the virtual machine.
It is recommended to use the helper methods instead:

Parameters:
action - The action name to be performed, can be:
"shutdown", "hold", "release", "stop", "cancel", "suspend", "resume", "restart", "finalize".
Returns:
If an error occurs the error message contains the reason.

migrate

public OneResponse migrate(int hostId,
                           boolean live)
Migrates the virtual machine to the target host (hid).

Parameters:
hostId - The target host id (hid) where we want to migrate the vm.
live - If true we are indicating that we want livemigration, otherwise false.
Returns:
If an error occurs the error message contains the reason.

shutdown

public OneResponse shutdown()
Shuts down the already deployed VM.

Returns:
If an error occurs the error message contains the reason.

cancel

public OneResponse cancel()
Cancels the running VM.

Returns:
If an error occurs the error message contains the reason.

hold

public OneResponse hold()
Sets the VM to hold state. The VM will not be scheduled until it is released.

Returns:
If an error occurs the error message contains the reason.

release

public OneResponse release()
Releases a virtual machine from hold state.

Returns:
If an error occurs the error message contains the reason.

stop

public OneResponse stop()
Stops the virtual machine. The virtual machine state is transferred back to OpenNebula for a possible reschedule.

Returns:
If an error occurs the error message contains the reason.

suspend

public OneResponse suspend()
Suspends the virtual machine. The virtual machine state is left in the cluster node for resuming.

Returns:
If an error occurs the error message contains the reason.

resume

public OneResponse resume()
Resumes the execution of a saved VM.

Returns:
If an error occurs the error message contains the reason.

finalizeVM

public OneResponse finalizeVM()
Deletes the VM from the pool and database.

Returns:
If an error occurs the error message contains the reason.

restart

public OneResponse restart()
Resubmits the virtual machine after failure.

Returns:
If an error occurs the error message contains the reason.

migrate

public OneResponse migrate(int hostId)
Migrates the virtual machine to the target host (hid).
It does the same as migrate(int, boolean) with live set to false.

Parameters:
hostId - The target host id (hid) where we want to migrate the vm.
Returns:
If an error occurs the error message contains the reason.

liveMigrate

public OneResponse liveMigrate(int hostId)
Performs a live migration of the virtual machine to the target host (hid).
It does the same as migrate(int, boolean) with live set to true.

Parameters:
hostId - The target host id (hid) where we want to migrate the vm.
Returns:
If an error occurs the error message contains the reason.

state

public int state()
Description copied from class: PoolElement
Performs an xpath evaluation for the "state" expression.

Overrides:
state in class PoolElement
Returns:
The value of the STATE element.

stateStr

public java.lang.String stateStr()
Returns the VM state of the VirtualMachine (string value).

Returns:
The VM state of the VirtualMachine (string value).

lcmState

public int lcmState()
Returns the LCM state of the VirtualMachine (numeric value).

Returns:
The LCM state of the VirtualMachine (numeric value).

lcmStateStr

public java.lang.String lcmStateStr()
Returns the LCM state of the VirtualMachine (string value).

Returns:
The LCM state of the VirtualMachine (string value).

status

public java.lang.String status()
Returns the short status string for the VirtualMachine.

Returns:
The short status string for the VirtualMachine.

OpenNebula
Cloud API

Visit OpenNebula.org
Copyright 2002-2010 © OpenNebula Project Leads (OpenNebula.org).