cluster.execute
Executes an RVC command on either of the nodes in a cluster, or on both nodes.
JSON-RPC Request
{"jsonrpc":"2.0","id":1,"method":"cluster.execute","params":{"method":"<rvc_method>","params":{},"target":"<target>"}}
Request parameters
| Argument | Type | Description | Required | Default |
|---|---|---|---|---|
method | String | The RVC method to be executed on the cluster node or nodes. | Yes | - |
params | Object | The parameters to be passed to the RVC method specified by method. The acceptable parameters depend on the method being used. | No | nil |
target | String | The node or nodes in the cluster where the method execution will take place. Accepted values: primary, secondary, other, both. | No | other |
JSON-RPC Response
{
"jsonrpc": "2.0",
"id": 1,
"result": [
{
"hostname": "<node_hostname>",
"member": "self",
"role": "<role>",
"result": "<method_result>"
}
]
}
CLI Examples
Example 1: Retrieve the running Docker containers on both nodes in a cluster
The following example uses the docker.containers method to retrieve the running Docker containers on both nodes in a cluster.
rvc cluster execute --method docker.containers --target both
Response
Response from sit0001red0 (Secondary in the cluster)
RVC method 'docker.containers' executed by the same node that did receive the 'cluster.execute' call
====================================================================================================
ID Image Names Status In Cluster
-------------------------------------------------------------------------------------------------
64add2310268 EXAMPLE.dkr.ecr.us-east-1.amazonaws.com/mysql mysql Up 3 weeks no
18c584e85413 nginx nginx Up 3 weeks no
Response from sit0001red1 (Primary in the cluster)
RVC method 'docker.containers' executed by the node that did not receive the 'cluster.execute' call
===================================================================================================
ID Image Names Status In Cluster
-----------------------------------------------------------------------------------------------------------------------------
aed58f9da2d0 adminer:4-fastcgi docker-container-adminer-resource Up 3 weeks yes
56aa51d08290 EXAMPLE.dkr.ecr.us-east-1.amazonaws.com/mysql mysql Up 3 weeks no
002a83e0b4c7 nginx nginx Up 3 weeks no
Example 2: Stop a KVM virtual machine on the secondary node in a cluster
The following example uses the kvm.shutdown method to stop a KVM virtual machine named kvm1 on the secondary node in a cluster. This example shows how to specify additional parameters for a method using --params. You simply convert the parameters to a JSON format.
rvc cluster execute --method kvm.shutdown --params '{"hostname":"kvm1"}' --target secondary
Response
{
"jsonrpc": "2.0",
"id": 1,
"result": [
{
"hostname": "sit0001red1",
"member": "other",
"role": "secondary",
"result": "Shutting down kvm1..."
}
]
}