创建自定义属性键

POST/zstack/v1/resource-attributes

Headers

Authorization: OAuth the-session-uuid

Body

{
  "params": {
    "name": "Operations personnel"
  },
  "systemTags": [],
  "userTags": []
}

上述示例中systemTagsuserTags字段可以省略。列出是为了表示body中可以包含这两个字段。

Curl示例

curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X POST -d '{"params":{"name":"Operations personnel"}}' \
http://localhost:8080/zstack/v1/resource-attributes

参数列表

名字类型位置描述可选值起始版本
nameStringbody(包含在params结构中)自定义属性键名称 4.10.16
description (可选)Stringbody(包含在params结构中)资源的详细描述 4.10.16
resourceTypes (可选)Listbody(包含在params结构中)该属性支持的资源类型列表, 默认支持所有可支持的属性 4.10.16
constraints (可选)Listbody(包含在params结构中)属性限制列表 4.10.16
resourceUuid (可选)Stringbody(包含在params结构中)资源 UUID 4.10.16
tagUuids (可选)Listbody(包含在params结构中)标签 UUID 列表 4.10.16
systemTags (可选)Listbody系统标签 4.10.16
userTags (可选)Listbody用户标签 4.10.16

API返回

返回示例

{
  "inventory": {
    "uuid": "ff03a2b491023030bf58b1b35ea9cd00",
    "name": "OperationsPersonnel",
    "description": "Kinny",
    "resourceTypes": [
      "VmInstanceVO"
    ],
    "createDate": "Nov 14, 2017 2:20:57 PM",
    "lastOpDate": "Nov 14, 2017 2:20:57 PM",
    "constraints": [
      {
        "id": 1,
        "keyUuid": "ff03a2b491023030bf58b1b35ea9cd00",
        "type": "option",
        "parameter": "Kinny",
        "createDate": "Nov 14, 2017 2:20:57 PM",
        "lastOpDate": "Nov 14, 2017 2:20:57 PM"
      }
    ]
  }
}
名字类型描述起始版本
successboolean创建是否成功4.10.16
inventoryResourceAttributeKeyInventory详情参考inventory4.10.16
errorErrorCode错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error0.6

inventory

名字类型描述起始版本
uuidString自定义属性键 UUID4.10.16
nameString自定义属性键名称4.10.16
descriptionString资源的详细描述4.10.16
createDateTimestamp创建时间4.10.16
lastOpDateTimestamp最后一次修改时间4.10.16

error

名字类型描述起始版本
odeString错误码号,错误的全局唯一标识,例如SYS.1000, HOST.10010.6
descriptionString错误的概要描述0.6
detailsString错误的详细信息0.6
elaborationString保留字段,默认为null0.6
opaqueLinkedHashMap保留字段,默认为null0.6
causeErrorCode根错误,引发当前错误的源错误,若无原错误,该字段为null0.6

SDK示例

Java SDK

CreateResourceAttributeKeyAction action = new CreateResourceAttributeKeyAction();
action.name = "Operations personnel";
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
CreateResourceAttributeKeyAction.Result res = action.call();

Python SDK

action = CreateResourceAttributeKeyAction()
action.name = "Operations personnel"
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
res = action.call()