跳转到: 导航, 搜索

API 特别兴趣组/当前设计/元数据

分析

当一个服务具有元数据资源时,它通常采用以下形式

{
  "metadata": {
    "key1": "value1",
    "key2": "value2"
  }
}

对于元数据的 CRUD 操作方式似乎没有强烈的共识。

特例是编排(Orchestration)的软件配置元数据,它似乎描述了一个与其它服务元数据概念不同的概念,以及对象存储的元数据,它使用头部处理所有事情。

Glance API(v1 和 v2)都支持丰富的元数据 API,但它不将这些东西称为“元数据”,因为从技术上讲它们不是元数据。它们只是数据。元数据是*关于*数据的元数据——例如,字符串的长度是元数据。字符串是数据。长度是关于数据的元数据。Glance API 将这些东西称为“属性”。

当前设计

服务器

https://developer.openstack.org/api-ref-compute-v2.html#compute_server_metadata

{
  "metadata": {
    "name": "test_server",
    "server_type": "test"
  }
}
方式 路径 描述
GET /v2/​{tenant_id}​/servers/​{server_id}​/metadata 显示服务器元数据
PUT /v2/​{tenant_id}​/servers/​{server_id}​/metadata 创建或替换服务器元数据项
POST /v2/​{tenant_id}​/servers/​{server_id}​/metadata 更新服务器元数据项
GET /v2/​{tenant_id}​/servers/​{server_id}​/metadata/​{key} ​显示服务器元数据项详情
PUT /v2/​{tenant_id}​/servers/​{server_id}​/metadata/​{key} ​创建或更新服务器元数据项
DELETE /v2/​{tenant_id}​/servers/​{server_id}​/metadata/​{key}​ 删除服务器元数据项

Glance v1 API 中的镜像属性

HTTP/1.1 204 No Content
x-image-meta-name             Ubuntu 10.04 Plain 5GB
x-image-meta-disk-format      vhd
x-image-meta-container-format ovf
x-image-meta-size             5368709120
x-image-meta-checksum         c2e5db72bd7fd153f53ede5da5a06de3
x-image-meta-created_at       2010-02-03 09:34:01
x-image-meta-updated_at       2010-02-03 09:34:01
x-image-meta-deleted_at
x-image-meta-status           available
x-image-meta-is-public        true
x-image-meta-owner            null
x-image-meta-property-distro  Ubuntu 10.04 LTS

请注意,关于磁盘镜像或快照的所有信息都作为 HTTP 头部返回。所有头部都以 *x-image-meta* 开头,因为在这种情况下,Glance 的数据是磁盘镜像字节。在其它 OpenStack API 中用于指代关于服务器等自由形式键/值数据的“元数据”一词,在 Glance 中称为“属性”,并且任何以 *x-image-meta-property* 开头的 HTTP 头部都表示镜像的这些属性之一。 上面,自由形式属性 *distro* 的值为 *Ubunut 10.04 LTS*。

方式 路径 描述
HEAD /v1/images/​{image_id}​ 以 HTTP 头部形式返回所有镜像属性
PUT /v1/images/​{image_id} 以 HTTP 头部形式创建或替换镜像属性
POST /v1/images/​{image_id} 以 HTTP 头部形式更新镜像属性

Glance v2 API 中的镜像标签

{
    "id": "da3b75d9-3f4a-40e7-8a2c-bfab23927dea",
    "name": "cirros-0.3.0-x86_64-uec-ramdisk",
    "status": "active",
    "visibility": "public",
    "size": 2254249,
    "checksum": "2cec138d7dae2aa59038ef8c9aec2390",
    "tags": ["ping", "pong"],
    "created_at": "2012-08-10T19:23:50Z",
    "updated_at": "2012-08-10T19:23:50Z",
    "self": "/v2/images/da3b75d9-3f4a-40e7-8a2c-bfab23927dea",
    "file": "/v2/images/da3b75d9-3f4a-40e7-8a2c-bfab23927dea/file",
    "schema": "/v2/schemas/image"
}

Glance v2 API 具有简单的字符串标签概念,而不是镜像上的键/值属性。标签作为对 GET /v2/images/{image_id} API 调用中镜像顶级 JSON 文档的“tags”属性中的字符串列表返回。

方式 路径 描述
GET /v2/images/​{image_id}​ 返回所有镜像信息和标签
PATCH /v2/images/​{image_id} 创建或替换镜像标签
PUT /v2/images/{image_id}/tags/{tag} 向镜像添加标签
DELETE /v2/images/{image_id}/tags/{tag} 从镜像移除标签

快照

https://developer.openstack.org/api-ref-blockstorage-v2.html#snapshots-v2

{
  "metadata": {
    "key": "v2"
  }
}
方式 路径 描述
GET /v2/​{tenant_id}​/snapshots/​{snapshot_id}​/metadata 显示快照元数据
PUT /v2/​{tenant_id}​/snapshots/​{snapshot_id}​/metadata 更新快照元数据

要设置或取消设置快照的一个或多个元数据键值对。
要取消设置元数据键值,仅指定键名。
要设置元数据键值,指定键和值对。

堆栈

https://developer.openstack.org/api-ref-orchestration-v1.html#stack-resources

{
  "metadata": {
    "some_key": "some_value",
    "some_other_key": "some_other_value"
  }
}
方式 路径 描述
GET /v1/​{tenant_id}​/stacks/​{stack_name}​/​{stack_id}​/resources/​{resource_name}​/metadata 显示资源元数据

软件配置

https://developer.openstack.org/api-ref-orchestration-v1.html#software-config

{
  "metadata": [
    {
      "inputs": [
        {
          "default": null,
          "type": "String",
          "name": "foo",
          "value": "fooooo",
          "description": null
        },
        {
          "default": null,
          "type": "String",
          "name": "bar",
          "value": "baaaaa",
          "description": null
        },
        {
          "type": "String",
          "name": "deploy_server_id",
          "value": "ec14c864-096e-4e27-bb8a-2c2b4dc6f3f5",
          "description": "ID of the server being deployed to"
        },
        {
          "type": "String",
          "name": "deploy_action",
          "value": "CREATE",
          "description": "Name of the current action being deployed"
        },
        {
          "type": "String",
          "name": "deploy_stack_id",
          "value": "a/9bd57090-8954-48ab-bab9-adf9e1ac70fc",
          "description": "ID of the stack this deployment belongs to"
        },
        {
          "type": "String",
          "name": "deploy_resource_name",
          "value": "deployment",
          "description": "Name of this deployment resource in the stack"
        },
        {
          "type": "String",
          "name": "deploy_signal_id",
          "value": "http://192.168.20.103:8000/v1/signal/arn%3Aopenstack%3Aheat%3A%3Ae2a84fbdaeb047ae8da4b503f3b69f1f%3Astacks%2Fa%2F9bd57090-8954-48ab-bab9-adf9e1ac70fc%2Fresources%2Fdeployment?Timestamp=2014-03-19T20%3A30%3A59Z&SignatureMethod=HmacSHA256&AWSAccessKeyId=ca3571413e4a49998d580215517b3685&SignatureVersion=2&Signature=w6Iu%2BNbg86mqwSOUf1GLuKPO7KaD82PiGpL4ig9Q1l4%3D",
          "description": "ID of signal to use for signalling output values"
        }
      ],
      "group": "script",
      "name": "a-config-we5zpvyu7b5o",
      "outputs": [
        {
          "type": "String",
          "name": "result",
          "error_output": false,
          "description": null
        }
      ],
      "options": null,
      "config": "#!/bin/sh -x\necho \"Writing to /tmp/$bar\"\necho $foo > /tmp/$bar\necho -n \"The file /tmp/$bar contains `cat /tmp/$bar` for server $deploy_server_id during $deploy_action\" > $heat_outputs_path.result\necho \"Written to /tmp/$bar\"\necho \"Output to stderr\" 1>&2",
      "id": "3d5ec2a8-7004-43b6-a7f6-542bdbe9d434"
    },
    {
      "inputs": [
        {
          "default": null,
          "type": "String",
          "name": "foo",
          "value": "fu",
          "description": null
        },
        {
          "default": null,
          "type": "String",
          "name": "bar",
          "value": "barmy",
          "description": null
        },
        {
          "type": "String",
          "name": "deploy_server_id",
          "value": "ec14c864-096e-4e27-bb8a-2c2b4dc6f3f5",
          "description": "ID of the server being deployed to"
        },
        {
          "type": "String",
          "name": "deploy_action",
          "value": "CREATE",
          "description": "Name of the current action being deployed"
        },
        {
          "type": "String",
          "name": "deploy_stack_id",
          "value": "a/9bd57090-8954-48ab-bab9-adf9e1ac70fc",
          "description": "ID of the stack this deployment belongs to"
        },
        {
          "type": "String",
          "name": "deploy_resource_name",
          "value": "other_deployment",
          "description": "Name of this deployment resource in the stack"
        },
        {
          "type": "String",
          "name": "deploy_signal_id",
          "value": "http://192.168.20.103:8000/v1/signal/arn%3Aopenstack%3Aheat%3A%3Ae2a84fbdaeb047ae8da4b503f3b69f1f%3Astacks%2Fa%2F9bd57090-8954-48ab-bab9-adf9e1ac70fc%2Fresources%2Fother_deployment?Timestamp=2014-03-19T20%3A30%3A59Z&SignatureMethod=HmacSHA256&AWSAccessKeyId=7b761482f8254946bcd3d5ccb36fe939&SignatureVersion=2&Signature=giMfv%2BhrAw6y%2FCMKQIQz2IhO5PkAj5%2BfP5YsL6rul3o%3D",
          "description": "ID of signal to use for signalling output values"
        }
      ],
      "group": "script",
      "name": "a-config-we5zpvyu7b5o",
      "outputs": [
        {
          "type": "String",
          "name": "result",
          "error_output": false,
          "description": null
        }
      ],
      "options": null,
      "config": "#!/bin/sh -x\necho \"Writing to /tmp/$bar\"\necho $foo > /tmp/$bar\necho -n \"The file /tmp/$bar contains `cat /tmp/$bar` for server $deploy_server_id during $deploy_action\" > $heat_outputs_path.result\necho \"Written to /tmp/$bar\"\necho \"Output to stderr\" 1>&2",
      "id": "8da95794-2ad9-4979-8ae5-739ce314c5cd"
    }
  ]
}
方式 路径 描述
GET /v1/​{tenant_id}​/software_deployments/metadata/​{server_id}​ 显示服务器配置元数据


容器

https://developer.openstack.org/api-ref-objectstorage-v1.html#storage_container_services

HTTP/1.1 204 No Content
X-Container-Meta-Author: SamuelClemens
方式 路径 描述
POST /v1/​{account}​/​{container}​ 创建、更新或删除容器元数据
HEAD /v1/​{account}​/​{container}​ 显示容器元数据