Virtual Machine Template

A template file consists of a set of attributes that defines a Virtual Machine. Using the command onetemplate create, a template can be registered in OpenNebula to be instantiated later. For compatibility with previous versions, you can also create a new Virtual Machine directly from a template file by using the onevm create command.

Syntax

The syntax of the template file is as follows:

  • Anything behind the pound or hash sign # is a comment.
  • Strings are delimited with double quotes ", if a double quote is part of the string it needs to be escaped \\".
  • Single Attributes are in the form:
NAME=VALUE
  • Vector Attributes that contain several values can be defined as follows:
NAME=[NAME1=VALUE1,NAME2=VALUE2]
  • Vector Attributes must contain at least one value.
  • Attribute names are case insensitive, in fact the names are converted to uppercase internally.

XML Syntax

Template files can be expressed in XML, with the following syntax:

  • The root element must be TEMPLATE.
  • Single Attributes are in the form:
<NAME>VALUE</NAME>
  • Vector Attributes that contain several values can be defined as follows:
<NAME>
  <NAME1>VALUE1</NAME1>
  <NAME2>VALUE2</NAME2>
</NAME>

A simple example:

<TEMPLATE>
  <NAME>test_vm</NAME>
  <CPU>2</CPU>
  <MEMORY>1024</MEMORY>
  <DISK>
    <IMAGE_ID>2</IMAGE_ID>
  </DISK>
  <DISK>
    <IMAGE>Data</IMAGE>
    <IMAGE_UNAME>oneadmin</IMAGE_UNAME>
  </DISK>
</TEMPLATE>

Capacity Section

The following attributes can be defined to specify the capacity of a VM.

AttributeDescriptionMandatory
NAMEName that the VM will get for description purposes. If NAME is not supplied a name generated by one will be in the form of one-<VID>. NOTE: When defining a template it is the name of the VM template. The actual name of the VM will be set when the VM template is instantiated.YES For Templates NO For VMs - will be set to one- if omitted
MEMORYAmount of RAM required for the VM, in Megabytes.YES
CPUPercentage of CPU divided by 100 required for the Virtual Machine, half a processor is written 0.5. This value is used by OpenNebula and the scheduler to guide the Host overcommitment.YES
VCPUNumber of virtual CPUs. This value is optional, the default hypervisor behavior is used, usually one virtual CPU.YES - will be set to 1 if omitted, this can be changed in the driver configuration

For example:

NAME   = test-vm
MEMORY = 128
CPU    = 1

Hotplug Resize VM Capacity

If you need to resize the capacity in RUNNING state you have to set up some extra attributes in the VM template. These attributes must be set before the VM is started. They are driver-specific, here you can find more info for KVM.

Showback Section

The following attributes can be defined to set the cost of a VM. Read the showback documentation for more information.

AttributeDescriptionMandatory
MEMORY_COSTCost of each memory MB per hour.NO
CPU_COSTCost of each CPU per hour.NO
DISK_COSTCost of each disk MB per hour.NO

OS and Boot Options Section

The operating system is defined with the OS vector attribute. The following sub-attributes are supported:

OS Sub-AttributeDescriptionKVMLXC
ARCHCPU architecture to virtualize.M (default i686)-
MACHINElibvirt machine type. Check libvirt capabilities for the list of available machine types.O-
KERNELpath to the OS kernel to boot the image in the Host.O-
KERNEL_DSimage to be used as kernel (see !!)O-
INITRDpath to the initrd image in the Host.O (for kernel)-
INITRD_DSimage to be used as ramdisk (see !!)O (for kernel)-
ROOTdevice to be mounted as root.O (for kernel)-
KERNEL_CMDarguments for the booting kernel.O (for kernel)-
BOOTLOADERpath to the bootloader executable.O-
BOOTcomma-separated list of boot devices types, by order of preference (first device in the list is the first device used for boot). Possible values: disk#,nic#.MO
SD_DISK_BUSbus for disks with sd prefix, either scsi or sata. If attribute is missing, libvirt chooses itself.O-
UUIDunique ID of the VM. It’s referenced as machine ID inside the VM. Could be used to force ID for licensing purposes.O-
FIRMWAREfirmware type or firmware path. Possible values: BIOS, UEFI or path.O-
FIRMWARE_SECUREenable Secure Boot. Possible values: true, false.O-

(!!) Use one of KERNEL_DS or KERNEL (and INITRD or INITRD_DS).

KERNEL_DS and INITRD_DS refer to an image registered in a File Datastore and must be of type KERNEL and RAMDISK, respectively. The image should be referred to using one of the following:

  • $FILE[IMAGE=<image name>], to select the user’s own files.
  • $FILE[IMAGE=<image name>, <IMAGE_UNAME|IMAGE_UID>=<owner name|owner id>], to select images owned by other users, by user name or uid.
  • $FILE[IMAGE_ID=<image id>], global file selection.

Here’s an example of a VM booting from sda1 with kernel /vmlinuz:

OS = [ KERNEL     = /vmlinuz,
       INITRD     = /initrd.img,
       ROOT       = sda1,
       KERNEL_CMD = "ro console=tty1"]
OS = [ KERNEL_DS  = "$FILE[IMAGE=\"kernel 3.6\"]",
       INITRD_DS  = "$FILE[IMAGE=\"initrd 3.6\"]",
       ROOT       = sda1,
       KERNEL_CMD = "ro console=tty1"]

CPU_MODEL Options Section

This section (CPU_MODEL) configures the hardware configuration of the CPU exposed to the guest.

Sub-AttributeDescriptionKVMLXC
MODELThe CPU model exposed to the guest. Host-passthrough is the same model as the Host. Available modes are stored in the Host information and obtained through monitor.O-
FEATURESThe CPU features required by the guest. This a comma-separated list of values of the CPU features in a Virtual Machine. Available features are stored in the Host information and obtained through monitor.O-

Features Section

This section configures the features enabled for the VM.

Sub-AttributeDescriptionKVMLXC
PAEPhysical address extension mode allows 32-bit guests to address more than 4 GB of memory.O-
ACPIUseful for power management, for example, with KVM guests it is required for graceful shutdown to work.O-
APICEnables the advanced programmable IRQ management. Useful for SMP machines.O-
LOCALTIMEThe guest clock will be synchronized to the Host’s configured timezone when booted. Useful for Windows VMs.O-
HYPERVAdd hyperv extensions to the VM. The options can be configured in the driver configuration, HYPERV_OPTIONS. Also, timers as configured in HYPERV_TIMERS are added to the domain clock.O-
GUEST_AGENTEnables the QEMU Guest Agent communication. This only creates the socket inside the VM, the Guest Agent itself must be installed and started in the VM.O-
VIRTIO_SCSI_QUEUESNumber of queues for the virtio-scsi controller.O-
VIRTIO_BLK_QUEUESNumber of dispatch queues for the virtio-blk driver.O-
IOTHREADSNumber of iothreads for virtio disks. By default threads will be assigned to disk by round robin algorithm. Disk thread id can be forced by disk IOTHREAD attribute.O-

When setting up the virtio-scsi or virtio-blk queues, you can use the keyword auto which defaults to the number of vCPUs defined in the Virtual Machine. Also, the virtio-blk queues can be overridden per DISK so you can enable the multi-queue feature for the selected disks only.

FEATURES = [
    PAE = "yes",
    ACPI = "yes",
    APIC = "no",
    GUEST_AGENT = "yes",
    VIRTIO_SCSI_QUEUES = "auto"
    VIRTIO_BLK_QUEUES = "auto"
]

Disks Section

The disks of a VM are defined with the DISK vector attribute. You can define as many DISK attributes as you need. There are three types of disks:

  • Persistent disks, uses an Image registered in a Datastore mark as persistent.
  • Clone disks, uses an Image registered in a Datastore. Changes to the Images will be discarded. A clone disk can be saved as other Image.
  • Volatile disks, created on-the-fly on the target Hosts. Disks are disposed when the VM is shut down and cannot be saved_as.

Persistent and Clone Disks

DISK Sub-AttributeDescriptionKVMLXC
IMAGE_IDID of the Image to use.M (no IMAGE)M (no IMAGE)
IMAGEName of the Image to use.M (no IMAGE_ID)M (no IMAGE_ID)
IMAGE_UIDTo select the Image of a given user by its ID.OO
IMAGE_UNAMETo select the Image of a given user by its NAME.OO
DEV_PREFIXPrefix for the emulated device this Image will be mounted at. For instance, attribute of the Image will be used.O-
TARGETDevice to map Image disk. If set, it will overwrite the default device hd, sd, or vd for KVM virtio. If omitted, the dev_prefix mapping.OO (where to mount the Image inside the container e.g.: /mnt. Only applies for non-root devices)
DRIVERSpecific Image mapping driver.O e.g.: raw, qcow2
CACHESelects the cache mechanism for the disk. Values are default, none, writethrough, writeback, directsync and unsafe. More info in the libvirt documentation.OO (Only for qcow2 disks)
READONLYSet how the Image is exposed by the hypervisor.O e.g.: yes, no. This attribute should only be used for special storage configurationsO
IOSet IO policy. Values are threads, native.O (Needs qemu 1.1)-
IOTHREADIothread id used by this disk. Default is round robin. Can be used only if IOTHREADS > 0.O (Needs qemu 2.1)-
VIRTIO_BLK_QUEUESNumber of queues for the virtio-blk driver. It can be set for all disks, through the FEATURES attributeO (Needs qemu 2.1)-
TOTAL_BYTES_SEC, READ_BYTES_SEC, WRITE_BYTES_SEC, TOTAL_IOPS_SEC, READ_IOPS_SEC, WRITE_IOPS_SECIO throttling attributes for the disk. They are specified in bytes or IOPS (IO Operations) and can be specified for the total (read+write) or specific for read or write. Total and read or write can not be used at the same time. By default these parameters are only allowed to be used by oneadmin.O (Needs qemu 1.1)O
TOTAL_BYTES_SEC_MAX, READ_BYTES_SEC_MAX, WRITE_BYTES_SEC_MAX, TOTAL_IOPS_SEC_MAX, READ_IOPS_SEC_MAX, WRITE_IOPS_SEC_MAXMaximum IO throttling attributes for the disk. They are specified in bytes or IOPS (IO Operations) and can be specified for the total (read+write) or specific for read or write. Total and read or write can not be used at the same time. By default these parameters are only allowed to be used by oneadmin.O (Needs qemu 1.1)O
TOTAL_BYTES_SEC_MAX_LENGTH, READ_BYTES_SEC_MAX_LENGTH, WRITE_BYTES_SEC_MAX_LENGTH, TOTAL_IOPS_SEC_MAX_LENGTH, READ_IOPS_SEC_MAX_LENGTH, WRITE_IOPS_SEC_MAX_LENGTHMaximum length IO throttling attributes for the disk. They are specified in bytes or IOPS (IO Operations) and can be specified for the total (read+write) or specific for read or write. Total and read or write can not be used at the same time. By default these parameters are only allowed to be used by oneadmin.O (Needs qemu 1.1)O
SIZE_IOPS_SECSize of IOPS throttling for the disk. This attribute is effective only if one of the TOTAL_IOPS_SEC, READ_IOPS_SEC, WRITE_IOPS_SEC is defined. By default this parameter is only allowed to be used by oneadmin.O (Needs qemu 1.7)-
DISK_TYPEThis is the type of the supporting media for the image. Values: a block device (BLOCK), an ISO-9660 file or readonly block device (CDROM), or a plain file (FILE)OO
DISCARDControls what’s done with with trim commands to the disk, the values can be ignore or discard.O (only with virtio-scsi)-
SERIALIf present, a serial number will be added to virtual hard drive. If set to auto, the serial number will be generated automatically. (<vm_id>-<disk_id>) If set to a specific value, that value will be used as the serial number.O-

Volatile DISKS

DISK Sub-AttributeDescriptionKVM
TYPEType of the disk: swap or fs.O
SIZEsize in MB.O
FORMATFormat of the Image: raw or qcow2.M(for fs)
DEV_PREFIXPrefix for the emulated device this image will be mounted at. For instance, hd, sd. If omitted, the default dev_prefix set in oned.conf will be used.O
TARGETdevice to map disk.O
DRIVERspecial disk mapping options. KVM: raw, qcow2.O
CACHESelects the cache mechanism for the disk. Values are default, none, writethrough, writeback, directsync and unsafe. More info in the libvirt documentation.O
READONLYSet how the image is exposed by the hypervisor.O e.g.: yes, no. This attribute should only be used for special storage configurations
IOSet IO policy. Values are threads, native.O
TOTAL_BYTES_SEC, READ_BYTES_SEC, WRITE_BYTES_SEC, TOTAL_IOPS_SEC, READ_IOPS_SEC, WRITE_IOPS_SEC, SIZE_IOPS_SECIO throttling attributes for the disk. They are specified in bytes or IOPS (IO Operations) and can be specified for the total (read+write) or specific for read or write. Total and read or write can not be used at the same time. By default these parameters are only allowed to be used by oneadmin.O
SERIALIf present, a serial number will be added to virtual hard drive. If set to auto, the serial number will be generated automatically. (<vm_id>-<disk_id>) If set to a specific value, that value will be used as the serial number.O

Disks Device Mapping

If the TARGET attribute is not set for a disk, OpenNebula will automatically assign it using the following precedence, starting with dev_prefix + a:

  • First OS type Image.
  • Contextualization CDROM.
  • CDROM type Images.
  • The rest of DATABLOCK and OS Images, and Volatile disks.

Please visit the guide for managing images and the image template reference to learn more about the different image types.

You can find a complete description of the contextualization features in the contextualization guide.

The default device prefix sd can be changed to hd or other prefix that suits your virtualization hypervisor requirements. You can find more information in the daemon configuration guide.

This a sample section for disks. There are four disks using the image repository, and two volatile ones. Note that fs and swap are generated on-the-fly:

# First OS image, will be mapped to sda. Use image with ID 2
DISK = [ IMAGE_ID  = 2 ]

# First DATABLOCK image, mapped to sdb.
# Use the Image named Data, owned by the user named oneadmin.
DISK = [ IMAGE        = "Data",
         IMAGE_UNAME  = "oneadmin" ]

# Second DATABLOCK image, mapped to sdc
# Use the Image named Results owned by user with ID 7.
DISK = [ IMAGE        = "Results",
         IMAGE_UID    = 7 ]

# Third DATABLOCK image, mapped to sdd
# Use the Image named Experiments owned by user instantiating the VM.
DISK = [ IMAGE        = "Experiments" ]

# Volatile filesystem disk, sde
DISK = [ TYPE   = fs,
         SIZE   = 4096,
         FORMAT = ext3 ]

# swap, sdf
DISK = [ TYPE     = swap,
         SIZE     = 1024 ]

Because this VM did not declare a CONTEXT or any disk using a CDROM Image, the first DATABLOCK found is placed right after the OS Image, in sdb. For more information on Image management and moving please check the Storage guide.

Network Section

NIC Sub-AttributeDescriptionKVMLXC
NETWORK_IDID of the network to attach this device, as defined by onevnet. Use if no NETWORK.M (No NETWORK)M (No NETWORK)
NETWORKName of the network to use (of those owned by user). Use if no NETWORK_ID.M (No NETWORK_ID)M (No NETWORK_ID)
NETWORK_UIDTo select the NETWORK of a given user by its ID.OO
NETWORK_UNAMETo select the NETWORK of a given user by its NAME.OO
IPRequest a specific IP from the NETWORK.OO
MACRequest a specific HW address from the network interface.OO
BRIDGEName of the bridge the network device is going to be attached to.OO
TARGETName for the tun device created for the VM.OO
SCRIPTName of a shell script to be executed after creating the tun device for the VM.OO
MODELHardware that will emulate this network interface. In KVM you can choose virtio to select its specific virtualization IO framework.O-
FILTERTo define a network filtering rule for the interface.OO
SECURITY_GROUPSCommand-separated list of the ids of the security groups to be applied to this interface.O-
INBOUND_AVG_BWAverage bitrate for the interface in kilobytes/second for inbound traffic.OO
INBOUND_PEAK_BWMaximum bitrate for the interface in kilobytes/second for inbound traffic.OO
INBOUND_PEAK_KBData that can be transmitted at peak speed in kilobytes.O-
OUTBOUND_AVG_BWAverage bitrate for the interface in kilobytes/second for outbound traffic.OO
OUTBOUND_PEAK_BWMaximum bitrate for the interface in kilobytes/second for outbound traffic.OO
OUTBOUND_PEAK_KBData that can be transmitted at peak speed in kilobytes.O-
NETWORK_MODETo let the Scheduler pick the VNET if set to auto), any other value will be ignored By default, the network mode is not set.OO
SCHED_REQUIREMENTSDefine the requirement when NETWORK_MODE is auto.OO
SCHED_RANKDefine the rank when NETWORK_MODE is auto.OO
NAMEName of the NIC.OO
PARENTIt is used only on alias, it references the NIC which it is an alias of.OO

Here’s an example of a VM with two NICs attached to two different networks:

NIC = [ NETWORK_ID = 1 ]

NIC = [ NETWORK     = "Blue",
        NETWORK_UID = 0 ]

NIC = [ NETWORK_MODE = "auto",
        SCHED_REQUIREMENTS = "TRAFFIC_TYPE=\"public\"" ]

And here’s an example of a VM with two NICs attached, one is an alias of the other one:

NIC = [ NETWORK = "Test", NAME = "TestName" ]
NIC_ALIAS = [ NETWORK = "Test", PARENT = "TestName" ]

For more information on setting up virtual networks please check the Managing Virtual Networks guide.

Network Defaults

You can define a NIC_DEFAULT attribute with values that will be copied to each new NIC. This is especially useful for an administrator to define configuration parameters, such as MODEL, that final users may not be aware of.

NIC_DEFAULT = [ MODEL = "virtio" ]

I/O Devices Section

The following I/O interfaces can be defined for a VM:

Attribute

Description

KVM

vCenter

LXC

INPUT

Define input devices, available sub-attributes:

  • TYPE: values are mouse or tablet

  • BUS: values are usb, ps2

O

-

-

GRAPHICS

Whether the VM should export its graphical display and how, available sub-attributes:

O

O

O

  • TYPE: values: vnc, sdl, spice.

O

O

O (vnc)

  • LISTEN: IP to listen on.

O

O

O

  • PORT: port for the VNC server.

O

O

O

  • PASSWD*: password for the VNC server.

O

O

O

  • KEYMAP: keyboard configuration locale to use in the VNC display.

O

O

-

  • RANDOM_PASSWD: if "YES", generate a random password for each VM.

O

O

O

VIDEO

Defines a custom video device, available sub-attributes:

O

-

-

  • TYPE: values: none, vnc, cirrus, and virtio

M

-

-

  • IOMMU: Enables the use of emulated IOMMU by the video device.

O

-

-

  • ATS: Enables Address Translate Service for the device.

O

-

-

  • VRAM: Defines the amount of VRAM for the device, in kB

O

-

-

  • RESOLUTION: The preferred device resolution(ex: "1920x1080", "1280x768")

O

-

-

For example:

GRAPHICS = [
  TYPE    = "vnc",
  LISTEN  = "0.0.0.0",
  PORT    = "5905"]

Context Section

Context information is passed to the Virtual Machine via an ISO mounted as a partition. This information can be defined in the VM template in the optional section called Context, with the following attributes:

AttributeDescriptionKVM/LXC
VARIABLEVariables that store values related to this Virtual Machine or others . The name of the variable is arbitrary (in the example, we use hostname).O
FILESSpace-separated list of paths to include in context device. The location of the files are restricted by the CONTEXT_RESTRICTED_DIRS in oned.confO
FILES_DSSpace-separated list of File Images to include in context device.O
INIT_SCRIPTSIf the VM uses the OpenNebula contextualization package the init.sh file is executed by default. When the init script added is not called init.sh or more than one init script is added, this list contains the scripts to run and the order. Ex. “init.sh users.sh mysql.sh”O
START_SCRIPTText of the script executed when the machine boots. It can contain shebang in case it is not a shell script. For example START_SCRIPT="yum upgrade" or START_SCRIPT="choco upgrade all" for Bash and PowerShell respectivelyO
START_SCRIPT_BASE64The same as START_SCRIPT but encoded in Base64.O
TARGETDevice to attach the context ISO.-
DEV_PREFIXDevice prefix for the context ISO, either sd, or hd.-
TOKENYES to create a token.txt file for OneGate monitorization.O
ONEGATE_ENDPOINTOpenNebula will automatically add this variable if TOKEN is YES. Defaults to http://169.254.16.9:5030. Value loaded from /etc/one/oned.confO
REPORT_READYThe VM will send the READY signal to the onegate server. After this, the VM template will contain READY=YES in the USER_TEMPLATE sectionO
READY_SCRIPTREADY=YES will only be sent if the script is successfully executedLinux
READY_SCRIPT_PATHSimilar to READY_SCRIPT but the script exists in the Guest FSLinux
NETWORKYES to automatically fill the networking parameters for each NIC, used by the Contextualization packages.O
NETCFG_TYPENetwork configuration service inside guest VM responsible for configuring the NICs: empty (autodetects suitable service inside VM), bsd (for FreeBSD network configuration), interfaces (for Debian-style configuration via /etc/network/interfaces), netplan (for Netplan, set custom Netplan renderer via NETCFG_NETPLAN_RENDERER) networkd (for systemd-networkd), nm (for NetworkManager), scripts (for legacy Red Hat-style configuration via ifcfg-ethX files)Linux
NETCFG_NETPLAN_RENDERERNetplan renderer (effective only when NETCFG_TYPE=netplan): empty or networkd (for systemd-networkd), NetworkManager (for NetworkManager)Linux
SET_HOSTNAMEThis parameter value will be the hostname of the VM.O
DNS_HOSTNAMEYES to set the VM hostname to the reverse dns name (from the first IP)O
DNSSpecific DNS server for the Virtual Machine.O
ETHx_MACUsed to find the correct interface.O
ETHx_IPIPv4 address for the interface.O
ETHx_IP6IPv6 address for the interface. Legacy ETHx_IPV6 is also valid.O
ETHx_IP6_PREFIX_LENGTHIPv6 prefix length for the interface.O
ETHx_IP6_ULAIPv6 unique local address for the interfaceO
ETHx_IP6_METRICIP6_METRIC value for the IPv6 (default) route associated with this interface.Linux
ETHx_IP6_METHODIPv6 configuration method for the interface inside VM: static (for static address assignment based on context variables), auto (for SLAAC), dhcp (for SLAAC and DHCPv6), disable (for disabling IPv6), skip (skip IPv6 NIC configuration), empty defaults to content of ETHx_METHOD set for IPv4O
ETHx_METHODIPv4 configuration method for the interface inside VM: empty or static (for static address assignment based on context variables), dhcp (for DHCPv4), skip (skip IPv4 NIC configuration)O
ETHx_NETWORKNetwork address of the interface.O
ETHx_MASKNetwork mask.O
ETHx_GATEWAYDefault IPv4 gateway for the interface.O
ETHx_GATEWAY6Default IPv6 gateway for the interface.O
ETHx_ROUTESComma-separated list of custom routes for the interface. Format: <dst_network2> via <gateway1>, <dst_network2> via <gateway2>O
ETHx_MTUMTU value for the interface.O
ETHx_METRICMETRIC value for the (default) route associated with this interface.O
ETHx_DNSDNS for the network.O
ETHx_ALIASy_MACUsed to find the correct interface.O
ETHx_ALIASy_IPIPv4 address for the alias.O
ETHx_ALIASy_IP6IPv6 address for the alias. Legacy ETHx_ALIASy_IPV6 is also valid.O
ETHx_ALIASy_IP6_PREFIX_LENGTHIPv6 prefix length for the alias.O
ETHx_ALIASy_IP6_ULAIPv6 unique local address for the alias.O
ETHx_ALIASy_IP6_METHODIP6_METHOD value for the alias.-
ETHx_ALIASy_IP6_METRICIP6_METRIC value for the alias.-
ETHx_ALIASy_NETWORKNetwork address of the alias.O
ETHx_ALIASy_MASKNetwork mask.O
ETHx_ALIASy_GATEWAYDefault IPv4 gateway for the alias.-
ETHx_ALIASy_GATEWAY6Default IPv6 gateway for the alias.-
ETHx_ALIASy_MTUMTU value for the alias.-
ETHx_ALIASy_METHODMETHOD value for the alias.-
ETHx_ALIASy_METRICMETRIC value for the alias.-
ETHx_ALIASy_DNSDNS for the alias.-
USERNAMEUser to be created in the guest OS. If any password or SSH_PUBLIC_KEY attribute is defined (see below) it will change this user (defaults to root).Linux
CRYPTED_PASSWORD_BASE64Crypted password encoded in base64. To be set for the user USERNAME.Linux
PASSWORD_BASE64Password encoded in base64. To be set for the user USERNAME.O
CRYPTED_PASSWORDCrypted password. To be set for the user USERNAME. This parameter is not recommended, use CRYPTED_PASSWORD_BASE64 instead.Linux
PASSWORDPassword to be set for the user USERNAME. This parameter is not recommended, use PASSWORD_BASE64 instead.O
SSH_PUBLIC_KEYKey to be added to USERNAME authorized_keys file or root in case USERNAME is not set. Requires OpenSSH server installed on Windows, user automatically detected. USERNAME ignored.O
ENABLE_SSHSet to NO to disable the automatic startup of the sshd service (if installed).Windows
WINADMINSet to NO to treat the Windows user as standard user for setting SSH_PUBLIC_KEY.Windows
SECURETTYIf set to NO it will disable securetty validation on PAM. If set to YES it will restore system defaults. Defaults: LXC -> YES, KVM -> NO.Linux
TIMEZONETime zone to set. On Linux, the name must match the zone file name relative to /usr/share/zoneinfo/ (e.g. US/Central). On Windows, the name must match supported zone listed by tzutil /l (e.g. Central Standard Time).O
GROW_ROOTFSIf set to NO, the automatic growing of the root filesystem or disk C: on Windows will be disabled.O
GROW_FSMountpoints on Linux (e.g.: /mnt/disk /data) or drive letters on Windows (e.g.: X: Y:) of all the extra filesystems which should be extended. The rootfs / on Linux or disk C: on Windows is implied (automatically added) if GROW_ROOTFS is left empty or set to YES.O
IGNORE_SWAPIf set to YES then one-contexd service will skip auto-mounting of any found swap devices (this does not affect swap defined in /etc/fstab).Linux
RECREATE_RUNIf set to YES, missing directories and files persisted in the Image in /run (or /var/run) are restored and copied to the ephemeral /run (or /var/run) of the VM instance.Linux
EJECT_CDROMValue YES will signal to eject the CD with the context.sh file when (re)contextualization is finished.Windows

The values referred to by VARIABLE can be defined as:

Hardcoded values:

SET_HOSTNAME   = "MAINHOST"

Using template variables

$<template_variable>: any single value variable of the VM template, for example:

IP_GEN       = "10.0.0.$VMID"
SET_HOSTNAME = "$NAME"

$<template_variable>[<attribute>]: Any single value contained in a multiple value variable in the VM template, for example:

IP_PRIVATE = $NIC[IP]

$<template_variable>[<attribute>, <attribute2>=<value2>]: Any single value contained in the variable of the VM template, setting one attribute to discern between multiple variables called the same way, for example:

IP_PUBLIC = "$NIC[IP, NETWORK=\"Public\"]"

Using Virtual Network template variables

$NETWORK[<vnet_attribute>, <NETWORK_ID|NETWORK|NIC_ID>=<vnet_id|vnet_name|nic_id>]: Any single value variable in the Virtual Network template, for example:

DNS = "$NETWORK[DNS, NETWORK_ID=3]"

Using Image template variables

$IMAGE[<image_attribute>, <IMAGE_ID|IMAGE>=<img_id|img_name>]: Any single value variable in the Image template, for example:

root = "$IMAGE[ROOT_PASS, IMAGE_ID=0]"

Using User template variables

$USER[<user_attribute>]: Any single value variable in the user (owner of the VM) template, for example:

ssh_key = "$USER[SSH_KEY]"

Pre-defined variables, apart from those defined in the template you can use:

  • $UID, the uid of the VM owner.
  • $UNAME, the name of the VM owner.
  • $GID, the id of the VM owner’s group.
  • $GNAME, the name of the VM owner’s group.
  • $TEMPLATE, the whole template in XML format and encoded in base64.

FILES_DS, each file must be registered in a FILE_DS datastore and has to be of type CONTEXT. Use the following to select files from Files Datastores:

  • $FILE[IMAGE=<image name>], to select the user’s own files.
  • $FILE[IMAGE=<image name>, <IMAGE_UNAME|IMAGE_UID>=<owner name|owner id>], to select images owned by other users, by user name or UID.
  • $FILE[IMAGE_ID=<image id>], global file selection.

For example:

CONTEXT = [
  SET_HOSTNAME = "MAINHOST",
  IP_PRIVATE   = "$NIC[IP]",
  DNS          = "$NETWORK[DNS, NAME=\"Public\"]",
  IP_GEN       = "10.0.0.$VMID",
  FILES        = "/service/init.sh /service/certificates /service/service.conf",
  FILES_DS     = "$FILE[IMAGE_ID=34] $FILE[IMAGE=\"kernel\"]",
  TARGET       = "sdc"
]

Placement Section

The following attributes sets placement constraints and preferences for the VM, valid for all hypervisors:

AttributeDescription
SCHED_REQUIREMENTSBoolean expression that rules out provisioning Hosts from list of machines suitable to run this VM.
SCHED_RANKThis field sets which attribute will be used to sort the suitable Hosts for this VM. Basically, it defines which Hosts are more suitable than others.
SCHED_DS_REQUIREMENTSBoolean expression that rules out entries from the pool of datastores suitable to run this VM.
SCHED_DS_RANKStates which attribute will be used to sort the suitable datastores for this VM. Basically, it defines which datastores are more suitable than others.
USER_PRIORITYAlter the standard FIFO ordering to dispatch VMs. VMs with a higher USER_PRIORITY will be dispatched first.

For example:

SCHED_REQUIREMENTS    = "CPUSPEED > 1000"
SCHED_RANK            = "FREE_CPU"
SCHED_DS_REQUIREMENTS = "NAME=GoldenCephDS"
SCHED_DS_RANK         = FREE_MB

Requirement Expression Syntax

The syntax of the requirement expressions is defined as:

stmt::= expr';'
expr::= VARIABLE '=' NUMBER
      | VARIABLE '!=' NUMBER
      | VARIABLE '>' NUMBER
      | VARIABLE '<' NUMBER
      | VARIABLE '@>' NUMBER
      | VARIABLE '=' STRING
      | VARIABLE '!=' STRING
      | VARIABLE '@>' STRING
      | expr '&' expr
      | expr '|' expr
      | '!' expr
      | '(' expr ')'

Each expression is evaluated to 1 (TRUE) or 0 (FALSE). Only those Hosts for which the requirement expression is evaluated to TRUE will be considered to run the VM.

Logical operators work as expected ( less ‘<’, greater ‘>’, ‘&’ AND, ‘|’ OR, ‘!’ NOT), ‘=’ means equals with numbers (floats and integers). When you use ‘=’ operator with strings, it performs a shell wildcard pattern matching. Additionally, the ‘@>’ operator means contains, if the variable evaluates to an array the expression will be true if that array contains the given number or string (or any string that matches the provided pattern).

Any variable included in the Host template or its Cluster template can be used in the requirements. You may also use an XPath expression to refer to the attribute.

There is a special variable, CURRENT_VMS, that can be used to deploy VMs in a Host where other VMs are (not) running. It can be used only with the operators ‘=’ and ‘!=’.

Examples:

# Only aquila hosts (aquila0, aquila1...), note the quotes
SCHED_REQUIREMENTS = "NAME = \"aquila*\""

# Only those resources with more than 60% of free CPU
SCHED_REQUIREMENTS = "FREE_CPU > 60"

# Deploy only in the Host where VM 5 is running. Two different forms:
SCHED_REQUIREMENTS = "CURRENT_VMS = 5"
SCHED_REQUIREMENTS = "\"HOST/VMS/ID\" @> 5"

# Deploy in any Host, except the ones where VM 5 or VM 7 are running
SCHED_REQUIREMENTS = "(CURRENT_VMS != 5) & (CURRENT_VMS != 7)"

# Use any datastore that is in cluster 101 (it list of cluster IDs contains 101)
SCHED_DS_REQUIREMENTS = "\"CLUSTERS/ID\" @> 101"
SCHED_REQUIREMENTS = "HYPERVISOR=\"LXC\""
  • $<template_variable>: any single value variable of the VM template.
  • $<template_variable>[<attribute>]: Any single value contained in a multiple value variable in the VM template.
  • $<template_variable>[<attribute>, <attribute2>=<value2>]: Any single value contained in a multiple value variable in the VM template, setting one attribute to discern between multiple variables called the same way.

For example, if you have a custom probe that generates a MACS attribute for the Hosts, you can do short of a MAC pinning, so only VMs with a given MAC runs in a given Host.

SCHED_REQUIREMENTS = "MAC=\"$NIC[MAC]\""

Rank Expression Syntax

The syntax of the rank expressions is defined as:

stmt::= expr';'
expr::= VARIABLE
      | NUMBER
      | expr '+' expr
      | expr '-' expr
      | expr '*' expr
      | expr '/' expr
      | '-' expr
      | '(' expr ')'

Rank expressions are evaluated using each Host’s information. ‘+’, ‘-’, ‘*’, ‘/’ and ‘-’ are arithmetic operators. The rank expression is calculated using floating point arithmetic and then rounded to an integer value.

Here are some examples:

# First those resources with a higher Free CPU
  SCHED_RANK = "FREE_CPU"

# Consider also the CPU temperature
  SCHED_RANK = "FREE_CPU * 100 - TEMPERATURE"

Predefined Host Attributes

There are some predefined Host attributes that can be used in the requirements and rank expressions, valid for all hypervisors:

AttributeDescription
NAMEHostname.
MAX_CPUTotal CPU in the Host, in (# cores * 100).
CPU_USAGEAllocated used CPU in (# cores * 100). This value is the sum of all the CPU requested by VMs running on the Host, and is updated instantly each time a VM is deployed or undeployed.
FREE_CPUReal free CPU in (# cores * 100), as returned by the probes. This value is updated each monitorization cycle.
USED_CPUReal used CPU in (# cores * 100), as returned by the probes. USED_CPU = MAX_CPU - FREE_CPU. This value is updated each monitorization cycle.
MAX_MEMTotal memory in the Host, in KB.
MEM_USAGEAllocated used memory in KB. This value is the sum of all the memory requested by VMs running on the Host, and is updated instantly each time a VM is deployed or undeployed.
FREE_MEMORYReal free memory in KB, as returned by the probes. This value is updated each monitorization cycle.
USED_MEMORYReal used memory in KB, as returned by the probes. USED_MEMORY = MAX_MEM - FREE_MEMORY. This value is updated each monitorization cycle.
RUNNING_VMSNumber of VMs deployed on this Host.
HYPERVISORHypervisor name.

You can execute onehost show <id> -x to see all the attributes and their values.

Hypervisor Section

You can also tune several low-level hypervisor attributes.

The RAW attribute (optional) section of the VM template is used pass VM information directly to the underlying hypervisor. Anything placed in the data attribute gets passed straight to the hypervisor unmodified.

AttributeDescriptionKVMLXC
TYPEPossible values are: kvm, lxc.OO
VALIDATEValidate DATA against XML schema, possible values yes, no. Default value yes.O-
DATARaw data to be passed directly to the hypervisor.OO
DATA_VMXRaw data to be added directly to the .vmx file.-.

For example:

RAW = [
    type = "kvm",
    validate = "yes",
    data = "<devices><serial type=\"pty\"><source path=\"/dev/pts/5\"/><target port=\"0\"/></serial><console type=\"pty\" tty=\"/dev/pts/5\"><source path=\"/dev/pts/5\"/><target port=\"0\"/></console></devices>"
]
RAW = [
    type = "lxc",
    data = "boot.autostart": "true", "limits.processes": "10000"
]

Additionally the following can be also set for KVM:

AttributeDescription
EMULATORPath to the emulator binary to use with this VM.

For example:

EMULATOR="/usr/bin/qemu-system-aarch64"

Restricted Attributes

All the default restricted attributes to users in the oneadmin group are summarized in:

  • CONTEXT/FILES
  • NIC/VLAN_ID
  • NIC/BRIDGE
  • NIC/FILTER
  • NIC/FILTER_IP_SPOOFING
  • NIC/FILTER_MAC_SPOOFING
  • NIC/INBOUND_AVG_BW
  • NIC/INBOUND_PEAK_BW
  • NIC/INBOUND_PEAK_KB
  • NIC/OUTBOUND_AVG_BW
  • NIC/OUTBOUND_PEAK_BW
  • NIC/OUTBOUND_PEAK_KB
  • NIC/OPENNEBULA_MANAGED
  • NIC/EXTERNAL
  • NIC_ALIAS/MAC
  • NIC_ALIAS/VLAN_ID
  • NIC_ALIAS/BRIDGE
  • NIC_ALIAS/INBOUND_AVG_BW
  • NIC_ALIAS/INBOUND_PEAK_BW
  • NIC_ALIAS/INBOUND_PEAK_KB
  • NIC_ALIAS/OUTBOUND_AVG_BW
  • NIC_ALIAS/OUTBOUND_PEAK_BW
  • NIC_ALIAS/OUTBOUND_PEAK_KB
  • NIC_ALIAS/OPENNEBULA_MANAGED
  • NIC_DEFAULT/MAC
  • NIC_DEFAULT/VLAN_ID
  • NIC_DEFAULT/BRIDGE
  • NIC_DEFAULT/FILTER
  • NIC_DEFAULT/EXTERNAL
  • DISK/TOTAL_BYTES_SEC
  • DISK/TOTAL_BYTES_SEC_MAX_LENGTH
  • DISK/TOTAL_BYTES_SEC_MAX
  • DISK/READ_BYTES_SEC
  • DISK/READ_BYTES_SEC_MAX_LENGTH
  • DISK/READ_BYTES_SEC_MAX
  • DISK/WRITE_BYTES_SEC
  • DISK/WRITE_BYTES_SEC_MAX_LENGTH
  • DISK/WRITE_BYTES_SEC_MAX
  • DISK/TOTAL_IOPS_SEC
  • DISK/TOTAL_IOPS_SEC_MAX_LENGTH
  • DISK/TOTAL_IOPS_SEC_MAX
  • DISK/READ_IOPS_SEC
  • DISK/READ_IOPS_SEC_MAX_LENGTH
  • DISK/READ_IOPS_SEC_MAX
  • DISK/WRITE_IOPS_SEC
  • DISK/WRITE_IOPS_SEC_MAX_LENGTH
  • DISK/WRITE_IOPS_SEC_MAX
  • DISK/SIZE_IOPS_SEC
  • DISK/OPENNEBULA_MANAGED
  • DISK/SIZE
  • DISK/ORIGINAL_SIZE
  • DISK/SIZE_PREV
  • DEPLOY_ID
  • CPU_COST
  • MEMORY_COST
  • DISK_COST
  • PCI
  • EMULATOR
  • RAW
  • USER_PRIORITY
  • USER_INPUTS/CPU
  • USER_INPUTS/MEMORY
  • USER_INPUTS/VCPU
  • TOPOLOGY/PIN_POLICY
  • TOPOLOGY/HUGEPAGE_SIZE

These attributes can be configured in oned.conf.

User Inputs

USER_INPUTS provides the template creator with the possibility to dynamically ask the user instantiating the template for dynamic values that must be defined.

USER_INPUTS = [
  BLOG_TITLE="M|text|Blog Title",
  MYSQL_PASSWORD="M|password|MySQL Password",
  INIT_HOOK="M|text64|You can write a script that will be run on startup",
  <VAR>="M|<type>|<desc>"
]

CONTEXT=[
  BLOG_TITLE="$BLOG_TITLE",
  MYSQL_PASSWORD="$MYSQL_PASSWORD" ]

Note that the CONTEXT references the variables defined in the USER_INPUTS so the value is injected into the VM.

Valid types:

TypesValueDescription
text<VAR>=”M|text| <desc>| | <default>”A string
text64<VAR>=”M|text64| <desc>| | <default>”text64 will encode the user’s response in Base64
password<VAR>=”M|password| <desc>”
number<VAR>=”M|number| <desc>| | <default>”An integer
float<VAR>=”M|number-float| <desc>| | <default>”A float
range<VAR>=”M|range| <desc>|<min>..<max>| <default>”A range of integers
range (float)<VAR>=”M|range-float| <desc>|<min>..<max>|<default>”A range of floats
list<VAR>=”M|list| <desc>|<v1>,<v2>,<v3>|<default>”A list
list-multiple<VAR>=”M|list-multiple| <desc>|<v1>,<v2>,<v3>|<default>|”A list with multiple values
boolean<VAR>=”M|boolean| <desc>| | <default>”Yes or no
fixed<VAR>=”M|fixed| <desc>| | <value>”A fixed value, cannot be changed

There is the possibility of making the USER_INPUT mandatory or not mandatory. If it is mandatory, we will see a letter ‘M’ but if it is not mandatory a letter ‘O’ will appear. For example:

  • <VAR>=”M|... This is mandatory
  • <VAR>=”O|... This is not mandatory

In Sunstone, the USER_INPUTS can be ordered with the mouse.

user_inputs

USER_INPUTS_METADATA provides the template creator with the possibility to add titles and descriptions to the user inputs. To understand how Sunstone renders user inputs metadata, see User Inputs in Sunstone.

AttributeMandatoryDescription
TYPEYesType of the metadata. Possible values: APP or GROUP.
NAMEYesName of the user input. It has to be an existing user input name in the same template.
TITLENoIn the case of APP is the text that will be shown to the user in a Sunstone tab. In the case of GROUP is the text that will be shown to the user in a Sunstone group.
DESCRIPTIONNoIn the case of APP is a text info note that will be shown in the APP tab. In the case of GROUP is the text that will be shown as info text in the Sunstone group.

Here’s an example:

USER_INPUTS_METADATA=[
  DESCRIPTION="This tab includes all the information about the blog section in this template.",
  NAME="BLOG",
  TITLE="Blog",
  TYPE="APP" ]
USER_INPUTS_METADATA=[
  NAME="MYSQL",
  TITLE="MySQL",
  TYPE="APP" ]
USER_INPUTS_METADATA=[
  DESCRIPTION="MySQL configuration parameters",
  NAME="CONFIG",
  TITLE="Configuration",
  TYPE="GROUP" ]
USER_INPUTS_METADATA=[
  DESCRIPTION="Additional MySQL parameters",
  NAME="ADDITIONAL",
  TITLE="Additional parameters",
  TYPE="GROUP" ]

Schedule Actions Section

The following attributes can used to define punctual or relative actions for the VM.

AttributeDescription
TIMETime in seconds to start the action. Can be defined as relative value +sec from the VM start, OpenNebula computes and stores absolute value.
WARNINGTime in seconds (can be relative +sec from the VM start), for the CLI and Sunstone to highlight the action, because it will be executed soon.
REPEATDefine the granularity of the action [ WEEKLY = 0 , MONTHLY = 1 , YEARLY = 2 , HOURLY = 3 ].
DAYSSets the frequency for recurring actions. The specific values depend on the REPEAT mode, i.e. for yearly periods DAYS=”1,365” would mean the first and last day of the year.
ACTIONThe action that will be executed.
ARGSAdditional arguments for the action (no need to define the VM_ID)
END_TYPEWhen the users want to end the action [ NEVER = 0 , NUMBER OF REPETITIONS = 1 , DATE = 2 ].
END_VALUEThe value for END_TYPE attribute, can be a number or a date.

For example:

SCHED_ACTION=[
    ACTION="suspend",
    DAYS="1,5",
    END_TYPE="1",
    END_VALUE="5",
    ID="0",
    REPEAT="0",
    TIME="1537653600",
    WARNING="1537567200" ]

NUMA topology Section

The following attributes can use to define a NUMA topology for the VM.

TOPOLOGY attributeDescription
PIN_POLICYvCPU pinning preference: CORE, THREAD, SHARED, NONE.
SOCKETSNumber of sockets or NUMA nodes.
CORESNumber of cores per node.
THREADSNumber of threads per core.
HUGEPAGE_SIZESize of the hugepages (MB). If not defined no hugepages will be used.
MEMORY_ACCESSControl if the memory is to be mapped shared or private.

For example:

TOPOLOGY = [
  HUGEPAGE_SIZE = "2",
  MEMORY_ACCESS = "shared",
  NUMA_NODES    = "2",
  PIN_POLICY    = "THREAD" ]

Asymmetric NUMA configurations, i.e., not distributing the VM resources evenly across the nodes, can be defined manually by setting the NUMA_NODE attribute:

NUMA_NODE attributeDescription
MEMORYMemory allocated in the node, in MB.
TOTAL_CPUSTotal number of CPU units, CORE*THREADS.

For example:

TOPOLOGY = [ PIN_POLICY = CORE, SOCKETS = 2 ]

NUMA_NODE = [ MEMORY = 1024, TOTAL_CPUS = 2 ]
NUMA_NODE = [ MEMORY = 2048, TOTAL_CPUS = 4 ]

Please check the NUMA guide for more information.

Sunstone Section

The following attributes are used to display elements in Sunstone:

AttributeDescription
NETWORK_ALIASDisable interface network type (alias)
NETWORK_AUTODisable interface network selection (Automatic selection)
NETWORK_RDPDisable interface network RDP connection (active)
NETWORK_SSHDisable interface network SSH connection (active)
NETWORK_SELECTDisable Network selection for VM on instantiation

For example:

SUNSTONE = [
  NETWORK_ALIAS = "yes",
  NETWORK_AUTO = "no",
  NETWORK_RDP = "yes",
  NETWORK_SSH = "yes"
]

sunstone_network_options

sunstone_network_options-2

sunstone_network_options-3