本文整理汇总了Python中host.hypervisor.esx.vim_client.VimClient.get_vm_power_state方法的典型用法代码示例。如果您正苦于以下问题:Python VimClient.get_vm_power_state方法的具体用法?Python VimClient.get_vm_power_state怎么用?Python VimClient.get_vm_power_state使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类host.hypervisor.esx.vim_client.VimClient
的用法示例。
在下文中一共展示了VimClient.get_vm_power_state方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestVimClient
# 需要导入模块: from host.hypervisor.esx.vim_client import VimClient [as 别名]
# 或者: from host.hypervisor.esx.vim_client.VimClient import get_vm_power_state [as 别名]
#.........这里部分代码省略.........
[mount_name_mock])
host_system.return_value = mount
path = self.vim_client.datastore_name_to_path("datastore_doesnt_exist")
assert_that(path, none())
def test_get_nfc_ticket(self):
self.vim_client.get_datastore = MagicMock(return_value=None)
self.assertRaises(DatastoreNotFound,
self.vim_client.get_nfc_ticket_by_ds_name,
"no_exist")
ds_mock = MagicMock()
self.vim_client.get_datastore = MagicMock(return_value=ds_mock)
type(self.vim_client).nfc_service = MagicMock()
self.vim_client.get_nfc_ticket_by_ds_name("existing_ds")
self.vim_client.nfc_service.FileManagement.assert_called_once_with(
ds_mock)
def test_inventory_path(self):
"""Check that convert to inventory path correctly."""
tests = [
{"path": (), "val": "ha-datacenter"},
{"path": ("network", None), "val": "ha-datacenter/network"},
{"path": ("vm",), "val": "ha-datacenter/vm"},
{"path": ("vm", "Cent/OS"), "val": "ha-datacenter/vm/Cent%2fOS"},
]
for test in tests:
result = self.vim_client.inventory_path(*test["path"])
assert_that(result, equal_to(test["val"]))
def test_get_vm_power_state(self):
"""Check that we return the expected power state."""
vm_mock = MagicMock(name="vm_mock")
vm_mock.runtime.powerState = "poweredoff"
assert_that(self.vim_client.get_vm_power_state(vm_mock),
equal_to("poweredoff"))
def test_get_vm_not_found(self):
"""Test that if the vm isn't found we throw an exception."""
self.vim_client.find_by_inventory_path = MagicMock(return_value=None)
# assertRaisesRegexp is only supported in 2.7
self.assertRaises(Exception, self.vim_client.get_vm, "vm_id")
@patch.object(Credentials, "_service_instance")
@patch.object(Credentials, "password")
def test_acquire_credentials(self, password_mock, si_method_mock):
"""The mockery of acquiring local hostd credentials"""
local_ticket_mock = MagicMock(name="local_ticket")
user_name_property = PropertyMock(return_value="local-root")
type(local_ticket_mock).userName = user_name_property
session_manager_mock = MagicMock(name="session-manager")
session_manager_mock.AcquireLocalTicket.return_value = \
local_ticket_mock
si = MagicMock(name="si")
session_manager_property = \
PropertyMock(return_value=session_manager_mock)
type(si.content).sessionManager = session_manager_property
si_method_mock.return_value = si