Vcenter获取资源信息

Vcenter获取资源信息

Vcenter获取资源具体操作流程

1、获取访问凭证Create Session

使用 API 创建会话。这相当于登录。此操作将安全上下文中提供的用户凭据交换为用于验证后续调用的会话令牌。为了验证后续调用,客户端需要包含会话令牌。对于 REST API 调用,应使用 HTTP vmware-api-session-id 标头字段。

官方文档:

https://developer.broadcom.com/xapis/vsphere-automation-api/latest/cis/api/session/post/https://developer.broadcom.com/xapis/vsphere-automation-api/latest/cis/api/session/post/

链接地址:https://{api_host}/api/session

返回值:token(后续操作都需要用到这个token)

2、List Datacenter(获取数据中心数据)

返回有关 vCenter 中与 Datacenter.FilterSpec 匹配的最多 1000 个可见(受权限检查)数据中心的信息。

官方地址:

https://developer.broadcom.com/xapis/vsphere-automation-api/latest/vcenter/api/vcenter/datacenter/get/https://developer.broadcom.com/xapis/vsphere-automation-api/latest/vcenter/api/vcenter/datacenter/get/

访问地址:https://{api_host}/api/vcenter/datacenter

返回值:有关与 Datacenter.FilterSpec 匹配的数据中心的常用信息。

[

{

"datacenter": "string",

"name": "string"

}

]

datacenter:数据中心的标识符。当客户端将此结构的值作为参数传递时,该字段必须是资源类型的标识符:Datacenter。当操作返回此结构的值作为结果时,该字段将是资源类型的标识符:Datacenter。

name:数据中心的名称。

3、List Host(获取宿主机)

返回 vCenter 中与 Host.FilterSpec 匹配的最多 2500 个可见(受权限检查)主机的信息。

官方文档:

https://developer.broadcom.com/xapis/vsphere-automation-api/latest/vcenter/api/vcenter/host/get/https://developer.broadcom.com/xapis/vsphere-automation-api/latest/vcenter/api/vcenter/host/get/

访问地址:https://{api_host}/api/vcenter/host

返回值:

[

{

"host": "string",

"name": "string",

"connection_state": "string",

"power_state": "string"

}

]

host:主机的标识符。当客户端将此结构的值作为参数传递时,该字段必须是资源类型的标识符:HostSystem。当操作返回此结构的值作为结果时,该字段将是资源类型的标识符:HostSystem。、

name:主机名

connection_state:Host.ConnectionState 枚举类型定义主机的连接状态。 CONNECTED :主机已连接到 vCenter Server DISCONNECTED :主机与 vCenter Server 断开连接 NOT_RESPONDING :VirtualCenter 未从服务器接收检测信号。再次收到心跳后,状态会自动更改为已连接。

power_state:Host.PowerState 枚举类型定义主机的电源状态。 POWERED_ON :主机已上电。进入待机模式的主机也处于此状态。 POWERED_OFF :用户通过 vCenter 服务器专门关闭主机电源。这种状态不是一种确定状态,因为vCenter Server发出主机下电命令后,主机可能会崩溃,或者杀掉所有进程但无法下电。 STANDBY :主机专门置于待机模式,由用户明确设置或由 DPM 自动设置。这种状态不是一种确定状态,因为VirtualCenter发出将主机置于待机状态的命令后,主机可能会崩溃,或者杀死所有进程但无法进入待机模式。退出待机模式的主机也处于此状态。

4、List VM(列出虚拟机)

返回有关 vCenter 中与 VM.FilterSpec 匹配的最多 4000 个可见(受权限检查)虚拟机的信息。

官方文档:

https://developer.broadcom.com/xapis/vsphere-automation-api/latest/vcenter/api/vcenter/vm/get/https://developer.broadcom.com/xapis/vsphere-automation-api/latest/vcenter/api/vcenter/vm/get/

访问地址:https://{api_host}/api/vcenter/vm

返回值:有关与 VM.FilterSpec 匹配的虚拟机的常用信息。

[

{

"vm": "string",

"name": "string",

"power_state": "string",

"cpu_count": 0,

"memory_size_MiB": 0

}

]

vm:虚拟机的标识符。当客户端将此结构的值作为参数传递时,该字段必须是资源类型的标识符:VirtualMachine。当操作返回此结构的值作为结果时,该字段将是资源类型的标识符:VirtualMachine。

name:虚拟机的名称。

power_state:Power.State 枚举类型定义虚拟机的有效电源状态。 POWERED_OFF :虚拟机已关闭。 POWERED_ON :虚拟机已启动。 SUSPENDED :虚拟机已暂停。

cpu_count:CPU 核心数。如果虚拟机配置不可用,则该字段将被取消设置。例如,如果服务器无法访问磁盘上的虚拟机文件,则配置信息将不可用,并且在虚拟机创建的初始阶段通常也不可用。

memory_size_MiB:内存大小(以兆字节为单位)。如果虚拟机配置不可用,则该字段将被取消设置。例如,如果服务器无法访问磁盘上的虚拟机文件,则配置信息将不可用,并且在虚拟机创建的初始阶段通常也不可用。

# 5、Get Vm(获取某个虚拟机的详细信息)

返回有关虚拟机的信息。如果您不具备如下所述的所有权限:

参数 vm 引用的资源 VirtualMachine 需要 System.Read。

官方文档:

https://developer.broadcom.com/xapis/vsphere-automation-api/latest/vcenter/api/vcenter/vm/vm/get/https://developer.broadcom.com/xapis/vsphere-automation-api/latest/vcenter/api/vcenter/vm/vm/get/

访问地址:https://{api_host}/api/vcenter/vm/{vm}

返回值:有关指定虚拟机的信息。具体信息去官网看

{

"guest_OS": "string",

"name": "string",

"identity": {

"name": "string",

"bios_uuid": "string",

"instance_uuid": "string"

},

"power_state": "string",

"instant_clone_frozen": false,

"hardware": {

"version": "string",

"upgrade_policy": "string",

"upgrade_version": "string",

"upgrade_status": "string",

"upgrade_error": {}

},

"boot": {

"type": "string",

"efi_legacy_boot": false,

"network_protocol": "string",

"delay": 0,

"retry": false,

"retry_delay": 0,

"enter_setup_mode": false

},

"boot_devices": [

{

"type": "string",

"nic": "string",

"disks": [

"string"

]

}

],

"cpu": {

"count": 0,

"cores_per_socket": 0,

"hot_add_enabled": false,

"hot_remove_enabled": false

},

"memory": {

"size_MiB": 0,

"hot_add_enabled": false,

"hot_add_increment_size_MiB": 0,

"hot_add_limit_MiB": 0

},

"disks": {

"disks": {

"label": "string",

"type": "string",

"ide": {

"primary": false,

"master": false

},

"scsi": {

"bus": 0,

"unit": 0

},

"sata": {

"bus": 0,

"unit": 0

},

"nvme": {

"bus": 0,

"unit": 0

},

"backing": {

"type": "string",

"vmdk_file": "string"

},

"capacity": 0

}

},

"nics": {

"nics": {

"label": "string",

"type": "string",

"upt_compatibility_enabled": false,

"upt_v2_compatibility_enabled": false,

"mac_type": "string",

"mac_address": "string",

"pci_slot_number": 0,

"wake_on_lan_enabled": false,

"backing": {

"type": "string",

"network": "string",

"network_name": "string",

"host_device": "string",

"distributed_switch_uuid": "string",

"distributed_port": "string",

"connection_cookie": 0,

"opaque_network_type": "string",

"opaque_network_id": "string"

},

"state": "string",

"start_connected": false,

"allow_guest_control": false

}

},

"cdroms": {

"cdroms": {

"type": "string",

"label": "string",

"ide": "Vm_Hardware_IdeAddressInfo Object",

"sata": "Vm_Hardware_SataAddressInfo Object",

"backing": {

"type": "string",

"iso_file": "string",

"host_device": "string",

"auto_detect": false,

"device_access_type": "string"

},

"state": "Vm_Hardware_ConnectionState Object",

"start_connected": false,

"allow_guest_control": false

}

},

"floppies": {

"floppies": {

"label": "string",

"backing": {

"type": "string",

"image_file": "string",

"host_device": "string",

"auto_detect": false

},

"state": "Vm_Hardware_ConnectionState Object",

"start_connected": false,

"allow_guest_control": false

}

},

"parallel_ports": {

"parallel_ports": {

"label": "string",

"backing": {

"type": "string",

"file": "string",

"host_device": "string",

"auto_detect": false

},

"state": "Vm_Hardware_ConnectionState Object",

"start_connected": false,

"allow_guest_control": false

}

},

"serial_ports": {

"serial_ports": {

"label": "string",

"yield_on_poll": false,

"backing": {

"type": "string",

"file": "string",

"host_device": "string",

"auto_detect": false,

"pipe": "string",

"no_rx_loss": false,

"network_location": "string",

"proxy": "string"

},

"state": "Vm_Hardware_ConnectionState Object",

"start_connected": false,

"allow_guest_control": false

}

},

"sata_adapters": {

"sata_adapters": {

"label": "string",

"type": "string",

"bus": 0,

"pci_slot_number": 0

}

},

"scsi_adapters": {

"scsi_adapters": {

"label": "string",

"type": "string",

"scsi": "Vm_Hardware_ScsiAddressInfo Object",

"pci_slot_number": 0,

"sharing": "string"

}

},

"nvme_adapters": {

"nvme_adapters": {

"label": "string",

"bus": 0,

"pci_slot_number": 0

}

}

}

相关推荐