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.
static OneResponse attachdisk(Client client, int id, java.lang.String diskTemplate)
          Attaches a disk to a running VM
 OneResponse attachdisk(java.lang.String diskTemplate)
          Attaches a disk to a running VM
 OneResponse cancel()
          Cancels the running VM.
 OneResponse chgrp(int gid)
          Changes the group
static OneResponse chmod(Client client, int id, int octet)
          Changes the permissions
static OneResponse chmod(Client client, int id, int owner_u, int owner_m, int owner_a, int group_u, int group_m, int group_a, int other_u, int other_m, int other_a)
          Changes the VM permissions
static OneResponse chmod(Client client, int id, java.lang.String octet)
          Changes the permissions
 OneResponse chmod(int octet)
          Changes the permissions
 OneResponse chmod(int owner_u, int owner_m, int owner_a, int group_u, int group_m, int group_a, int other_u, int other_m, int other_a)
          Changes the VM permissions
 OneResponse chmod(java.lang.String octet)
          Changes the permissions
static OneResponse chown(Client client, int id, int uid, int gid)
          Changes the owner/group
 OneResponse chown(int uid)
          Changes the owner
 OneResponse chown(int uid, int gid)
          Changes the owner/group
 OneResponse deploy(int hostId)
          Initiates the instance of the VM on the target host.
static OneResponse detachdisk(Client client, int id, int diskId)
          Detaches a disk to a running VM
 OneResponse detachdisk(int diskId)
          Detaches a disk to a running VM
 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 monitoring()
          Retrieves the monitoring information of the given VM, in XML
static OneResponse monitoring(Client client, int id)
          Retrieves the monitoring information of the given VM, in XML
 OneResponse reboot()
          Reboots a running VM.
 OneResponse release()
          Releases a virtual machine from hold state.
 OneResponse resched()
          Sets the re-scheduling flag for the VM
 OneResponse reset()
          Resets a running VM.
 OneResponse restart()
          Forces a re-deployment of a VM in UNKNOWN or BOOT state.
 OneResponse resubmit()
          Resubmits a VM to PENDING state.
 OneResponse resume()
          Resumes the execution of a saved VM.
 OneResponse savedisk(int diskId, java.lang.String imageName)
          Sets the specified vm's disk to be saved in a new image when the VirtualMachine shutdowns.
 OneResponse savedisk(int diskId, java.lang.String imageName, java.lang.String imageType)
          Sets the specified vm's disk to be saved in a new image when the VirtualMachine shutdowns.
 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.
 OneResponse unresched()
          Unsets the re-scheduling flag for the VM
 
Methods inherited from class org.opennebula.client.PoolElement
chmod, chmod, chmod, getId, getName, gid, id, processInfo, uid, 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.

chown

public static OneResponse chown(Client client,
                                int id,
                                int uid,
                                int gid)
Changes the owner/group

Parameters:
client - XML-RPC Client.
id - The virtual machine id (vid) of the target instance.
uid - The new owner user ID. Set it to -1 to leave the current one.
gid - The new group ID. Set it to -1 to leave the current one.
Returns:
If an error occurs the error message contains the reason.

chmod

public static OneResponse chmod(Client client,
                                int id,
                                int owner_u,
                                int owner_m,
                                int owner_a,
                                int group_u,
                                int group_m,
                                int group_a,
                                int other_u,
                                int other_m,
                                int other_a)
Changes the VM permissions

Parameters:
client - XML-RPC Client.
id - The VM id of the target VM.
owner_u - 1 to allow, 0 deny, -1 do not change
owner_m - 1 to allow, 0 deny, -1 do not change
owner_a - 1 to allow, 0 deny, -1 do not change
group_u - 1 to allow, 0 deny, -1 do not change
group_m - 1 to allow, 0 deny, -1 do not change
group_a - 1 to allow, 0 deny, -1 do not change
other_u - 1 to allow, 0 deny, -1 do not change
other_m - 1 to allow, 0 deny, -1 do not change
other_a - 1 to allow, 0 deny, -1 do not change
Returns:
If an error occurs the error message contains the reason.

chmod

public static OneResponse chmod(Client client,
                                int id,
                                java.lang.String octet)
Changes the permissions

Parameters:
client - XML-RPC Client.
id - The id of the target object.
octet - Permissions octed , e.g. 640
Returns:
If an error occurs the error message contains the reason.

chmod

public static OneResponse chmod(Client client,
                                int id,
                                int octet)
Changes the permissions

Parameters:
client - XML-RPC Client.
id - The id of the target object.
octet - Permissions octed , e.g. 640
Returns:
If an error occurs the error message contains the reason.

monitoring

public static OneResponse monitoring(Client client,
                                     int id)
Retrieves the monitoring information of the given VM, in XML

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 monitoring information returned by OpenNebula.

attachdisk

public static OneResponse attachdisk(Client client,
                                     int id,
                                     java.lang.String diskTemplate)
Attaches a disk to a running VM

Parameters:
client - XML-RPC Client.
id - The virtual machine id (vid) of the target instance.
diskTemplate - Template containing the new DISK definition
Returns:
If an error occurs the error message contains the reason.

detachdisk

public static OneResponse detachdisk(Client client,
                                     int id,
                                     int diskId)
Detaches a disk to a running VM

Parameters:
client - XML-RPC Client.
id - The virtual machine id (vid) of the target instance.
diskId - The DISK_ID of the disk to detach
Returns:
If an error occurs the error message contains the reason.

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", "reboot", "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.

savedisk

public OneResponse savedisk(int diskId,
                            java.lang.String imageName)
Sets the specified vm's disk to be saved in a new image when the VirtualMachine shutdowns.

Parameters:
diskId - ID of the disk to be saved.
imageName - Name of the new Image that will be created.
Returns:
If an error occurs the error message contains the reason.

savedisk

public OneResponse savedisk(int diskId,
                            java.lang.String imageName,
                            java.lang.String imageType)
Sets the specified vm's disk to be saved in a new image when the VirtualMachine shutdowns.

Parameters:
diskId - ID of the disk to be saved.
imageName - Name of the new Image that will be created.
imageType - Type of the new image. Set to empty string to use the default type
Returns:
If an error occurs the error message contains the reason.

chown

public OneResponse chown(int uid,
                         int gid)
Changes the owner/group

Parameters:
uid - The new owner user ID. Set it to -1 to leave the current one.
gid - The new group ID. Set it to -1 to leave the current one.
Returns:
If an error occurs the error message contains the reason.

chown

public OneResponse chown(int uid)
Changes the owner

Parameters:
uid - The new owner user ID.
Returns:
If an error occurs the error message contains the reason.

chgrp

public OneResponse chgrp(int gid)
Changes the group

Parameters:
gid - The new group ID.
Returns:
If an error occurs the error message contains the reason.

chmod

public OneResponse chmod(int owner_u,
                         int owner_m,
                         int owner_a,
                         int group_u,
                         int group_m,
                         int group_a,
                         int other_u,
                         int other_m,
                         int other_a)
Changes the VM permissions

Parameters:
owner_u - 1 to allow, 0 deny, -1 do not change
owner_m - 1 to allow, 0 deny, -1 do not change
owner_a - 1 to allow, 0 deny, -1 do not change
group_u - 1 to allow, 0 deny, -1 do not change
group_m - 1 to allow, 0 deny, -1 do not change
group_a - 1 to allow, 0 deny, -1 do not change
other_u - 1 to allow, 0 deny, -1 do not change
other_m - 1 to allow, 0 deny, -1 do not change
other_a - 1 to allow, 0 deny, -1 do not change
Returns:
If an error occurs the error message contains the reason.

chmod

public OneResponse chmod(java.lang.String octet)
Changes the permissions

Parameters:
octet - Permissions octed , e.g. 640
Returns:
If an error occurs the error message contains the reason.

chmod

public OneResponse chmod(int octet)
Changes the permissions

Parameters:
octet - Permissions octed , e.g. 640
Returns:
If an error occurs the error message contains the reason.

monitoring

public OneResponse monitoring()
Retrieves the monitoring information of the given VM, in XML

Returns:
If successful the message contains the string with the monitoring information returned by OpenNebula.

attachdisk

public OneResponse attachdisk(java.lang.String diskTemplate)
Attaches a disk to a running VM

Parameters:
diskTemplate - Template containing the new DISK definition
Returns:
If an error occurs the error message contains the reason.

detachdisk

public OneResponse detachdisk(int diskId)
Detaches a disk to a running VM

Parameters:
diskId - The DISK_ID of the disk to detach
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.

reboot

public OneResponse reboot()
Reboots a running VM.

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

reset

public OneResponse reset()
Resets a running 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()
Forces a re-deployment of a VM in UNKNOWN or BOOT state.

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

resubmit

public OneResponse resubmit()
Resubmits a VM to PENDING state.

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

resched

public OneResponse resched()
Sets the re-scheduling flag for the VM

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

unresched

public OneResponse unresched()
Unsets the re-scheduling flag for the VM

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-2012 © OpenNebula Project Leads (OpenNebula.org).