本文整理汇总了Python中host.hypervisor.esx.vim_client.VimClient._vim_cache方法的典型用法代码示例。如果您正苦于以下问题:Python VimClient._vim_cache方法的具体用法?Python VimClient._vim_cache怎么用?Python VimClient._vim_cache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类host.hypervisor.esx.vim_client.VimClient
的用法示例。
在下文中一共展示了VimClient._vim_cache方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_update_cache
# 需要导入模块: from host.hypervisor.esx.vim_client import VimClient [as 别名]
# 或者: from host.hypervisor.esx.vim_client.VimClient import _vim_cache [as 别名]
def test_update_cache(self, connect_mock, spec_mock):
vim_client = VimClient(auto_sync=False)
vim_client.connect_userpwd("esx.local", "root", "password")
vim_client._property_collector.WaitForUpdatesEx.return_value = {}
vim_client._vim_cache = VimCache()
# 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),
locationId="location1"),
))
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._vim_cache.poll_updates(vim_client)
vim_client._property_collector.WaitForUpdatesEx.assert_called()
vms = vim_client.get_vms_in_cache()
assert_that(vim_client._vim_cache._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_(VmPowerState.STOPPED))
assert_that(len(vms[0].disks), is_(2))
assert_that(vms[0].disks, contains_inanyorder("disk1", "disk2"))
assert_that(vms[0].location_id, is_("location1"))
# 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._vim_cache.poll_updates(vim_client)
vms = vim_client.get_vms_in_cache()
assert_that(vim_client._vim_cache._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_(VmPowerState.STARTED))
assert_that(len(vms[0].disks), is_(2))
assert_that(vms[0].disks, contains_inanyorder("disk3", "disk4"))
# Test leave
update.version = "3"
object_update = vmodl.query.PropertyCollector.ObjectUpdate(
kind="leave",
obj=vim.VirtualMachine("vim.VirtualMachine:9"),
)
filter.objectSet[0] = object_update
vim_client._vim_cache.poll_updates(vim_client)
vms = vim_client.get_vms_in_cache()
assert_that(vim_client._vim_cache._current_version, is_("3"))
assert_that(len(vms), is_(0))