Skip to content

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 target clusters. The command is base64 encoded before being sent over this control channel.

curl --location --request POST 'https://app.phani-ptnr-1219.dev.rafay-edge.net/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 "Job ID" is returned. This Job ID should be used to query for results.

{
    "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 "Job ID" to retrieve results.

curl --location --request GET 'https://app.phani-ptnr-1219.dev.rafay-edge.net/cmdexec/v1/projects/j2q4j5k/edges/3mxg7ek/execution/dpkv0mn/' \
--header 'X-RAFAY-API-KEYID: g5439debbd24b1c876aa79b4d2997bdca7009f3g'

Example Output

{
    "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": []
}