CreateAffinityGroup

API Request

URLs
POST zstack/v1/affinity-groups
Headers
Authorization: OAuth the-session-uuid
Body
{
  "params": {
    "name": "vm-affinity-group",
    "description": "vm affinity group for test vms",
    "policy": "antiSoft",
    "type": "host"
  },
  "systemTags": [],
  "userTags": []
}
Note: In the preceding sample, both systemTags and userTags are optional. These two fields can be included in the body structure.
Curl Sample
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X POST -d '{"params":{"name":"vm-affinity-group","description":"vm affinity group for test vms","policy":"antiSoft","type":"host"}}' \
http://localhost:8080/zstack/v1/affinity-groups
Request Parameters
Name Type Location Description Optional Value Starting Version
name String body (contained in the params structure) The affinity group name. 2.3
description String body (contained in the params structure) Optional. The detailed description of the affinity group. 2.3
policy String body (contained in the params structure) The affinity group policy.
  • antiSoft
2.3
type String body (contained in the params structure) Optional. The affinity group type.
  • The current type is host.
  • In the future, network, router, data center, and rack affinity groups will be supported.
  • host
2.3
resourceUuid String body (contained in the params structure) Optional. The resource UUID. 2.3
systemTags List body Optional. The system tags. 2.3
userTags List body Optional. The user tags. 2.3

API Response

Sample Response
{
  "inventory": {
    "uuid": "05ad02be7c5f4a6a9b6d164cb2980be6",
    "name": "affinity-group-test",
    "description": "affinity group for test",
    "policy": "ANTISOFT",
    "version": "1.0",
    "type": "HOST"
  }
}
Name Type Description Starting Version
error ErrorCode The error code. If not null, the operation fails, or vice versa. For more information, see error. 2.3
inventory AffinityGroupInventory See inventory. 2.3
#error
Name Type Description Starting Version
code String The error code, which is a numbered or alphanumeric code that specifies an error. For example, SYS.1000, HOST.1001. 2.3
description String The brief description of the error. 2.3
details String The details about the error. 2.3
elaboration String The reserved field. Default value: null. 2.3
opaque LinkedHashMap The reserved field. Default value: null. 2.3
cause ErrorCode The root error, which is the associated root cause of the current error. If no root error exists, this parameter is null. 2.3
#inventory
Name Type Description Starting Version
uuid String The resource UUID. 2.3
name String The resource name. 2.3
description String The detailed description of the resource. 2.3
policy String The affinity group policy. 2.3
version String The version of the affinity group allocation algorithm. 2.3
type String The affinity group type.
  • The current type is host.
  • In the future, network, router, data center, and rack affinity groups will be supported.
2.3
appliance String The affinity group appliance. 2.3
state String 2.3
createDate Timestamp The creation date. 2.3
lastOpDate Timestamp The last operation date. 2.3
usages List See usages. 2.3
#usages
Name Type Description Starting Version
uuid String The resource binding UUID of the affinity group. 2.3
affinityGroupUuid String The affinity group UUID. 2.3
resourceUuid String The UUID of the resource that joins the affinity group. 2.3
resourceType String The type of the resource that joins the affinity group. 2.3
createDate Timestamp The creation date. 2.3
lastOpDate Timestamp The last operation date. 2.3

SDK Sample

Java SDK
CreateAffinityGroupAction action = new CreateAffinityGroupAction();
action.name = "vm-affinity-group";
action.description = "vm affinity group for test vms";
action.policy = "antiSoft";
action.type = "host";
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
CreateAffinityGroupAction.Result res = action.call();
Python SDK
CreateAffinityGroupAction action = CreateAffinityGroupAction()
action.name = "vm-affinity-group"
action.description = "vm affinity group for test vms"
action.policy = "antiSoft"
action.type = "host"
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
CreateAffinityGroupAction.Result res = action.call()

DeleteAffinityGroup

API Request

URLs
DELETE zstack/v1/affinity-groups/{uuid}?deleteMode={deleteMode}
Headers
Authorization: OAuth the-session-uuid
Curl Sample
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X DELETE http://localhost:8080/zstack/v1/affinity-groups/ed0b2f029cc53ca385adc19dd36b51be?deleteMode=Permissive
Request Parameters
Name Type Location Description Optional Value Starting Version
uuid String url The resource UUID. 2.2
deleteMode String url Optional. The delete mode. 2.2
systemTags List body Optional. The system tags. 2.2
userTags List body Optional. The user tags. 2.2

API Response

When the API succeeded, an empty JSON structure {} is returned. When the API failed, the returned JSON structure includes an error field. For example,
{
    "error": {
        "code": "SYS.1001",
        "description": "A message or a operation timeout",
        "details": "Create VM on KVM timeout after 300s"
    }
}

SDK Sample

Java SDK
DeleteAffinityGroupAction action = new DeleteAffinityGroupAction();
action.uuid = "ed0b2f029cc53ca385adc19dd36b51be";
action.deleteMode = "Permissive";
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
DeleteAffinityGroupAction.Result res = action.call();
Python SDK
DeleteAffinityGroupAction action = DeleteAffinityGroupAction()
action.uuid = "ed0b2f029cc53ca385adc19dd36b51be"
action.deleteMode = "Permissive"
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
DeleteAffinityGroupAction.Result res = action.call()

QueryAffinityGroup

API Request

URLs
GET zstack/v1/affinity-groups
GET zstack/v1/affinity-groups/{uuid}
Headers
Authorization: OAuth the-session-uuid
Curl Sample
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X GET http://localhost:8080/zstack/v1/affinity-groups?q=uuid=656ebc992c3333fea209c6c90e6a76cf
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X GET http://localhost:8080/zstack/v1/affinity-groups/b49759dff8593098a1d106c8129974cf

Queryable Fields

You can check all queryable fields and resource names that can be queried across tables by using zstack-cli, entering QueryAffinityGroup, and pressing the Tab key.

API Response

Sample Response
{
  "inventories": [
    {
      "uuid": "99fa95af4aac4eaabd320dbdd6d36ef8",
      "name": "affinity-group-test",
      "description": "affinity group for test",
      "policy": "ANTISOFT",
      "version": "1.0",
      "type": "HOST",
      "usages": [
        {
          "resourceUuid": "acedd8848c874cd7b1c68df7c593f6c1",
          "resourceType": "HOST"
        }
      ]
    }
  ]
}
Name Type Description Starting Version
error ErrorCode The error code. If not null, the operation fails, or vice versa. For more information, see error. 2.3
inventories List See inventories. 2.3
#error
Name Type Description Starting Version
code String The error code, which is a numbered or alphanumeric code that specifies an error. For example, SYS.1000, HOST.1001. 2.3
description String The brief description of the error. 2.3
details String The details about the error. 2.3
elaboration String The reserved field. Default value: null. 2.3
opaque LinkedHashMap The reserved field. Default value: null. 2.3
cause ErrorCode The root error, which is the associated root cause of the current error. If no root error exists, this parameter is null. 2.3
#inventories
Name Type Description Starting Version
uuid String The resource UUID. 2.3
name String The resource name. 2.3
description String The detailed description of the resource. 2.3
policy String The affinity group policy. 2.3
version String The version of the affinity group allocation algorithm. 2.3
type String The affinity group type.
  • The current type is host.
  • In the future, network, router, data center, and rack affinity groups will be supported.
2.3
appliance String The affinity group appliance. 2.3
state String 2.3
createDate Timestamp The creation date. 2.3
lastOpDate Timestamp The last operation date. 2.3
usages List See usages. 2.3
#usages
Name Type Description Starting Version
uuid String The resource binding UUID of the affinity group. 2.3
affinityGroupUuid String The affinity group UUID. 2.3
resourceUuid String The UUID of the resource that joins the affinity group. 2.3
resourceType String The type of the resource that joins the affinity group. 2.3
createDate Timestamp The creation date. 2.3
lastOpDate Timestamp The last operation date. 2.3

SDK Sample

Java SDK
QueryAffinityGroupAction action = new QueryAffinityGroupAction();
action.conditions = asList("uuid=bceb37906e673f37bb425933bdf2df46");
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
QueryAffinityGroupAction.Result res = action.call();
Python SDK
QueryAffinityGroupAction action = QueryAffinityGroupAction()
action.conditions = ["uuid=3714ccec7a933aba94c073fcba6e52bd"]
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
QueryAffinityGroupAction.Result res = action.call()







Download

Already filled the basic info? Click here.

Enter at least 2 characters.
Invalid mobile number.
Enter at least 4 characters.
Invalid email address.
Wrong code. Try again. Send Code Resend Code (60s)

An email with a verification code will be sent to you. Make sure the address you provided is valid and correct.

Download

Not filled the basic info yet? Click here.

Invalid email address or mobile number.

Email Us

contact@zstack.io
ZStack certification training consulting
Enter at least 2 characters.
Invalid mobile number.
Enter at least 4 characters.
Invalid email address.
Wrong code. Try again. Send Code Resend Code (60s)

Email Us

contact@zstack.io

The download link is sent to your email address.

If you don't see it, check your spam folder, subscription folder, or AD folder. After receiving the email, click the URL to download the documentation.

The download link is sent to your email address.

If you don't see it, check your spam folder, subscription folder, or AD folder.
Or click on the URL below. (For Internet Explorer, right-click the URL and save it.)

Thank you for using ZStack products and services.

Submit successfully.

We'll connect soon.

Thank you for choosing ZStack products and services.

Back to Top