Command-Cluster
You can use the Zero Trust Host Access capability to send "commands" to a target cluster(s).
Command Payload¶
In this example, we want to send a command to "ping google.com" from the nodes in the target cluster. Note that the command is base64 encoded (highlighted below) before being sent over this control channel.
curl --location --request POST 'https://console.rafay.dev/cmdexec/v1/projects/j2q4j5k/edges/3mxg7ek/execute/' \
--header 'X-RAFAY-API-KEYID: g5439debbd24b1c876aa79b4d2997bdca7009f3g' \
--header 'Content-Type: application/json' \
--data-raw '{
"target_type" : "cluster",
"command": "cGluZyAtYyAxIGdvb2dsZS5jb20KaWYgWyAkPyA9PSAwIF07IHRoZW4KICAgIGVjaG8gJ0Nvbm5lY3Rpb24gd29ya2luZycKZWxzZQogICAgZWNobyAnRXJyb3IgaW4gY29ubmVjdGlvbiB0byBVUkwnCmZpCg==",
"content_type": "base64",
"timeout": 120
}'
Once submitted, a response with a "Exec ID" (highlighted below) is returned. This ID should be used to query for results by the calling application.
{
"Id": "dpkv0mn",
"SubmittedAt": "2021-10-11T07:44:01.09573Z",
"ClusterId": "3mxg7ek",
"ClusterName": "madhunew-ubuntu201-arm",
"ProjectId": "j2q4j5k",
"OrganizationId": "dk69nqk",
"PartnerId": "9d2wyk8",
"Command": "cGluZyAtYyAxIGdvb2dsZS5jb20KaWYgWyAkPyA9PSAwIF07IHRoZW4KICAgIGVjaG8gJ0Nvbm5lY3Rpb24gd29ya2luZycKZWxzZQogICAgZWNobyAnRXJyb3IgaW4gY29ubmVjdGlvbiB0byBVUkwnCmZpCg==",
"Target": [],
"TargetType": "cluster",
"TargetNodes": [
"madhuamd-ubuntu201"
],
"ContentType": "base64",
"Timeout": 120,
"Username": "[email protected]",
"UnreachableNodes": [
"madhuarm-ubuntu201"
],
"UnapprovedNodes": []
}
Retrieve Results¶
Use a GET request to the API Endpoint with the "Exec ID" to retrieve results.
curl --location --request GET 'https://console.rafay.dev/cmdexec/v1/projects/j2q4j5k/edges/3mxg7ek/execution/dpkv0mn/' \
--header 'X-RAFAY-API-KEYID: g5439debbd24b1c876aa79b4d2997bdca7009f3g'
Shown below is an example of what the JSON response could look like. The "Resp" section of the JSON contains the results of the command that was executed remotely on the nodes attached to the cluster.
{
"NodeResponses": [
{
"Name": "madhuamd-ubuntu201",
"Resp": {
"Return": "PING google.com (172.217.5.206) 56(84) bytes of data.\n64 bytes from lax28s10-in-f14.1e100.net (172.217.5.206): icmp_seq=1 ttl=118 time=9.98 ms\n\n--- google.com ping statistics ---\n1 packets transmitted, 1 received, 0% packet loss, time 0ms\nrtt min/avg/max/mdev = 9.979/9.979/9.979/0.000 ms\nConnection working",
"Retcode": 0,
"Success": true
}
}
],
"Responded": [
"madhuamd-ubuntu201"
],
"Unreachable": [
"madhuarm-ubuntu201"
],
"Unapproved": [],
"Pending": []
}