本文整理汇总了Python中host.hypervisor.esx.vim_client.VimClient.update_cache方法的典型用法代码示例。如果您正苦于以下问题:Python VimClient.update_cache方法的具体用法?Python VimClient.update_cache怎么用?Python VimClient.update_cache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类host.hypervisor.esx.vim_client.VimClient
的用法示例。
在下文中一共展示了VimClient.update_cache方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_update_fail_will_suicide
# 需要导入模块: from host.hypervisor.esx.vim_client import VimClient [as 别名]
# 或者: from host.hypervisor.esx.vim_client.VimClient import update_cache [as 别名]
def test_update_fail_will_suicide(self, sleep_mock,
connect_mock,
update_mock, update_hosts_mock):
killed = threading.Event()
def suicide():
killed.set()
threading.current_thread().stop()
update_cache = MagicMock()
update_cache.side_effect = vim.fault.HostConnectFault
client = VimClient("esx.local", "root", "password",
auto_sync=True,
min_interval=1,
errback=lambda: suicide())
client.update_cache = update_cache
killed.wait(1)
client.disconnect(wait=True)
# update_cache will be called 5 times before it kill itself
assert_that(update_cache.call_count, is_(5))
assert_that(killed.is_set(), is_(True))
示例2: test_update_cache
# 需要导入模块: from host.hypervisor.esx.vim_client import VimClient [as 别名]
# 或者: from host.hypervisor.esx.vim_client.VimClient import update_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
#.........这里部分代码省略.........