为 os-migrations API 添加分页和 changes-since 过滤支持

https://blueprints.launchpad.net/nova/+spec/add-pagination-and-change-since-for-migration-list

此蓝图为 GET /os-migrations 请求添加了可选参数 limitmarker,以支持分页。

此蓝图还为 GET /os-migrations 请求添加了可选参数 changes-since,以支持按最后更新时间过滤响应数据。

问题描述

目前,os-migrations API 不支持分页。在大型部署中,迁移记录的数量也可能非常大,查询所有记录可能导致性能瓶颈,因此支持分页将非常有用。

此外,os-migrations API 不支持按最后更新时间过滤迁移记录。对于生产部署,系统将运行很长时间,迁移记录的数量也会非常多。支持按最后更新时间过滤将非常有用。

用例

对于大型生产部署,管理员可以使用分页和最后更新时间过滤器来获得更高效的数据库查询。

提议的变更

添加一个 API 微版本,允许使用通用的分页机制,通过 GET /os-migrations 请求的 limitmarker 可选参数获取多个迁移。并使用 changes-since 可选参数添加过滤器到 GET /os-migrations 请求。

  • marker:上一页的最后一个迁移 UUID。显示 “marker” 之后的迁移列表。

  • limit:要显示的迁移的最大数量。如果 limit 大于 Nova API 的 [api]/max_limit 选项,则将使用 [api]/max_limit 代替。

对于多单元格,我们可能有具有相同 ID 的迁移,将迁移 ID 作为分页标记不起作用。目前,迁移记录在其上有一个 uuid 列 [1],我们只需要在响应中添加迁移 UUID 字段,并且迁移 UUID 需要作为分页标记。

我们建议在从所有多个单元格获取结果后,在计算 API 代码中对结果进行合并排序,并且结果按 [‘created_at’, ‘id’] 键降序排序。

此外,由于我们将为 os-migrations API 的响应添加 uuid 字段,我们也将借此机会将迁移 uuid 添加到 GET /servers/{server_id}/migrations/{migration_id}GET /servers/{server_id}/migrations 服务器迁移 API 的响应中。

备选方案

数据模型影响

将在 migrations.updated_at 上添加数据库索引,以提高按 ‘changes-since’ 参数过滤迁移的性能。

REST API 影响

该提案将添加 API 微版本,用于使用通用的分页机制获取多个迁移。新的可选参数 limitmarkerchanges-since 将添加到 GET /os-migrations 请求中。

通用请求格式

GET /os-migrations?limit={limit}&marker={migration_uuid}
  1. 获取所有迁移

    GET /os-migrations
    

    响应

    {
    "migrations": [
        {
            "created_at": "2012-10-29T13:42:02.000000",
            "dest_compute": "compute2",
            "dest_host": "1.2.3.4",
            "dest_node": "node2",
            "id": 1,
            "instance_uuid": "instance_id_123",
            "new_instance_type_id": 2,
            "old_instance_type_id": 1,
            "source_compute": "compute1",
            "source_node": "node1",
            "status": "Done",
            "updated_at": "2012-10-29T13:42:02.000000",
            "uuid": "12341d4b-346a-40d0-83c6-5f4f6892b650"
        },
        {
            "created_at": "2013-10-22T13:42:02.000000",
            "dest_compute": "compute20",
            "dest_host": "5.6.7.8",
            "dest_node": "node20",
            "id": 2,
            "instance_uuid": "instance_id_456",
            "new_instance_type_id": 6,
            "old_instance_type_id": 5,
            "source_compute": "compute10",
            "source_node": "node10",
            "status": "Done",
            "updated_at": "2013-10-22T13:42:02.000000",
            "uuid": "56781d4b-346a-40d0-83c6-5f4f6892b650"
        },
        {
            "created_at": "2013-10-22T13:45:02.000000",
            "dest_compute": "compute21",
            "dest_host": "5.6.7.8",
            "dest_node": "node21",
            "id": 3,
            "instance_uuid": "instance_id_4561",
            "new_instance_type_id": 6,
            "old_instance_type_id": 5,
            "source_compute": "compute10",
            "source_node": "node10",
            "status": "Done",
            "updated_at": "2013-10-22T13:45:02.000000",
            "uuid": "56791d4b-346a-40d0-83c6-5f4f6892b650"
        }
    ]
    }
    
  2. 获取最多 2 个迁移

    GET /os-migrations?limit=2
    

    响应

    {
    "migrations": [
        {
            "created_at": "2012-10-29T13:42:02.000000",
            "dest_compute": "compute2",
            "dest_host": "1.2.3.4",
            "dest_node": "node2",
            "id": 1,
            "instance_uuid": "instance_id_123",
            "new_instance_type_id": 2,
            "old_instance_type_id": 1,
            "source_compute": "compute1",
            "source_node": "node1",
            "status": "Done",
            "updated_at": "2012-10-29T13:42:02.000000",
            "uuid": "12341d4b-346a-40d0-83c6-5f4f6892b650"
        },
        {
            "created_at": "2013-10-22T13:42:02.000000",
            "dest_compute": "compute20",
            "dest_host": "5.6.7.8",
            "dest_node": "node20",
            "id": 2,
            "instance_uuid": "instance_id_456",
            "new_instance_type_id": 6,
            "old_instance_type_id": 5,
            "source_compute": "compute10",
            "source_node": "node10",
            "status": "Done",
            "updated_at": "2013-10-22T13:42:02.000000",
            "uuid": "56781d4b-346a-40d0-83c6-5f4f6892b650"
        }
    ],
    "migrations_links": [
        {
            "href": "https://openstack.example.com/v2.1/os-migrations?limit=2&marker=56781d4b-346a-40d0-83c6-5f4f6892b650",
            "rel": "next"
        }
    ]
    }
    
  3. 获取 uuid=12341d4b-346a-40d0-83c6-5f4f6892b650 之后的全部迁移

    GET /os-migrations?marker=12341d4b-346a-40d0-83c6-5f4f6892b650
    

    响应

    {
    "migrations": [
        {
            "created_at": "2013-10-22T13:42:02.000000",
            "dest_compute": "compute20",
            "dest_host": "5.6.7.8",
            "dest_node": "node20",
            "id": 2,
            "instance_uuid": "instance_id_456",
            "new_instance_type_id": 6,
            "old_instance_type_id": 5,
            "source_compute": "compute10",
            "source_node": "node10",
            "status": "Done",
            "updated_at": "2013-10-22T13:42:02.000000",
            "uuid": "56781d4b-346a-40d0-83c6-5f4f6892b650"
        },
        {
            "created_at": "2013-10-22T13:45:02.000000",
            "dest_compute": "compute21",
            "dest_host": "5.6.7.8",
            "dest_node": "node21",
            "id": 3,
            "instance_uuid": "instance_id_4561",
            "new_instance_type_id": 6,
            "old_instance_type_id": 5,
            "source_compute": "compute10",
            "source_node": "node10",
            "status": "Done",
            "updated_at": "2013-10-22T13:45:02.000000",
            "uuid": "56791d4b-346a-40d0-83c6-5f4f6892b650"
        }
    ]
    }
    
  4. 获取 changes-since=2013-10-22T13:45:02.000000 之后的全部迁移

    GET /os-migrations?changes-since=2013-10-22T13:45:02.000000
    

注意

提供的时间应为 ISO 8061 格式的时间。例如 2013-10-22T13:45:02.000000, 2017-10-18T16:06:59Z

响应

{
"migrations":[
    {
        "created_at": "2013-10-22T13:45:02.000000",
        "dest_compute": "compute21",
        "dest_host": "5.6.7.8",
        "dest_node": "node21",
        "id": 3,
        "instance_uuid": "instance_id_4561",
        "new_instance_type_id": 6,
        "old_instance_type_id": 5,
        "source_compute": "compute10",
        "source_node": "node10",
        "status": "Done",
        "updated_at": "2013-10-22T13:45:02.000000",
        "uuid": "56791d4b-346a-40d0-83c6-5f4f6892b650"
    }
]
}

安全影响

通知影响

其他最终用户影响

Python-novaclient 将被修改以处理新的微版本,以支持迁移分页。

性能影响

其他部署者影响

开发人员影响

实现

负责人

主要负责人

江益坤

其他贡献者

郑振宇

工作项

  • 创建一个新的 API 微版本,用于使用通用的分页机制和时间戳过滤获取多个迁移,并在响应中添加迁移 UUID 字段。

  • 修改 Nova 客户端以处理新的微版本,以支持迁移分页。

依赖项

测试

需要新的树内功能和单元测试。

文档影响

需要新的 API 微版本和用量文档。

参考资料

历史

修订

发布名称

描述

Newton

提议

Queens

重新提出