You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用vSphere REST API创建资源池遇阻,需明确parent字段及相关方法

vCenter REST API 自动化创建资源池、文件夹及虚拟机问题

环境结构

  • vcs.domain
    • datacenter
      • cluster
        • resource pool 1
        • resource pool 2

遇到的问题

  • 调用/api/vcenter/resource-pool的POST请求创建第三个资源池始终失败,核心困惑是请求体中parent字段的取值规则。
  • 创建VM文件夹和DVS端口组时也遇到类似的字段取值问题。

已完成操作

  • 完成认证并获取访问令牌
  • GET请求可正常执行
  • 尝试过多种POST请求体(例如:{"name": "test", "parent": "cluster"},也包含过所有非必填字段)

错误响应

{
    "error_type": "NOT_FOUND",
    "messages": [
        {
            "args": [],
            "default_message": "Resource pool with identifier '{}' does not exist.",
            "id": "com.vmware.api.vcenter.resourcepool.not_found"
        }
    ]
}

解决方案

资源池创建(/api/vcenter/resource-pool POST)

错误根源是parent字段不能填集群名称,必须填集群或父资源池的UUID——vCenter REST API所有涉及资源引用的字段,几乎都要求用ID而非名称。

获取父资源ID

  • 获取集群ID:调用GET /api/vcenter/cluster,从返回结果中找到目标集群的cluster字段值(UUID格式)
  • 获取现有资源池ID:调用GET /api/vcenter/resource-pool,从返回结果中找到对应资源池的resource_pool字段值

正确请求体示例

{
    "name": "test",
    "parent": "目标集群的UUID值",
    "cpu_allocation": {
        "expandable_reservation": true,
        "limit": -1,
        "reservation": 0,
        "shares": {
            "level": "NORMAL"
        }
    },
    "memory_allocation": {
        "expandable_reservation": true,
        "limit": -1,
        "reservation": 0,
        "shares": {
            "level": "NORMAL"
        }
    }
}

VM文件夹创建(/api/vcenter/folder POST)

VM文件夹的parent字段需要填数据中心ID或父文件夹ID,同样不能用名称:

  1. 获取数据中心ID:调用GET /api/vcenter/datacenter,取datacenter字段的UUID
  2. 正确请求体示例:
{
    "type": "VM",
    "name": "new-vm-folder",
    "parent": "数据中心UUID"
}

DVS端口组创建(/api/vcenter/network/dvs/portgroup POST)

端口组的switch字段需要填分布式交换机的ID,可选的folder字段填文件夹ID:

  1. 获取分布式交换机ID:调用GET /api/vcenter/network/dvs,取dvs字段的UUID
  2. 正确请求体示例:
{
    "switch": "分布式交换机UUID",
    "name": "new-portgroup",
    "vlan": {
        "type": "STANDARD",
        "vlan_id": 100
    },
    "port_config": {
        "block_all_ports": false,
        "ipfix_enabled": false,
        "port_group_type": "EARLY_BINDING"
    }
}

内容的提问来源于stack exchange,提问作者Mathieu Dupont

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 13:43:27