Run Shell Command on KVM

PUT/zstack/v1/hosts/kvm/actions

Headers

Authorization: OAuth the-session-uuid

Body

{
  "kvmRunShell": {
    "hostUuids": [
      "d987c37b69e14c0fbc02e32f0689e81e",
      "6d47a55252504d49a5c8f344190a578c"
    ],
    "script": "ls"
  },
  "systemTags": [],
  "userTags": []
}

In the above example, systemTags and userTags fields can be omitted. They are listed to indicate that these two fields can be included in the body.

Curl Example

curl -H "Content-Type: application/json;charset=UTF-8" \
    -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
    -X PUT -d '{"kvmRunShell":{"hostUuids":["7b474bb39b14397b97bc7d8d0bdd8854","580f2a7f2ca23af6aa1c93e88d4a788e"],"script":"ls"}}' \
http://localhost:8080/zstack/v1/hosts/kvm/actions

Parameter List

NameTypeLocationDescriptionAllowed ValuesStarting Version
hostUuidsSetbody (contained in kvmRunShell structure)Target Host UUIDs 0.6
scriptStringbody (contained in kvmRunShell structure)Script 0.6
systemTags (optional)ListbodySystem tag 0.6
userTags (optional)ListbodyUser tag 0.6

API Response

Response Example

{
  "inventory": {
    "8903b4b7fa694c149d932bc53ee716df": {
      "returnCode": 100.0,
      "stdout": "hello",
      "errorCode": {}
    }
  }
}
NameTypeDescriptionStarting Version
errorErrorCodeError code. If not null, the operation failed. If null, the operation succeeded. See details error0.6
inventoryMapSee details inventory0.6

error

NameTypeDescriptionStarting Version
codeStringError code number, globally unique identifier of the error, e.g. SYS.1000, HOST.10010.6
descriptionStringBrief description of the error0.6
detailsStringDetailed error information0.6
elaborationStringReserved field, default is null0.6
opaqueLinkedHashMapReserved field, default is null0.6
causeErrorCodeRoot cause, the error that caused the current error. If there is no original error, this field is null0.6

inventory

NameTypeDescriptionStarting Version
returnCodeint 0.6
stdoutString 0.6
stderrString 0.6
errorCodeErrorCodeSee details errorCode0.6

errorCode

NameTypeDescriptionStarting Version
codeStringError code number, globally unique identifier of the error, e.g. SYS.1000, HOST.10010.6
descriptionStringBrief description of the error0.6
detailsStringDetailed error information0.6
elaborationStringReserved field, default is null0.6
opaqueLinkedHashMapReserved field, default is null0.6
causeErrorCodeRoot cause, the error that caused the current error. If there is no original error, this field is null0.6

SDK Examples

Java SDK

KvmRunShellAction action = new KvmRunShellAction();
action.hostUuids = asList("f3349fddda414ee0b64c5f32635ff76e","624ca9859a044fbe909f2aeef4e95b3e");
action.script = "ls";
action.sessionId = "c5e92dd1ca554dd781a50961fd8121ac";
KvmRunShellAction.Result res = action.call();

Python SDK

KvmRunShellAction action = KvmRunShellAction()
action.hostUuids = [b0e1155a97644eb1a756dd8d3de8eb3b, 04a502bd377e4763850d7a94ba4ffb43]
action.script = "ls"
action.sessionId = "72425e0cb8d8425f96114b5760d9a495"
KvmRunShellAction.Result res = action.call()