镜像元数据 API 调用¶
以下调用允许您创建、修改和删除镜像元数据记录。
创建镜像¶
POST /v2/images
请求体必须是 JSON 编码,并符合 image JSON 模式。例如
{
"id": "e7db3b45-8db7-47ad-8109-3fb55c2c24fd",
"name": "Ubuntu 12.10",
"tags": ["ubuntu", "quantal"]
}
成功的 HTTP 响应是 201 Created,包含一个 Location 头,其中包含新创建的镜像 URI。响应体显示创建的 image 实体。例如
{
"id": "e7db3b45-8db7-47ad-8109-3fb55c2c24fd",
"name": "Ubuntu 12.10",
"status": "queued",
"visibility": "public",
"tags": ["ubuntu", "quantal"],
"created_at": "2012-08-11T17:15:52Z",
"updated_at": "2012-08-11T17:15:52Z",
"self": "/v2/images/e7db3b45-8db7-47ad-8109-3fb55c2c24fd",
"file": "/v2/images/e7db3b45-8db7-47ad-8109-3fb55c2c24fd/file",
"schema": "/v2/schemas/image"
}
更新镜像¶
PATCH /v2/images/{image_id}
请求体必须符合 ‘application/openstack-images-v2.1-json-patch’ 媒体类型,详见附录 B。以 PATCH /v2/images/e7db3b45-8db7-47ad-8109-3fb55c2c24fd 为例
[
{"op": "replace", "path": "/name", "value": "Fedora 17"},
{"op": "replace", "path": "/tags", "value": ["fedora", "beefy"]}
]
响应体显示更新的 image 实体。例如
{
"id": "e7db3b45-8db7-47ad-8109-3fb55c2c24fd",
"name": "Fedora 17",
"status": "queued",
"visibility": "public",
"tags": ["fedora", "beefy"],
"created_at": "2012-08-11T17:15:52Z",
"updated_at": "2012-08-11T17:15:52Z",
"self": "/v2/images/e7db3b45-8db7-47ad-8109-3fb55c2c24fd",
"file": "/v2/images/e7db3b45-8db7-47ad-8109-3fb55c2c24fd/file",
"schema": "/v2/schemas/image"
}
PATCH 方法也可以用于添加或删除镜像属性。要添加一个自定义用户定义的属性,例如“login-user”,请使用以下示例请求。
[
{"op": "add", "path": "/login-user", "value": "kvothe"}
]
类似地,要删除镜像的属性,例如“login-user”,请使用以下示例请求。
[
{"op": "remove", "path": "/login-user"}
]
有关 ‘application/openstack-images-v2.1-json-patch’ 媒体类型的更多详细信息,请参阅附录 B。
属性保护
Images API 的 2.2 版本确认云提供商能够使用属性保护。因此,可能存在非管理员用户无法更新或删除的镜像属性。
添加镜像标签¶
PUT /v2/images/{image_id}/tags/{tag}
您想要添加的标签应编码到请求 URI 中。例如,要将镜像 e7db3b45-8db7-47ad-8109-3fb55c2c24fd 标记为 ‘miracle’,您将 PUT /v2/images/e7db3b45-8db7-47ad-8109-3fb55c2c24fd/tags/miracle。请求体将被忽略。
镜像标签的长度最多为 255 个字符。请参阅 ‘image’ json-schema 以确定允许哪些字符。
镜像只能使用特定字符串标记一次。多次尝试使用相同的字符串标记镜像将导致该字符串的单个实例被添加到镜像的标签列表中。
将返回 HTTP 状态码 204。
删除镜像标签¶
DELETE /v2/images/{image_id}/tags/{tag}
您想要删除的标签应编码到请求 URI 中。例如,要从镜像 e7db3b45-8db7-47ad-8109-3fb55c2c24fd 中删除标签 ‘miracle’,您将 DELETE /v2/images/e7db3b45-8db7-47ad-8109-3fb55c2c24fd/tags/miracle。请求体将被忽略。
将返回 HTTP 状态码 204。后续尝试删除该标签将导致返回 404。
列出镜像¶
GET /v2/images
请求体将被忽略。
响应体将是客户端可用的镜像列表。例如
{
"images": [
{
"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"
},
{
"id": "0d5bcbc7-b066-4217-83f4-7111a60a399a",
"name": "cirros-0.3.0-x86_64-uec",
"status": "active",
"visibility": "public",
"size": 25165824,
"checksum": "2f81976cae15c16ef0010c51e3a6c163",
"tags": [],
"created_at": "2012-08-10T19:23:50Z",
"updated_at": "2012-08-10T19:23:50Z",
"self": "/v2/images/0d5bcbc7-b066-4217-83f4-7111a60a399a",
"file": "/v2/images/0d5bcbc7-b066-4217-83f4-7111a60a399a/file",
"schema": "/v2/schemas/image"
},
{
"id": "e6421c88-b1ed-4407-8824-b57298249091",
"name": "cirros-0.3.0-x86_64-uec-kernel",
"status": "active",
"visibility": "public",
"size": 4731440,
"checksum": "cfb203e7267a28e435dbcb05af5910a9",
"tags": [],
"created_at": "2012-08-10T19:23:49Z",
"updated_at": "2012-08-10T19:23:49Z",
"self": "/v2/images/e6421c88-b1ed-4407-8824-b57298249091",
"file": "/v2/images/e6421c88-b1ed-4407-8824-b57298249091/file",
"schema": "/v2/schemas/image"
}
],
"first": "/v2/images?limit=3",
"next": "/v2/images?limit=3&marker=e6421c88-b1ed-4407-8824-b57298249091",
"schema": "/v2/schemas/images"
}
获取镜像模式¶
GET /v2/schemas/images
请求体将被忽略。
响应体包含一个 json-schema 文档,显示一个 images 实体(一个 image 实体的容器)。例如
{
"name": "images",
"properties": {
"images": {
"items": {
"type": "array",
"name": "image",
"properties": {
"id": {"type": "string"},
"name": {"type": "string"},
"visibility": {"enum": ["public", "private"]},
"status": {"type": "string"},
"protected": {"type": "boolean"},
"tags": {
"type": "array",
"items": {"type": "string"}
},
"checksum": {"type": "string"},
"size": {"type": "integer"},
"created_at": {"type": "string"},
"updated_at": {"type": "string"},
"file": {"type": "string"},
"self": {"type": "string"},
"schema": {"type": "string"}
},
"additionalProperties": {"type": "string"},
"links": [
{"href": "{self}", "rel": "self"},
{"href": "{file}", "rel": "enclosure"},
{"href": "{schema}", "rel": "describedby"}
]
}
},
"schema": {"type": "string"},
"next": {"type": "string"},
"first": {"type": "string"}
},
"links": [
{"href": "{first}", "rel": "first"},
{"href": "{next}", "rel": "next"},
{"href": "{schema}", "rel": "describedby"}
]
}
获取镜像模式¶
GET /v2/schemas/image
请求体将被忽略。
响应体包含一个 json-schema 文档,显示一个 image。例如
{
"name": "image",
"properties": {
"id": {"type": "string"},
"name": {"type": "string"},
"visibility": {"enum": ["public", "private"]},
"status": {"type": "string"},
"protected": {"type": "boolean"},
"tags": {
"type": "array",
"items": {"type": "string"}
},
"checksum": {"type": "string"},
"size": {"type": "integer"},
"created_at": {"type": "string"},
"updated_at": {"type": "string"},
"file": {"type": "string"},
"self": {"type": "string"},
"schema": {"type": "string"}
},
"additionalProperties": {"type": "string"},
"links": [
{"href": "{self}", "rel": "self"},
{"href": "{file}", "rel": "enclosure"},
{"href": "{schema}", "rel": "describedby"}
]
}