2.11. Managing Templates

A template in Virtuozzo is a pre-configured virtual machine or container that can be easily and quickly deployed into a fully functional virtual machine or container. Like any normal virtual machine or container, a template contains hardware (virtual disks, peripheral devices) and the operating system. It can also have additional software installed. In fact, the only main difference between a virtual machine or container and a template is that the latter cannot be started.

You can perform the following operations on templates:

These operations are described in the following subsections in detail.

Note

In addition, see Using Customized EZ Templates for details on how to manually create and use custom container templates.

2.11.1. Creating Templates

In Virtuozzo, you can create a template using the prlctl clone utility. Making a template may prove useful if you need to create several virtual machines or containers with the same configuration. In this case, your steps can be as follows:

  1. You create a virtual machine or container with the required configuration.
  2. You make a template on the basis of the created virtual machine or container.
  3. You use the template to create as many virtual machines or containers as necessary.

Let us assume that you want to create a template of the virtual machine MyVM. To do this, you can run the following command:

# prlctl clone MyVM --name template1 --template

This command clones the virtual machine and saves it as the template1 template. After the template has been successfully created, you can use it for creating new virtual machines.

2.11.2. Listing Templates

Sometimes, you may need to get an overview of the templates available on your hardware node. For example, this may be necessary if you plan to create a virtual machine or container from a specific template, but do not remember its exact name. In this case, you can use the prlctl list command to list all templates on the hardware node and find the one you need:

# prlctl list -t
UUID                                    DIST            T  NAME
{017bfdf0-b546-4309-90d0-147ce55773f2}  centos          VM centos_tmpl
{92cd331e-0572-46ac-8586-f19b8d029c4d}  centos          CT ct201_tmp1
{fc40e38e-8da4-4b26-bb18-6098ec85f7b4}  debian          VM deb_tmpl
{0dea5912-b114-45a9-bd1a-dc065c1b8e9f}  ubuntu          VM ubuntu_tmp1
{479e66aa-332c-4e3e-975e-b8b6bfc9d2e0}  win-2012        VM w12en_tmpl

In this example, 5 templates exist on the server. The information on these templates is presented in the form of a table with the following columns (from left to right): the template ID, the operating system contained in the template, the template type (for a container or virtual machine) and the template name.

2.11.3. Deploying Templates

To deploy a virtual machine or container from a template, use the --ostemplate option of the prlctl create command. For example, to deploy the virtual machine MyVMtemplate1 from the template template1, run the following:

# prlctl create MyVMtemplate1 --ostemplate template1

To check that the virtual machine has been successfully created, use the prlctl list -a command:

# prlctl list -a
STATUS       IP_ADDR         NAME
running      10.12.12.101    MyVM
stopped      10.12.12.34     MyVMtemplate1

The template itself is left intact and can be used for creating other virtual machines:

# prlctl list -t
{4ad11c28-9f0e-4086-84ea-9c0487644026} win-2008 template1
{64bd8fea-6047-45bb-a144-7d4bba49c849} rhel     template2

2.11.4. Storing Templates on Virtuozzo Storage

Starting from Virtuozzo 7.0.7 (Update 7), you can store container and virtual machine templates in shared directories of Virtuozzo Storage clusters. These templates will be available to any server participating in the cluster.

To place a template on Virtuozzo Storage, do as follows on the cluster node where the source container or VM is located:

  1. Create a template. For example:

    # prlctl clone MyVM --name template1 --template
    
  2. Move this template to the vmtemplates directory located on Virtuozzo Storage:

    • for Virtuozzo Storage with CLI management, the path is /vstorage/<cluster_name>/vmtemplates, e.g.:

      # prlctl move template1 --dst /vstorage/vstor1/vmtemplates
      
    • for Virtuozzo Storage with GUI management, the path is /mnt/vstorage/vmtemplates, e.g.:

      # prlctl move template1 --dst /mnt/vstorage/vmtemplates
      

Within five minutes, the template will be autodetected by the prlctl utility. You can check template availability by listing templates on another Virtuozzo Storage server. For example:

# prlctl list -t | grep template1
{4ad11c28-9f0e-4086-84ea-9c0487644026} win-2008 template1

Once the template is available throughout the cluster, you can start creating containers or VMs based on it on any cluster node as described in Deploying Templates.