Home > Articles > Creating a Virtuozzo Container

Creating a Virtuozzo Container

November 19th, 2008 Leave a comment Go to comments

When creating a new Virtuozzo Container, the following configuration parameters are mandatory and must be selected every time:

  • Sample configuration name. Virtuozzo Containers software comes with a set of sample configurations that are installed on the Hardware Node at the time the Virtuozzo Containers software is installed. XML API provides the env_samplem/get_sample_conf call to retrieve the list of the available configurations. In the example provided in this section, the C# equivalent of that call is the env_samplemBinding.get_sample_conf() method.
  • Operating System Template. The list of the available templates can be retrieved using the vzapkgm.get_list XML API call. The C# equivalent is vzapkgmBinding.get_list call. For simplicity, we are not including this call in the example because Virtuozzo Containers for Windows currently comes with just one OS template, and Virtuozzo for Linux has one template for each supported Linux distribution. For example, the standard Red Hat Linux OS template name is redhat-as3-minimal.

The rest of the parameters that we use in this example are optional but are typically used when a new Container is created. The following sample shows how to create a Virtuozzo Container.

Sample Function Parameters:

Name

Description

name

The name that you would like to use for the Container.

os_template

The name of the OS template to use for the Container.

platform

Operating system type: linux or windows. This parameter will be used in our function to select a sample configuration for the Container. If the sample configuration is compatible with the specified platform, we will use it. In a real application, you would probably select the sample configuration in advance and would pass its name to the method that actually creates a Container. In this example, we automate this task while providing a demonstration of how to retrieve the list of the available sample configurations.

architecture

CPU architecture, e.g. x86, ia64. This parameter, together with the platform parameter (above) will also be used to determine the sample configuration compatibility with the specified CPU architecture.

hostname

The hostname that you would like to use for the Container.

ip

The IP address to assign to the Container.

netmask

Netmask.

network

Network interface ID: venet0 for Linux; venet1 for Windows. These are the standard host-routed Virtuozzo network interfaces. For other network configuration scenarios, please refer to Parallels Agent XML Programmer’s Reference.

offline_management

Specifies whether to turn the Container Offline Management feature on or off.

Sample Function:

/// <summary>

/// Sample function CreateCT.

/// Creates a new Virtuozzo Container.

/// </summary>

/// <param name=”name”>Container name.</param>

/// <param name=”os_template”>OS template name.</param>

/// <param name=”platform”>Operating system type: linux or windows.</param>

/// <param name=”architecture”>CPU architecture (x86, ia64)</param>

/// <param name=”hostname”>Container hostname.</param>

/// <param name=”ip”>Container IP address.</param>

/// <param name=”netmask”>Netmask.</param>

/// <param name=”network”>Network interface ID.</param>

/// <param name=”offline_management”>

/// A flag specifyin whether to turn the “offline management”

/// feature on or off.

/// </param>

/// <returns>Server ID of the new Container.</returns>

public string CreateCT(string name, string os_template, string platform, string architecture, string hostname, string ip, string netmask, string network, bool offline_management)

{

try {

// Instantiate the proxy class.

vzaenvmBinding env = (vzaenvmBinding)binder.InitBinding(typeof(vzaenvmBinding));

// The main input object.

create create_input = new create();

// Container configuration information.

venv_configType1 veconfig = new venv_configType1();

/* Retrieve the list of sample configurations.

* Select the first one that is compatible with the

* specified platform (Linux, Windows) and CPU architecture.

*/

env_samplemBinding env_sample = (env_samplemBinding)binder.InitBinding(typeof(env_samplemBinding));

get_sample_conf get_sample = new get_sample_conf();

sample_confType[] samples = env_sample.get_sample_conf(get_sample);

if (samples != null) {

foreach (sample_confType sample in samples) {

if (sample.env_config.os != null) {

if (sample.env_config.os.platform == platform && sample.env_config.architecture == architecture) {

// Set sample configuration ID.

veconfig.base_sample_id = sample.id;

break;

}

}

}

}

// Set OS template.

templateType osTemplate = new templateType();

osTemplate.name = os_template;

veconfig.os_template = osTemplate;

// Set Container name

veconfig.name = name;

// Set Container hostname

veconfig.hostname = hostname;

// Set Container IP address and netmask.

ip_addressType[] ip_address = new ip_addressType[1];

ip_address[0] = new ip_addressType();

ip_address[0].ip = ip;

ip_address[0].netmask = netmask;

// Set network.

net_vethType[] net = new net_vethType[1];

net[0] = new net_vethType();

net[0].host_routed = new object();

net[0].id = network;

net[0].ip_address = ip_address;

veconfig.net_device = net;

// Set the offline management feature.

veconfig.offline_managementSpecified = true;

veconfig.offline_management = offline_management;

// Finalize the new Container configuration.

create_input.config = veconfig;

// Create the Container.

return env.create(create_input).env.eid;

}

catch (Exception e) {

return “Exception: ” + e.Message;

}

}

The function invocation example:

createCT(”sample_ve”, “redhat-as3-minimal”, “linux”,”x86″, “sample_ve_hostname”, “10.16.3.179″, “255.255.255.0″, “venet0″, true );

Categories: Articles Tags:
  1. No comments yet.
  1. No trackbacks yet.
You must be logged in to post a comment.