本文整理汇总了Python中host.hypervisor.esx.vim_client.VimClient.get_vm_obj_in_cache方法的典型用法代码示例。如果您正苦于以下问题:Python VimClient.get_vm_obj_in_cache方法的具体用法?Python VimClient.get_vm_obj_in_cache怎么用?Python VimClient.get_vm_obj_in_cache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类host.hypervisor.esx.vim_client.VimClient
的用法示例。
在下文中一共展示了VimClient.get_vm_obj_in_cache方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_update_cache
# 需要导入模块: from host.hypervisor.esx.vim_client import VimClient [as 别名]
# 或者: from host.hypervisor.esx.vim_client.VimClient import get_vm_obj_in_cache [as 别名]
def test_update_cache(self, connect_mock, spec_mock):
vim_client = VimClient("esx.local", "root", "password",
auto_sync=False)
vim_client.property_collector.WaitForUpdatesEx.return_value = {}
# Test enter
update = vmodl.query.PropertyCollector.UpdateSet(version="1")
filter = vmodl.query.PropertyCollector.FilterUpdate()
update.filterSet.append(filter)
object_update = vmodl.query.PropertyCollector.ObjectUpdate(
kind="enter",
obj=vim.VirtualMachine("vim.VirtualMachine:9"),
)
filter.objectSet.append(object_update)
object_update.changeSet.append(vmodl.query.PropertyCollector.Change(
name="name",
op="assign",
val="agent4"))
object_update.changeSet.append(vmodl.query.PropertyCollector.Change(
name="runtime.powerState",
op="assign",
val="poweredOff"))
object_update.changeSet.append(vmodl.query.PropertyCollector.Change(
name="config",
op="assign",
val=vim.vm.ConfigInfo(
files=vim.vm.FileInfo(
vmPathName="[datastore2] agent4/agent4.vmx"),
hardware=vim.vm.VirtualHardware(
memoryMB=4096
)
)
))
disk_list = vim.vm.FileLayout.DiskLayout.Array()
disk_list.append(vim.vm.FileLayout.DiskLayout(diskFile=["disk1"]))
disk_list.append(vim.vm.FileLayout.DiskLayout(diskFile=["disk2"]))
object_update.changeSet.append(vmodl.query.PropertyCollector.Change(
name="layout.disk",
op="assign",
val=disk_list
))
vim_client.property_collector.WaitForUpdatesEx.return_value = update
assert_that(len(vim_client.get_vms_in_cache()), is_(0))
vim_client.update_cache()
vim_client.property_collector.WaitForUpdatesEx.assert_called()
vms = vim_client.get_vms_in_cache()
assert_that(vim_client.current_version, is_("1"))
assert_that(len(vms), 1)
assert_that(vms[0].memory_mb, is_(4096))
assert_that(vms[0].path, is_("[datastore2] agent4/agent4.vmx"))
assert_that(vms[0].name, is_("agent4"))
assert_that(vms[0].power_state, is_(PowerState.poweredOff))
assert_that(len(vms[0].disks), is_(2))
assert_that(vms[0].disks, contains_inanyorder("disk1", "disk2"))
# Test retrieving VM moref
vm_obj = vim_client.get_vm_obj_in_cache("agent4")
assert_that(vm_obj._moId, is_("9"))
assert_that(str(vm_obj), is_("'vim.VirtualMachine:9'"))
assert_that(vm_obj,
instance_of(vim.VirtualMachine))
# Test Modify
update.version = "2"
object_update = vmodl.query.PropertyCollector.ObjectUpdate(
kind="modify",
obj=vim.VirtualMachine("vim.VirtualMachine:9"),
)
filter.objectSet[0] = object_update
object_update.changeSet.append(vmodl.query.PropertyCollector.Change(
name="runtime.powerState",
op="assign",
val="poweredOn"))
object_update.changeSet.append(vmodl.query.PropertyCollector.Change(
name="runtime.powerState",
op="assign",
val="poweredOn"))
disk_list = vim.vm.FileLayout.DiskLayout.Array()
disk_list.append(vim.vm.FileLayout.DiskLayout(diskFile=["disk3",
"disk4"]))
object_update.changeSet.append(vmodl.query.PropertyCollector.Change(
name="layout.disk",
op="assign",
val=disk_list
))
vim_client.update_cache()
vms = vim_client.get_vms_in_cache()
assert_that(vim_client.current_version, is_("2"))
assert_that(len(vms), is_(1))
assert_that(vms[0].memory_mb, is_(4096))
assert_that(vms[0].path, is_("[datastore2] agent4/agent4.vmx"))
assert_that(vms[0].name, is_("agent4"))
assert_that(vms[0].power_state, is_(PowerState.poweredOn))
assert_that(len(vms[0].disks), is_(2))
assert_that(vms[0].disks, contains_inanyorder("disk3", "disk4"))
# Test leave
#.........这里部分代码省略.........