本文整理汇总了Python中healthnmon.resourcemodel.healthnmonResourceModel.VmHost.set_virtualMachineIds方法的典型用法代码示例。如果您正苦于以下问题:Python VmHost.set_virtualMachineIds方法的具体用法?Python VmHost.set_virtualMachineIds怎么用?Python VmHost.set_virtualMachineIds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类healthnmon.resourcemodel.healthnmonResourceModel.VmHost
的用法示例。
在下文中一共展示了VmHost.set_virtualMachineIds方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _createCache
# 需要导入模块: from healthnmon.resourcemodel.healthnmonResourceModel import VmHost [as 别名]
# 或者: from healthnmon.resourcemodel.healthnmonResourceModel.VmHost import set_virtualMachineIds [as 别名]
def _createCache(self):
self.mox.StubOutWithMock(api, "vm_host_get_all")
vmhost = VmHost()
vmhost.set_id("vmhost1")
vmhost1 = VmHost()
vmhost1.set_id("vmhost2")
vm = Vm()
vm.set_id("vm1")
vm.set_powerState(Constants.VM_POWER_STATES[1])
vm.set_vmHostId("vmhost1")
vm1 = Vm()
vm1.set_id("vm2")
vm1.set_powerState(Constants.VM_POWER_STATES[1])
vm1.set_vmHostId("vmhost2")
vmhost.set_virtualMachineIds(["vm1", "vm2"])
stPool = StorageVolume()
stPool.set_id("stpool1")
subNet = Subnet()
subNet.set_id("net1")
api.vm_host_get_all(mox.IgnoreArg()).AndReturn([vmhost, vmhost1])
self.mox.StubOutWithMock(api, "vm_get_all")
api.vm_get_all(mox.IgnoreArg()).AndReturn([vm, vm1])
self.mox.StubOutWithMock(api, "storage_volume_get_all")
api.storage_volume_get_all(mox.IgnoreArg()).AndReturn([stPool])
self.mox.StubOutWithMock(api, "subnet_get_all")
api.subnet_get_all(mox.IgnoreArg()).AndReturn([subNet])
示例2: setUp
# 需要导入模块: from healthnmon.resourcemodel.healthnmonResourceModel import VmHost [as 别名]
# 或者: from healthnmon.resourcemodel.healthnmonResourceModel.VmHost import set_virtualMachineIds [as 别名]
def setUp(self):
self.mock = mox.Mox()
self.connection = LibvirtConnection(False)
vmHost = VmHost()
vmHost.set_virtualMachineIds([])
InventoryCacheManager.update_object_in_cache('1', vmHost)
self.connection._wrapped_conn = None
self.connection.compute_rmcontext = \
ComputeRMContext(rmType='fake', rmIpAddress='10.10.155.165',
rmUserName='openstack',
rmPassword='password')
InventoryCacheManager.get_all_compute_inventory()['1'] = \
ComputeInventory(self.connection.compute_rmcontext)
self.mock.StubOutWithMock(LibvirtConnection, '_connect')
self.connection._connect(
mox.IgnoreArg(),
mox.IgnoreArg()).AndRaise(libvirt.libvirtError)
self.mock.ReplayAll()
self.inventoryMonitor = LibvirtInventoryMonitor()
libvirtEvents = LibvirtEvents()
self.libvirtVmHost = LibvirtVmHost(
self.connection._wrapped_conn, '1', libvirtEvents)
cfg.CONF.set_override('healthnmon_notification_drivers',
['healthnmon.notifier.log_notifier'])
示例3: test_host_disconnected_event
# 需要导入模块: from healthnmon.resourcemodel.healthnmonResourceModel import VmHost [as 别名]
# 或者: from healthnmon.resourcemodel.healthnmonResourceModel.VmHost import set_virtualMachineIds [as 别名]
def test_host_disconnected_event(self):
self.__mock_service_get_all_by_topic()
backedUp_libvirt = connection.libvirt
connection.libvirt = libvirt
try:
compute_id = '1'
virtConnection = LibvirtConnection(False)
vmHost = VmHost()
vmHost.id = compute_id
vmHost.set_virtualMachineIds([])
InventoryCacheManager.update_object_in_cache(compute_id, vmHost)
# virtConnection.setUuid('34353438-3934-434e-3738-313630323543'
# )
virtConnection._wrapped_conn = None
virtConnection.compute_rmcontext = \
ComputeRMContext(rmType='KVM',
rmIpAddress='10.10.155.165',
rmUserName='openstack',
rmPassword='password')
cachedHost = VmHost()
cachedHost.id = compute_id
cachedHost.connectionState = Constants.VMHOST_CONNECTED
self.mox.StubOutWithMock(InventoryCacheManager,
'get_object_from_cache')
self.mox.StubOutWithMock(
InventoryCacheManager, 'get_compute_conn_driver')
InventoryCacheManager.get_compute_conn_driver(
self.libvirtVmHost.compute_id,
Constants.VmHost).AndReturn(fake.get_connection())
InventoryCacheManager.get_object_from_cache(
compute_id,
Constants.VmHost).AndReturn(cachedHost)
self.mox.StubOutWithMock(api, 'vm_host_save')
api.vm_host_save(mox.IgnoreArg(),
mox.IgnoreArg()).MultipleTimes().AndReturn(None)
self.mox.ReplayAll()
libvirtEvents = LibvirtEvents()
libvirtVmHost = LibvirtVmHost(
virtConnection._wrapped_conn, compute_id, libvirtEvents)
libvirtVmHost.processUpdates()
self.assertEquals(libvirtVmHost.vmHost.get_connectionState(),
Constants.VMHOST_DISCONNECTED)
self.assertEquals(len(test_notifier.NOTIFICATIONS), 1)
msg = test_notifier.NOTIFICATIONS[0]
self.assertEquals(msg['priority'], notifier_api.CRITICAL)
event_type = \
event_metadata.get_EventMetaData(
event_metadata.EVENT_TYPE_HOST_DISCONNECTED)
self.assertEquals(msg['event_type'],
event_type.get_event_fully_qal_name())
payload = msg['payload']
self.assertEquals(payload['entity_type'], 'VmHost')
self.assertEquals(payload['entity_id'],
libvirtVmHost.compute_id)
finally:
connection.libvirt = backedUp_libvirt
示例4: setUp
# 需要导入模块: from healthnmon.resourcemodel.healthnmonResourceModel import VmHost [as 别名]
# 或者: from healthnmon.resourcemodel.healthnmonResourceModel.VmHost import set_virtualMachineIds [as 别名]
def setUp(self):
super(VmEventsTest, self).setUp()
self.connection = LibvirtConnection(False)
vmHost = VmHost()
vmHost.set_virtualMachineIds([])
InventoryCacheManager.update_object_in_cache('1', vmHost)
self.connection._wrapped_conn = libvirt.open('qemu:///system')
self.libvirtVM = LibvirtVM(self.connection._wrapped_conn,
'1')
self.connection.compute_rmcontext = \
ComputeRMContext(rmType='KVM', rmIpAddress='10.10.155.165',
rmUserName='openstack',
rmPassword='password')
self.flags(healthnmon_notification_drivers=['nova.notifier.test_notifier']
)
test_notifier.NOTIFICATIONS = []
self.mox.StubOutWithMock(nova_db, 'service_get_all_by_topic')
nova_db.service_get_all_by_topic(mox.IgnoreArg(),
mox.IgnoreArg()).MultipleTimes().AndReturn(None)
示例5: createInvCache
# 需要导入模块: from healthnmon.resourcemodel.healthnmonResourceModel import VmHost [as 别名]
# 或者: from healthnmon.resourcemodel.healthnmonResourceModel.VmHost import set_virtualMachineIds [as 别名]
def createInvCache(self, vmrunning, hostconnection='Connected'):
vmhost = VmHost()
vmhost.set_id(self.vmhost_id)
vmhost.set_connectionState(hostconnection)
vm = Vm()
vm.set_id(self.vm_id)
if vmrunning:
vm.set_powerState(Constants.VM_POWER_STATES[1])
else:
vm.set_powerState(Constants.VM_POWER_STATES[0])
vm.set_vmHostId(self.vmhost_id)
vmhost.set_virtualMachineIds([self.vm_id
])
vmhost.set_processorSpeedMhz(2100)
vmhost.set_processorCoresCount(4)
vmhost.set_processorCount('2')
vmhost.set_memorySize(2097152)
vmhost.set_memoryConsumed(2097152)
InventoryCacheManager.update_object_in_cache(self.vmhost_id, vmhost)
InventoryCacheManager.update_object_in_cache(
self.vm_id,
vm)
示例6: setUp
# 需要导入模块: from healthnmon.resourcemodel.healthnmonResourceModel import VmHost [as 别名]
# 或者: from healthnmon.resourcemodel.healthnmonResourceModel.VmHost import set_virtualMachineIds [as 别名]
def setUp(self):
super(VmHostEventsTest, self).setUp()
self.connection = LibvirtConnection(False)
vmHost = VmHost()
vmHost.set_virtualMachineIds([])
InventoryCacheManager.update_object_in_cache('1', vmHost)
rm_context = ComputeRMContext(
rmType='QEMU', rmIpAddress='10.10.155.165',
rmUserName='openstack',
rmPassword='password')
InventoryCacheManager.update_object_in_cache('1', vmHost)
InventoryCacheManager.get_all_compute_inventory()['1'] = \
ComputeInventory(rm_context)
self.connection._wrapped_conn = libvirt.open('qemu:///system')
libvirtEvents = LibvirtEvents()
self.libvirtVmHost = LibvirtVmHost(
self.connection._wrapped_conn, '1', libvirtEvents)
self.connection.compute_rmcontext = rm_context
self.flags(healthnmon_notification_drivers=[
'nova.notifier.test_notifier'])
test_notifier.NOTIFICATIONS = []
示例7: test_LibvirtVM
# 需要导入模块: from healthnmon.resourcemodel.healthnmonResourceModel import VmHost [as 别名]
# 或者: from healthnmon.resourcemodel.healthnmonResourceModel.VmHost import set_virtualMachineIds [as 别名]
class test_LibvirtVM(unittest.TestCase):
def setUp(self):
self.connection = LibvirtConnection(False)
self.vmHost = VmHost()
self.vmHost.set_virtualMachineIds([])
InventoryCacheManager.update_object_in_cache('1', self.vmHost)
#self.connection.setUuid('34353438-3934-434e-3738-313630323543')
self.connection._wrapped_conn = libvirt.open('qemu:///system')
self.libvirtVM = LibvirtVM(self.connection._wrapped_conn,
'1')
self.libvirtVM.vmHost.set_id('1')
self.connection.compute_rmcontext = \
ComputeRMContext(rmType='QEMU', rmIpAddress='10.10.155.165',
rmUserName='openstack',
rmPassword='password')
self.mock = mox.Mox()
cfg.CONF.set_override('healthnmon_notification_drivers',
['healthnmon.notifier.log_notifier'])
def tearDown(self):
cfg.CONF.set_override('healthnmon_notification_drivers', None)
self.mock.stubs.UnsetAll()
def test_ProcessUpdates(self):
self.mock.StubOutWithMock(api, 'vm_save')
api.vm_save(mox.IgnoreArg(),
mox.IgnoreArg()).MultipleTimes().AndReturn(None)
self.mock.StubOutWithMock(api, 'vm_delete_by_ids')
api.vm_delete_by_ids(mox.IgnoreArg(),
mox.IgnoreArg()).MultipleTimes().AndReturn(None)
self.mock.StubOutWithMock(nova_db, 'service_get_all_by_topic')
nova_db.service_get_all_by_topic(
mox.IgnoreArg(),
mox.IgnoreArg()).MultipleTimes().AndReturn(None)
self.mock.StubOutWithMock(
InventoryCacheManager, 'get_compute_conn_driver')
InventoryCacheManager.get_compute_conn_driver(
self.libvirtVM.compute_id,
Constants.VmHost).AndReturn(fake.get_connection())
self.mock.ReplayAll()
self.assertEquals(self.libvirtVM.processUpdates(), None)
vm = InventoryCacheManager.get_object_from_cache(
"25f04dd3-e924-02b2-9eac-876e3c943262", Constants.Vm)
# self.assertEquals("TestVirtMgrVM7", vm.get_name())
self.assertEquals("1048576", str(vm.get_memorySize()))
self.assertEquals("hd", str(vm.get_bootOrder()).strip())
self.mock.stubs.UnsetAll()
def test_process_updates_for_updated_VM(self):
self.mock.StubOutWithMock(api, 'vm_save')
api.vm_save(mox.IgnoreArg(),
mox.IgnoreArg()).MultipleTimes().AndReturn(None)
self.mock.StubOutWithMock(api, 'vm_delete_by_ids')
api.vm_delete_by_ids(mox.IgnoreArg(),
mox.IgnoreArg()).MultipleTimes().AndReturn(None)
self.mock.StubOutWithMock(nova_db, 'service_get_all_by_topic')
nova_db.service_get_all_by_topic(
mox.IgnoreArg(),
mox.IgnoreArg()).MultipleTimes().AndReturn(None)
self.mock.StubOutWithMock(
InventoryCacheManager, 'get_compute_conn_driver')
InventoryCacheManager.get_compute_conn_driver(
self.libvirtVM.compute_id,
Constants.VmHost).AndReturn(fake.get_connection())
self.mock.ReplayAll()
domainObj = libvirt.virDomain()
self.assertEquals(
self.libvirtVM.process_updates_for_updated_VM(domainObj), None)
vm = InventoryCacheManager.get_object_from_cache(
"25f04dd3-e924-02b2-9eac-876e3c943262", Constants.Vm)
# self.assertEquals("TestVirtMgrVM7", vm.get_name())
self.assertEquals("1048576", str(vm.get_memorySize()))
self.assertEquals("hd", str(vm.get_bootOrder()).strip())
self.mock.stubs.UnsetAll()
def test_process_updates_for_updated_VM_exception(self):
domainObj = libvirt.virDomain()
self.libvirtVM.vmHost = None
self.libvirtVM.process_updates_for_updated_VM(domainObj)
self.assertRaises(Exception, LibvirtVM)
self.mock.stubs.UnsetAll()
self.mock.VerifyAll()
def test_ProcessUpdatesException(self):
self.mock.StubOutWithMock(api, 'vm_save')
api.vm_save(mox.IgnoreArg(),
mox.IgnoreArg()).MultipleTimes().AndReturn(None)
self.mock.StubOutWithMock(api, 'vm_delete_by_ids')
#.........这里部分代码省略.........
示例8: test_LibvirtVM
# 需要导入模块: from healthnmon.resourcemodel.healthnmonResourceModel import VmHost [as 别名]
# 或者: from healthnmon.resourcemodel.healthnmonResourceModel.VmHost import set_virtualMachineIds [as 别名]
class test_LibvirtVM(test.TestCase):
def setUp(self):
super(test_LibvirtVM, self).setUp()
self.connection = LibvirtConnection(False)
self.vmHost = VmHost()
self.vmHost.set_virtualMachineIds([])
InventoryCacheManager.update_object_in_cache('1', self.vmHost)
# self.connection.setUuid('34353438-3934-434e-3738-313630323543')
self.connection._wrapped_conn = libvirt.open('qemu:///system')
self.libvirtVM = LibvirtVM(self.connection._wrapped_conn,
'1')
self.libvirtVM.vmHost.set_id('1')
self.connection.compute_rmcontext = \
ComputeRMContext(rmType='QEMU', rmIpAddress='10.10.155.165',
rmUserName='openstack',
rmPassword='password')
self.mock = mox.Mox()
cfg.CONF.set_override('healthnmon_notification_drivers',
['healthnmon.notifier.log_notifier'])
def tearDown(self):
cfg.CONF.set_override('healthnmon_notification_drivers', None)
super(test_LibvirtVM, self).tearDown()
def test_ProcessUpdates(self):
self.mock.StubOutWithMock(api, 'vm_save')
api.vm_save(mox.IgnoreArg(),
mox.IgnoreArg()).MultipleTimes().AndReturn(None)
self.mock.StubOutWithMock(api, 'vm_delete_by_ids')
api.vm_delete_by_ids(mox.IgnoreArg(),
mox.IgnoreArg()).MultipleTimes().AndReturn(None)
self.mock.StubOutWithMock(nova_db, 'service_get_all_by_topic')
nova_db.service_get_all_by_topic(
mox.IgnoreArg(),
mox.IgnoreArg()).MultipleTimes().AndReturn(None)
self.mock.StubOutWithMock(
InventoryCacheManager, 'get_compute_conn_driver')
InventoryCacheManager.get_compute_conn_driver(
self.libvirtVM.compute_id,
Constants.VmHost).AndReturn(fake.get_connection())
self.mock.ReplayAll()
self.assertEquals(self.libvirtVM.processUpdates(), None)
vm = InventoryCacheManager.get_object_from_cache(
"25f04dd3-e924-02b2-9eac-876e3c943262", Constants.Vm)
# self.assertEquals("TestVirtMgrVM7", vm.get_name())
self.assertEquals("1048576", str(vm.get_memorySize()))
self.assertEquals("hd", str(vm.get_bootOrder()).strip())
self.mock.stubs.UnsetAll()
def test_process_incomplete_vms(self):
self.mock.StubOutWithMock(api, 'vm_save')
api.vm_save(mox.IgnoreArg(),
mox.IgnoreArg()).MultipleTimes().AndReturn(None)
self.mock.StubOutWithMock(api, 'vm_delete_by_ids')
api.vm_delete_by_ids(mox.IgnoreArg(),
mox.IgnoreArg()).MultipleTimes().AndReturn(None)
self.mock.StubOutWithMock(nova_db, 'service_get_all_by_topic')
nova_db.service_get_all_by_topic(
mox.IgnoreArg(),
mox.IgnoreArg()).MultipleTimes().AndReturn(None)
self.mock.StubOutWithMock(
InventoryCacheManager, 'get_compute_conn_driver')
InventoryCacheManager.get_compute_conn_driver(
self.libvirtVM.compute_id,
Constants.VmHost).AndReturn(fake.get_connection())
self.mock.ReplayAll()
libvirt_inventorymonitor.incomplete_vms = \
{self.libvirtVM.compute_id:
{'25f04dd3-e924-02b2-9eac-876e3c943262': 1}}
self.libvirtVM.process_incomplete_vms()
vm = InventoryCacheManager.get_object_from_cache(
"25f04dd3-e924-02b2-9eac-876e3c943262", Constants.Vm)
self.assert_(vm.get_vmDisks(), "VM disks inventory not collected")
self.assert_(
'25f04dd3-e924-02b2-9eac-876e3c943262' not in
libvirt_inventorymonitor.incomplete_vms[
self.libvirtVM.compute_id],
"VM id not removed from incomplete list")
self.mock.stubs.UnsetAll()
def test_process_incomplete_vms_with_retry(self):
self.mock.StubOutWithMock(api, 'vm_save')
api.vm_save(mox.IgnoreArg(),
mox.IgnoreArg()).MultipleTimes().AndReturn(None)
self.mock.StubOutWithMock(api, 'vm_delete_by_ids')
api.vm_delete_by_ids(mox.IgnoreArg(),
mox.IgnoreArg()).MultipleTimes().AndReturn(None)
self.mock.StubOutWithMock(nova_db, 'service_get_all_by_topic')
#.........这里部分代码省略.........