The following function retrieves a list of Virtuozzo Containers from a Hardware Node. The function accepts a numeric code specifying the Container state as a parameter allowing you to retrieve the information only for the Containers in a particular state (running, stopped, etc.). The state codes are as follows:
Code |
Name |
|
Unknown |
|
Unexisting |
|
Config |
|
Down |
|
Mounted |
|
Suspended |
|
Running |
|
Repairing |
|
License Violation |
The function returns a string containing the list of names of the existing Containers.
/// <summary>
/// sample function GetCTList.
/// Retrieves the list of Containers from a Hardware Node.
/// </summary>
/// <param name="state">Container state code.</param>
/// <returns>Container names.</returns>
///
public string GetCTList(int state)
{
string list_result = "";
try {
// Instantiate the proxy class.
vzaenvmBinding env = (vzaenvmBinding)binder.InitBinding(typeof(vzaenvmBinding));
// The main input object.
get_list1 velist = new get_list1();
/* Set the Container status parameter.
* -1 means ignore the status.
*/
env_statusType[] env_status = new env_statusType[1];
env_status[0] = new env_statusType();
if (state == -1) {
env_status[0].stateSpecified = false;
}
else {
env_status[0].state = state;
}
velist.status = env_status;
/* Get the list of the Containers then loop through it getting the
* Server ID and the name for each Container
*/
foreach (string ve_eid in env.get_list(velist)) {
get_info2 ve_info = new get_info2();
ve_info.eid = new string[1];
ve_info.eid[0] = ve_eid;
/* Get the Container name from the Container configuration structure.
* Please note that if the name was not assigned to a
* Container when it was created, the "name" field will be empty.
*/
list_result += env.get_info(ve_info)[0].virtual_config.name + "\n";
}
}
catch (Exception e) {
list_result += "Exception: " + e.Message;
}
return list_result;
}