Before you delve into the details of the individual file management operations, we have to discuss an important Agent API feature called Request Routing.
Most of the Virtuozzo-specific methods have the Server ID (eid) input parameter which is used to specify the Container on which the operation should be performed. For example, when you start or stop a Container, you pass Server ID as an input parameter (see Starting, Stopping, Restarting a Container). In contrast, methods of the classes that allow to perform operations on both Virtuozzo Containers and Hardware Nodes don't usually have this parameter. For example, the filerBinding.list
method (lists files and directories) does not have the eid
parameter. So how do you get file listing for a particular Container? That's where request routing comes in.
Routing
You can tell Agent to route the request to the specified Container and execute it there instead of executing it on the Hardware Node level. You accomplish this by including the dst/host
(destination host) parameter in the Agent request message header to contain the Server ID of the target Virtuozzo Container. By not including the dst/host
parameter in the message header, you are instructing Agent to perform the operation on the Hardware Node.
We already have a sample class called Binder
that implements this functionality. The InitBinding
method of the Binder
class instantiates a proxy class and populates the request message header. The overloaded InitBinding
method accepts the Container Server ID as a second parameter and adds the dst/host
parameter to the header. To route a request to a particular Virtuozzo Container, use this method to instantiate a proxy class passing the target Server ID to it.
The following sample code shows how to create a proxy class object without the request routing information specified.
vzaenvmBinding env = (vzaenvmBinding)binder.InitBinding(typeof(vzaenvmBinding));
The following sample uses the request routing feature. The requests initiated by the class methods will be routed to the specified Virtuozzo Container.
string ve_eid = "3b8f950a-981d-b94d-bde1-647df39674f1";
filerBinding filer = (filerBinding)binder.InitBinding(typeof(filerBinding), ve_eid);
So the question is, when exactly do you use the request routing feature? The rule of thumb is as follows:
eid
) as a parameter, you have to use request routing.eid
parameter, don't use request routing. If you try to route a request to a Container by mistake, it most likely will fail with a message saying that the functionality is not supported.There are only a few classes that rely on the request routing functionality when the target of an operation is a Virtuozzo Container. Here's the list:
Class name |
Description |
|
Computer management. Provides methods for managing Hardware Nodes and Containers as if they were regular physical machines. |
|
Provides methods for managing files and directories. |
|
Firewall management (Linux only). |
|
System processes management. Provides methods for executing a program inside a Container and for killing system processes. |
|
Services management. Provides methods for managing OS system services. |
|
Provides methods for managing users and groups on Hardware Nodes and Virtuozzo Containers. |