When creating a new Virtuozzo Container, the following configuration parameters are mandatory and must be selected every time:
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. 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 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 |
|
The name that you would like to use for the Container. |
|
The name of the OS template from which to create a Container. |
|
Operating system type: |
|
CPU architecture, e.g. |
|
The hostname that you would like to use for the Container. |
|
The IP address to assign to the Container. |
|
Container network netmask. |
|
Network interface ID: |
|
Specifies whether to turn the Offline Management feature on or off. |
Sample Function:
/// <summary>
/// Sample function CreateVE.
/// 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 CreateVE(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 Container sample
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:
createVE( "sample_ve", "redhat-as3-minimal", "linux","x86", "sample_ve_hostname", "10.16.3.179", "255.255.255.0", "venet0", true );