Class XenClient.MachineOperations
Implements the XenClient virtual machine operations.
Namespace: Neon.XenServer
Assembly: Neon.XenServer.dll
Syntax
public class XenClient.MachineOperations
Methods
AddDisk(XenVirtualMachine, XenVirtualDisk)
Adds a new disk to a virtual machine.
note
The virtual machine must be stopped.
Declaration
public void AddDisk(XenVirtualMachine virtualMachine, XenVirtualDisk disk)
Parameters
Type | Name | Description |
---|---|---|
XenVirtualMachine | virtualMachine | The target virtual machine. |
XenVirtualDisk | disk | The disk information. |
Create(string, string, int, long, long, bool, IEnumerable<XenVirtualDisk>, string, string)
Creates a virtual machine from a template, optionally initializing its memory and disk size.
note
This does not start the machine.
Declaration
public XenVirtualMachine Create(string name, string templateName, int vcpus = 2, long memoryBytes = 0, long diskBytes = 0, bool snapshot = false, IEnumerable<XenVirtualDisk> extraDisks = null, string primaryStorageRepository = "Local storage", string extraStorageRespository = "Local storage")
Parameters
Type | Name | Description |
---|---|---|
string | name | Name for the new virtual machine. |
string | templateName | Identifies the template. |
int | vcpus | Optionally specifies the number of CPU cores to be assigned. This defaults to 2. |
long | memoryBytes | Optionally specifies the memory assigned to the machine (overriding the template). |
long | diskBytes | Optionally specifies the primary disk size (overriding the template). |
bool | snapshot | Optionally specifies that the virtual machine should snapshot the template. This defaults to |
IEnumerable<XenVirtualDisk> | extraDisks | Optionally specifies any additional virtual disks to be created and then attached to the new virtual machine. |
string | primaryStorageRepository | Optionally specifies the storage repository where the virtual machine's primary disk will be created. This defaults to Local storage. |
string | extraStorageRespository | Optionally specifies the storage repository where any extra disks for the virtual machine will be created. This defaults to Local storage. noteThe default value assumes that your XenServer pool is NOT CONFIGURED FOR HA. Auto start VMs are not recommended for HA pools due to potential conflicts. We're not sure what problems having autostart VMs in a HA pool cause. |
Returns
Type | Description |
---|---|
XenVirtualMachine | The new XenVirtualMachine. |
Remarks
note
snapshot
is ignored if the virtual machine template is not
hosted by the same storage repository where the virtual machine is to be created.
Exceptions
Type | Condition |
---|---|
XenException | Thrown if the operation failed. |
DiskCount(XenVirtualMachine)
Returns the number of disks attached to a virtual machine.
Declaration
public int DiskCount(XenVirtualMachine virtualMachine)
Parameters
Type | Name | Description |
---|---|---|
XenVirtualMachine | virtualMachine | The target virtual machine. |
Returns
Type | Description |
---|---|
int | The number of attached disks. |
Find(string, string)
Finds a specific virtual machine by name or unique ID.
Declaration
public XenVirtualMachine Find(string name = null, string uuid = null)
Parameters
Type | Name | Description |
---|---|---|
string | name | Specifies the target name. |
string | uuid | Specifies the target unique ID. |
Returns
Type | Description |
---|---|
XenVirtualMachine | The named item or |
Remarks
note
One of name
or uuid
must be specified.
Exceptions
Type | Condition |
---|---|
XenException | Thrown if the operation failed. |
List()
Lists the XenServer virtual machines.
Declaration
public List<XenVirtualMachine> List()
Returns
Type | Description |
---|---|
List<XenVirtualMachine> | The list of virtual machines. |
Remarks
note
Only virtual machines with names will be returned with the assumption that unnamed VMs are XenServer infrastructure related.
Exceptions
Type | Condition |
---|---|
XenException | Thrown if the operation failed. |
Reboot(XenVirtualMachine, bool)
Reboots a virtual machine.
Declaration
public void Reboot(XenVirtualMachine virtualMachine, bool force = false)
Parameters
Type | Name | Description |
---|---|---|
XenVirtualMachine | virtualMachine | The target virtual machine. |
bool | force | Optionally forces the virtual machine to reboot. |
Exceptions
Type | Condition |
---|---|
XenException | Thrown if the operation failed. |
Remove(XenVirtualMachine, bool)
Removes a virtual machine and its drives.
Declaration
public void Remove(XenVirtualMachine virtualMachine, bool keepDrives = false)
Parameters
Type | Name | Description |
---|---|---|
XenVirtualMachine | virtualMachine | The target virtual machine. |
bool | keepDrives | Optionally retains the VM disks. |
Shutdown(XenVirtualMachine, bool)
Shuts down a virtual machine.
Declaration
public void Shutdown(XenVirtualMachine virtualMachine, bool turnOff = false)
Parameters
Type | Name | Description |
---|---|---|
XenVirtualMachine | virtualMachine | The target virtual machine. |
bool | turnOff | Optionally just turns the VM off without performing a graceful shutdown first. noteWARNING! This could result in the loss of unsaved data. |
Exceptions
Type | Condition |
---|---|
XenException | Thrown if the operation failed. |
Start(XenVirtualMachine)
Starts a stopped virtual machine resumes a suspended or paused virtual machine. This does nothing when the virtual machine is already running.
Declaration
public void Start(XenVirtualMachine virtualMachine)
Parameters
Type | Name | Description |
---|---|---|
XenVirtualMachine | virtualMachine | The target virtual machine. |
Exceptions
Type | Condition |
---|---|
XenException | Thrown if the operation failed. |
Suspend(XenVirtualMachine)
Suspends a virtual machine by persisting its memory to disk and stopping the virtual machine so that it can be restarted where it left off later.
Declaration
public void Suspend(XenVirtualMachine virtualMachine)
Parameters
Type | Name | Description |
---|---|---|
XenVirtualMachine | virtualMachine | The target virtual machine. |
Exceptions
Type | Condition |
---|---|
XenException | Thrown if the operation failed. |