Creating virtual machines

Limitations

  • Virtual machines are created with the host CPU model, by default. Having compute nodes with different CPUs may lead to live migration issues. To avoid them, you can manually set the CPU model for all new VMs, as described in Setting virtual machine CPU model. Alternatively, you can create a placement for each group of compute nodes with the same CPU model by using the instructions in Managing placements for compute nodes.

  • UEFI boot is not supported for CentOS 7.x virtual machines with less than 1 GiB of RAM.

Prerequisites

To create a virtual machine

Admin panel

  1. On the Compute > Virtual machines > Virtual machines tab, click Create virtual machine. A window will open where you will need to specify the VM parameters.

  2. Specify a name for the new VM.
  3. Select the VM boot media:

    If you select an image or volume with an assigned placement, the created VM will also inherit this placement.

    After selecting the boot media, volumes required for this media to boot will be automatically added to the Volumes section.

  4. Configure the VM disks:

    1. In the Volumes window, make sure the default boot volume is large enough to accommodate the guest OS. Otherwise, click the ellipsis icon next to it, and then Edit. Change the volume size and click Save.
    2. Add more disks to the VM by creating or attaching volumes. To do this, click the pencil icon in the Volumes section, and then Add or Attach in the Volumes window.

    3. Select volumes that will be removed during the VM deletion. To do this, click the pencil icon in the Volumes section, click the ellipsis icon next to the needed volume, and then Edit. Enable Delete on termination and click Save.
    4. When you finish configuring the VM disks, click Done.
  5. Choose the amount of RAM and CPU resources that will be allocated to the VM in the Flavor section. In the Flavor window, select a flavor, and then click Done.

    When choosing a flavor for a VM, ensure it satisfies the hardware requirements of the guest OS.

    To select a flavor with an assigned placement, you can filter flavors by placement. The VM created from such a flavor will also inherit this placement.

  6. Add network interfaces to the VM in the Networks section:

    1. In the Network interfaces window, click Add to attach a network interface.
    2. In the Add network interface window, select a compute network to connect to, and then specify MAC address, IPv4 and/or IPv6 addresses, and security groups. By default, MAC and primary IP addresses are assigned automatically. To specify them manually, clear the Assign automatically check boxes, and enter the desired addresses. Optionally, assign additional IP addresses to the network interface in the Secondary IP addresses section. Note that a secondary IPv6 address is not available for an IPv6 subnet that works in the SLAAC or DHCPv6 stateless mode.

      Secondary IP addresses, unlike the primary one, will not be automatically assigned to the network interface inside the virtual machine guest OS. You should assign them manually.

      After specifying the network interface parameters, click Add. The network interface will appear in the Network interfaces list.

    3. If required, edit IP addresses and security groups of newly added network interfaces. To do this, click the ellipsis icon, click Edit, and then set the parameters.

    4. When you finish configuring the VM network interfaces, click Done.
  7. If you have chosen to boot from a template or volume, which has cloud-init and OpenSSH installed:

    As cloud images have no default password, you can access VMs deployed from them only by using the key authentication method with SSH.

  8. Enable CPU and RAM hot plug for the VM in Advanced options, to be able to change its flavor when the VM is running. You can also enable hot plug after the VM is created.

  9. If you have chosen to boot from an ISO image, enable UEFI boot in Advanced options, to be able to boot the VM in the UEFI mode. This option cannot be configured after the VM is created.

    You cannot configure UEFI boot if you have selected a template as the VM boot media. If your template has UEFI boot enabled, the option is automatically enabled for the VM, and vice versa.

  10. After configuring all of the VM parameters, click Deploy to create and boot the VM.

If you are deploying the VM from an ISO image, you need to install the guest OS inside the VM by using the built-in VNC console. For VMs with UEFI boot enabled, open the VNC console, and then press any key to boot from the chosen ISO image. Virtual machines created from a template or a boot volume already have a preinstalled guest OS.

Command-line interface

Use the following command:

vinfra service compute server create [--description <description>]
                                     [--metadata <metadata>]
                                     [--user-data <user-data>]
                                     [--key-name <key-name>]
                                     [--config-drive] [--count <count>]
                                     [--ha-enabled {true,false}]
                                     [--placements <placements>]
                                     [--allow-live-resize] [--uefi]
                                     --network id|<id=id[,key=value,…]>
                                     --volume <source=source
                                     [,key=value,…]>
                                     --flavor <flavor> <server-name>
--description <description>
Virtual machine description
--metadata <metadata>
Virtual machine metadata
--user-data <user-data>
User data file
--key-name <key-name>
Key pair to inject
--config-drive
Use an ephemeral drive
--count <count>
If count is specified and greater than 1, the name argument is treated as a naming pattern.
--ha-enabled {true,false}
Enable or disable HA for the virtual machine.
--placements <placements>
Names or IDs of placements to add the virtual machine to.
--allow-live-resize
Allow online resize for the virtual machine.
--uefi
Allow UEFI boot for the virtual machine. This option can be used for VMs created from ISO images.
--network id|<id=id[,key=value,…]>

Create a virtual machine with a specified network. Specify this option multiple times to create multiple networks.

  • id: attach network interface to a specified network (ID or name)
  • comma-separated key=value pairs with keys (optional):
    • mac: MAC address for network interface
    • fixed-ip: fixed IP address or None to automatically allocate an IP address. This option can be used multiple times.
    • spoofing-protection-enable: enable spoofing protection for network interface
    • spoofing-protection-disable: disable spoofing protection for network interface
    • security-group: security group ID or name. This option can be used multiple times.
    • no-security-group: do not use a security group
--volume <source=source[,key=value,…]>

Create a virtual machine with a specified volume. Specify this option multiple times to create multiple volumes.

  • source: source type (volume, image, snapshot, or blank)
  • comma-separated key=value pairs with keys (optional):
    • id: resource ID or name for the specified source type (required for source types volume, image, and snapshot)
    • size: block device size, in gigabytes (required for source types image and blank)
    • boot-index: block device boot index (required for multiple volumes with source type volume)
    • bus: block device controller type (scsi)
    • type: block device type (disk or cdrom)
    • rm: remove block device on virtual machine termination (yes or no)
    • storage-policy: block device storage policy
--flavor <flavor>
Flavor ID or name
<server-name>
A new name for the virtual machine

For example, to create a virtual machine myvm based on the image cirros and the flavor tiny, connect it to the virtual network private with the fixed IP address 192.168.128.100, run:

# vinfra service compute server create myvm --network id=private,fixed-ip=192.168.128.100 \
--volume source=image,id=cirros,size=1 --flavor tiny
+--------------+--------------------------------------+
| Field        | Value                                |
+--------------+--------------------------------------+
| config_drive |                                      |
| created      | 2019-05-29T11:24:04Z                 |
| description  |                                      |
| flavor       | disk: 0                              |
|              | ephemeral: 0                         |
|              | extra_specs: {}                      |
|              | original_name: tiny                  |
|              | ram: 512                             |
|              | swap: 0                              |
|              | vcpus: 1                             |
| ha_enabled   | True                                 |
| host         |                                      |
| id           | 8cd29296-8bee-4efb-828d-0e522d816c6e |
| key_name     |                                      |
| metadata     | {}                                   |
| name         | myvm                                 |
| networks     | []                                   |
| power_state  | NOSTATE                              |
| project_id   | b4267de6fd0c442da99542cd20f5932c     |
| status       | BUILD                                |
| task_state   | scheduling                           |
| updated      | 2019-05-29T11:24:21Z                 |
| user_data    |                                      |
| vm_state     | building                             |
| volumes      | []                                   |
+--------------+--------------------------------------+

The new virtual machine will appear in the vinfra service compute server list output:

# vinfra service compute server list
+-------------+------+--------+------------------------+---------------------------+
| id          | name | status | host                   | networks                  |
+-------------+------+--------+------------------------+---------------------------+
| 8cd29296<…> | myvm | ACTIVE | node002.vstoragedomain | - private=192.168.128.100 |
+-------------+------+--------+------------------------+---------------------------+