如何获取 vSphere VM 的创建时间

how to get a vsphere VM's creation time

如何使用 ruby SDK 获取 vSphere VM 的创建时间?我可以获得 VM 实例,但似乎没有 属性 显示创建 VM 的时间。

api_client = VSphereAutomation::ApiClient.new(configuration)
VSphereAutomation::CIS::SessionApi.new(api_client).create('')
vm_api = VSphereAutomation::VCenter::VMApi.new(api_client)
vms = vm_api.list({filter_power_states: ["POWERED_ON"]})
...
# this will get a specific VM information but nothing about creation time.
vm_api.get('vm-34122')

输出来自 vSphere Web 服务 API,通过 Virtual Machine managed object, which is nested in the ConfigInfo 中的新 属性,可以被 createDate 引用。完整 属性 路径:vm.config.createdate

值得注意的是,此信息在 vSphere 的 REST(例如 vSphere Automation)API 中不可用,因此您需要使用 rbvmomi 来访问它。此外,如果您碰巧提取了 non-sensical 日期,这可能是由于在 属性 之前创建的 VM 被引入到 vSphere 6.7 中的 API。