本文整理汇总了Python中healthnmon.resourcemodel.healthnmonResourceModel.Vm.set_id方法的典型用法代码示例。如果您正苦于以下问题:Python Vm.set_id方法的具体用法?Python Vm.set_id怎么用?Python Vm.set_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类healthnmon.resourcemodel.healthnmonResourceModel.Vm
的用法示例。
在下文中一共展示了Vm.set_id方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _createCache
# 需要导入模块: from healthnmon.resourcemodel.healthnmonResourceModel import Vm [as 别名]
# 或者: from healthnmon.resourcemodel.healthnmonResourceModel.Vm import set_id [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: test_diff_resourcemodel_vm_with_type_changesandupdate
# 需要导入模块: from healthnmon.resourcemodel.healthnmonResourceModel import Vm [as 别名]
# 或者: from healthnmon.resourcemodel.healthnmonResourceModel.Vm import set_id [as 别名]
def test_diff_resourcemodel_vm_with_type_changesandupdate(self):
old_vm = Vm()
old_vm.set_id(unicode('vm-01'))
old_vm.set_name(unicode('vm-01'))
disk1 = VmDisk()
disk1.set_id(unicode('disk-01'))
disk1.set_storageVolumeId(unicode("datastore-939"))
old_vm.add_vmDisks(disk1)
old_vm.set_vmHostId(unicode('host-329'))
new_vm = Vm()
new_vm.set_id('vm-01')
new_vm.set_name('vm-01')
disk3 = VmDisk()
disk3.set_id('disk-01')
disk3.set_storageVolumeId("datastore-939-999")
new_vm.add_vmDisks(disk3)
new_vm.set_vmHostId('host-329')
diff = ResourceModelDiff(old_vm, new_vm)
diff_res = diff.diff_resourcemodel()
self.assertTrue(len(diff_res) > 0)
self.assertTrue(self.update in diff_res)
vmDisks = 'vmDisks'
self.assertTrue(vmDisks in diff_res[self.update])
self.assertTrue(self.update in diff_res[self.update][vmDisks])
self.assertTrue('disk-01' in diff_res[self.update][vmDisks][
self.update])
self.assertTrue(self.update in diff_res[self.update][vmDisks][
self.update]['disk-01'])
self.assertTrue('storageVolumeId' in diff_res[self.update][vmDisks][
self.update]['disk-01'][self.update])
self.assertEquals(diff_res[self.update][vmDisks][self.update][
'disk-01'][self.update]['storageVolumeId'], 'datastore-939-999')
示例3: test_timestamp_columns
# 需要导入模块: from healthnmon.resourcemodel.healthnmonResourceModel import Vm [as 别名]
# 或者: from healthnmon.resourcemodel.healthnmonResourceModel.Vm import set_id [as 别名]
def test_timestamp_columns(self):
"""
Test the time stamp columns createEpoch,
modifiedEpoch and deletedEpoch
"""
vm = Vm()
vm.set_id('VM1')
# Check for createEpoch
epoch_before = utils.get_current_epoch_ms()
healthnmon_db_api.vm_save(self.admin_context, vm)
epoch_after = utils.get_current_epoch_ms()
vm_queried = healthnmon_db_api.vm_get_by_ids(
self.admin_context, [vm.get_id()])[0]
self.assert_(test_utils.is_timestamp_between(
epoch_before, epoch_after, vm_queried.get_createEpoch()))
# Check for lastModifiedEpoch and createEpoch
# after adding VmGlobalSettings
vm_modified = vm_queried
test_utils.unset_timestamp_fields(vm_modified)
vmGlobalSettings = VmGlobalSettings()
vmGlobalSettings.set_id('VMGS1')
vmGlobalSettings.set_autoStartAction(Constants.AUTO_START_ENABLED)
vm_modified.set_vmGlobalSettings(vmGlobalSettings)
epoch_before = utils.get_current_epoch_ms()
healthnmon_db_api.vm_save(self.admin_context, vm_modified)
epoch_after = utils.get_current_epoch_ms()
vm_queried = healthnmon_db_api.vm_get_by_ids(
self.admin_context, [vm.get_id()])[0]
self.assert_(
vm_modified.get_createEpoch() == vm_queried.get_createEpoch())
self.assert_(test_utils.is_timestamp_between(
epoch_before, epoch_after, vm_queried.get_lastModifiedEpoch()))
self.assert_(test_utils.is_timestamp_between(
epoch_before, epoch_after,
vm_queried.get_vmGlobalSettings().get_createEpoch()))
# Check for lastModifiedEpoch after modifying vm
vm_modified = vm_queried
test_utils.unset_timestamp_fields(vm_modified)
vm_modified.set_name('changed_name')
epoch_before = utils.get_current_epoch_ms()
healthnmon_db_api.vm_save(self.admin_context, vm_modified)
epoch_after = utils.get_current_epoch_ms()
vm_queried = healthnmon_db_api.vm_get_by_ids(
self.admin_context, [vm.get_id()])[0]
self.assert_(test_utils.is_timestamp_between(
epoch_before, epoch_after, vm_queried.get_lastModifiedEpoch()))
self.assert_(test_utils.is_timestamp_between(
epoch_before, epoch_after,
vm_queried.get_vmGlobalSettings().get_lastModifiedEpoch()))
self.assert_(
vm_modified.get_createEpoch() == vm_queried.get_createEpoch())
self.assert_(vm_modified.get_vmGlobalSettings().get_createEpoch() ==
vm_queried.get_vmGlobalSettings().get_createEpoch())
示例4: get_vm_list
# 需要导入模块: from healthnmon.resourcemodel.healthnmonResourceModel import Vm [as 别名]
# 或者: from healthnmon.resourcemodel.healthnmonResourceModel.Vm import set_id [as 别名]
def get_vm_list(self):
vm_list = []
vm = Vm()
vm.set_id('vm-01')
vm.set_name('vm-01')
disk = VmDisk()
disk.set_storageVolumeId('datastore-999')
vm.set_vmHostId('host-1234')
vm.add_vmDisks(disk)
vm_list.append(vm)
vm = Vm()
vm.set_id('vm-02')
vm.set_name('vm-02')
vm_list.append(vm)
return vm_list
示例5: get_single_vm
# 需要导入模块: from healthnmon.resourcemodel.healthnmonResourceModel import Vm [as 别名]
# 或者: from healthnmon.resourcemodel.healthnmonResourceModel.Vm import set_id [as 别名]
def get_single_vm(self):
vm_list = []
vm = Vm()
vm.set_id('vm-01')
vm.set_name('vm-01')
disk1 = VmDisk()
disk1.set_id('disk-01')
disk1.set_storageVolumeId('datastore-939')
disk2 = VmDisk()
disk2.set_id('disk-02')
disk2.set_storageVolumeId('datastore-439')
vm.add_vmDisks(disk1)
vm.add_vmDisks(disk2)
vm.set_vmHostId('host-329')
vm_list.append(vm)
return vm_list
示例6: _createCache
# 需要导入模块: from healthnmon.resourcemodel.healthnmonResourceModel import Vm [as 别名]
# 或者: from healthnmon.resourcemodel.healthnmonResourceModel.Vm import set_id [as 别名]
def _createCache(self):
self.mox.StubOutWithMock(api, 'vm_host_get_all')
vmhost = VmHost()
vmhost.set_id('vmhost1')
vm = Vm()
vm.set_id('vm1')
stPool = StorageVolume()
stPool.set_id('stpool1')
subnet = Subnet()
subnet.set_id('bridge0')
api.vm_host_get_all(mox.IgnoreArg()).AndReturn([vmhost])
self.mox.StubOutWithMock(api, 'vm_get_all')
api.vm_get_all(mox.IgnoreArg()).AndReturn([vm])
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])
示例7: test_storagevolume_delete
# 需要导入模块: from healthnmon.resourcemodel.healthnmonResourceModel import Vm [as 别名]
# 或者: from healthnmon.resourcemodel.healthnmonResourceModel.Vm import set_id [as 别名]
def test_storagevolume_delete(self):
storagevolume = StorageVolume()
storagevolume_id = 'SV1'
storagevolume.id = storagevolume_id
vm = Vm()
vm.set_id('vm-01')
vmGlobalSettings = VmGlobalSettings()
vmGlobalSettings.set_id('vm_01')
vm.set_vmGlobalSettings(vmGlobalSettings)
vmDisk = VmDisk()
vmDisk.set_id('disk-01')
vmDisk.set_storageVolumeId(storagevolume_id)
vm.add_vmDisks(vmDisk)
vmDisk = VmDisk()
vmDisk.set_id('disk-02')
vmDisk.set_storageVolumeId('SV2')
vm.add_vmDisks(vmDisk)
healthnmon_db_api.vm_save(self.admin_context, vm)
healthnmon_db_api.storage_volume_save(self.admin_context,
storagevolume)
storagevolumes = \
healthnmon_db_api.storage_volume_get_by_ids(self.admin_context,
[storagevolume_id])
self.assertFalse(storagevolumes is None,
'storage volume get by id returned a none list'
)
self.assertTrue(
len(storagevolumes) > 0,
'storage volume get by id returned invalid number of list')
healthnmon_db_api.storage_volume_delete_by_ids(self.admin_context,
[storagevolume_id])
storagevolumes = \
healthnmon_db_api.storage_volume_get_by_ids(self.admin_context,
[storagevolume_id])
self.assertTrue(storagevolumes is None or len(storagevolumes)
== 0, 'Storage volume not deleted')
示例8: createInvCache
# 需要导入模块: from healthnmon.resourcemodel.healthnmonResourceModel import Vm [as 别名]
# 或者: from healthnmon.resourcemodel.healthnmonResourceModel.Vm import set_id [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)
示例9: test_diff_resourcemodel_vm_with_type_changes
# 需要导入模块: from healthnmon.resourcemodel.healthnmonResourceModel import Vm [as 别名]
# 或者: from healthnmon.resourcemodel.healthnmonResourceModel.Vm import set_id [as 别名]
def test_diff_resourcemodel_vm_with_type_changes(self):
old_vm = Vm()
old_vm.set_id(unicode('vm-01'))
old_vm.set_name(unicode('vm-01'))
disk1 = VmDisk()
disk1.set_id(unicode('disk-01'))
disk1.set_storageVolumeId(unicode("datastore-939"))
old_vm.add_vmDisks(disk1)
old_vm.set_vmHostId(unicode('host-329'))
new_vm = Vm()
new_vm.set_id('vm-01')
new_vm.set_name('vm-01')
disk3 = VmDisk()
disk3.set_id('disk-01')
disk3.set_storageVolumeId("datastore-939")
new_vm.add_vmDisks(disk3)
new_vm.set_vmHostId('host-329')
diff = ResourceModelDiff(old_vm, new_vm)
diff_res = diff.diff_resourcemodel()
self.assertTrue(len(diff_res) == 0)
示例10: test_vm_host_delete
# 需要导入模块: from healthnmon.resourcemodel.healthnmonResourceModel import Vm [as 别名]
# 或者: from healthnmon.resourcemodel.healthnmonResourceModel.Vm import set_id [as 别名]
def test_vm_host_delete(self):
vmhost_id = 'VH1'
vmhost = VmHost()
vmhost.id = vmhost_id
vSwitch = VirtualSwitch()
vSwitch.set_id('vSwitch-01')
vSwitch.set_name('vSwitch-01')
vSwitch.set_resourceManagerId('rmId')
vSwitch.set_switchType('vSwitch')
cost1 = Cost()
cost1.set_value(100)
cost1.set_units('USD')
vSwitch.set_cost(cost1)
portGroup = PortGroup()
portGroup.set_id('pg-01')
portGroup.set_name('pg-01')
portGroup.set_resourceManagerId('rmId')
portGroup.set_type('portgroup_type')
portGroup.set_cost(cost1)
vSwitch.add_portGroups(portGroup)
vmhost.add_virtualSwitches(vSwitch)
vmhost.add_portGroups(portGroup)
healthnmon_db_api.vm_host_save(get_admin_context(), vmhost)
vmhost2 = VmHost()
vmhost2.set_id('VH2')
healthnmon_db_api.vm_host_save(get_admin_context(), vmhost2)
storage = StorageVolume()
storage.set_id('sv-01')
storage.set_name('storage-01')
storage.set_resourceManagerId('rmId')
storage.set_size(1234)
storage.set_free(2345)
storage.set_vmfsVolume(True)
storage.set_shared(True)
storage.set_assignedServerCount(1)
storage.set_volumeType('VMFS')
storage.set_volumeId('101')
hostMount1 = HostMountPoint()
hostMount1.set_path('test_path1')
hostMount1.set_vmHostId('VH1')
storage.add_mountPoints(hostMount1)
hostMount2 = HostMountPoint()
hostMount2.set_path('test_path2')
hostMount2.set_vmHostId('VH2')
storage.add_mountPoints(hostMount2)
healthnmon_db_api.storage_volume_save(get_admin_context(),
storage)
vm = Vm()
vm.set_id('vm-01')
vm.set_name('vm-01')
vm.set_vmHostId('VH1')
healthnmon_db_api.vm_save(get_admin_context(), vm)
vmhosts = \
healthnmon_db_api.vm_host_get_by_ids(get_admin_context(),
[vmhost_id])
self.assertFalse(vmhosts is None,
'host get by id returned a none list')
self.assertTrue(len(vmhosts) > 0,
'host get by id returned invalid number of list'
)
healthnmon_db_api.vm_host_delete_by_ids(get_admin_context(),
[vmhost_id])
vmhosts = \
healthnmon_db_api.vm_host_get_by_ids(get_admin_context(),
[vmhost_id])
self.assertTrue(vmhosts is None or len(vmhosts) == 0,
'host not deleted')
示例11: APiTest
# 需要导入模块: from healthnmon.resourcemodel.healthnmonResourceModel import Vm [as 别名]
# 或者: from healthnmon.resourcemodel.healthnmonResourceModel.Vm import set_id [as 别名]
class APiTest(test.TestCase):
''' TestCase for healthnmon.notifier.api '''
def setUp(self):
super(APiTest, self).setUp()
self.mox.StubOutWithMock(nova_db, 'service_get_all_by_topic')
self.vm = Vm()
self.vm.set_id('12345')
self.vm.set_name('TestVm')
self.flags(healthnmon_notification_drivers=[
'nova.openstack.common.notifier.test_notifier'])
test_notifier.NOTIFICATIONS = []
def testNotify(self):
scheduler_services = [{'host': 'testhost'}]
nova_db. \
service_get_all_by_topic(
mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn(scheduler_services)
self.mox.ReplayAll()
self.assertEquals(events_api.notify(
event_metadata.EVENT_TYPE_VM_DELETED,
self.vm), None)
msg = test_notifier.NOTIFICATIONS[0]
self.assertEquals(msg['priority'], notifier_api.INFO)
event_type = \
event_metadata.get_EventMetaData(
event_metadata.EVENT_TYPE_VM_DELETED)
self.assertEquals(msg['event_type'],
event_type.get_event_fully_qal_name())
self.assertEquals(msg['publisher_id'],
'testhost.healthnmon')
payload = msg['payload']
self.assertEquals(payload['entity_type'], 'Vm')
self.assertEquals(payload['entity_id'],
self.vm.get_id())
def testNotifyNoneScheduler(self):
scheduler_services = None
nova_db. \
service_get_all_by_topic(
mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn(scheduler_services)
self.mox.ReplayAll()
self.assertEquals(events_api.notify(
event_metadata.EVENT_TYPE_VM_DELETED, self.vm), None)
msg = test_notifier.NOTIFICATIONS[0]
self.assertEquals(msg['priority'], notifier_api.INFO)
event_type = \
event_metadata.get_EventMetaData(
event_metadata.EVENT_TYPE_VM_DELETED)
self.assertEquals(msg['event_type'],
event_type.get_event_fully_qal_name())
self.assertEquals(msg['publisher_id'],
'healthnmon')
payload = msg['payload']
self.assertEquals(payload['entity_type'], 'Vm')
self.assertEquals(payload['entity_id'],
self.vm.get_id())
def testNotifyEmptyScheduler(self):
scheduler_services = []
nova_db.service_get_all_by_topic(
mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn(scheduler_services)
self.mox.ReplayAll()
self.assertEquals(events_api.notify(
event_metadata.EVENT_TYPE_VM_DELETED, self.vm), None)
msg = test_notifier.NOTIFICATIONS[0]
self.assertEquals(msg['priority'], notifier_api.INFO)
event_type = \
event_metadata.get_EventMetaData(
event_metadata.EVENT_TYPE_VM_DELETED)
self.assertEquals(msg['event_type'],
event_type.get_event_fully_qal_name())
self.assertEquals(msg['publisher_id'],
'healthnmon')
payload = msg['payload']
self.assertEquals(payload['entity_type'], 'Vm')
self.assertEquals(payload['entity_id'],
self.vm.get_id())
def testNotifyMultipleScheduler(self):
scheduler_services = [{'host': 'testhost'}, {'host': 'testhost2'
}]
nova_db.service_get_all_by_topic(
mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn(scheduler_services)
self.mox.ReplayAll()
self.assertEquals(events_api.notify(
event_metadata.EVENT_TYPE_VM_DELETED, self.vm), None)
#.........这里部分代码省略.........
示例12: test_diff_resourcemodel_vm_withaddupdtedelete
# 需要导入模块: from healthnmon.resourcemodel.healthnmonResourceModel import Vm [as 别名]
# 或者: from healthnmon.resourcemodel.healthnmonResourceModel.Vm import set_id [as 别名]
def test_diff_resourcemodel_vm_withaddupdtedelete(self):
vm = Vm()
vm.set_id('vm-01')
vm.set_name('vm-01')
disk1 = VmDisk()
disk1.set_id('disk-01')
disk1.set_storageVolumeId('datastore-939')
disk2 = VmDisk()
disk2.set_id('disk-02')
disk2.set_storageVolumeId('datastore-439')
vm.add_vmDisks(disk1)
vm.add_vmDisks(disk2)
vm.set_vmHostId('host-329')
vm1 = Vm()
vm1.set_id('vm-01')
vm1.set_name('vm-01')
disk11 = VmDisk()
disk11.set_id('disk-01')
disk11.set_storageVolumeId('datastore-939-999')
disk21 = VmDisk()
disk21.set_id('disk-03')
disk21.set_storageVolumeId('datastore-439-999')
vm1.add_vmDisks(disk11)
vm1.add_vmDisks(disk21)
vm1.set_vmHostId('host-329-999')
diff = ResourceModelDiff(vm, vm1)
diff_res = diff.diff_resourcemodel()
self.assertTrue(len(diff_res) > 0)
self.assertTrue(self.update in diff_res)
vmDisks = 'vmDisks'
self.assertTrue(vmDisks in diff_res[self.update])
self.assertTrue(self.add in diff_res[self.update][vmDisks])
self.assertTrue('disk-03' in diff_res[self.update][vmDisks][self.add])
self.assertTrue(isinstance(diff_res[self.update][vmDisks][self.add][
'disk-03'], VmDisk))
addVmdisk = diff_res[self.update][vmDisks][self.add]['disk-03']
self.assertEquals(addVmdisk.get_storageVolumeId(), 'datastore-439-999')
self.assertTrue(self.delete in diff_res[self.update][vmDisks])
self.assertTrue('disk-02' in diff_res[self.update][vmDisks][
self.delete])
self.assertTrue(isinstance(diff_res[self.update][vmDisks][
self.delete]['disk-02'], VmDisk))
delVmdisk = diff_res[self.update][vmDisks][self.delete]['disk-02']
self.assertEquals(delVmdisk.get_storageVolumeId(), 'datastore-439')
self.assertTrue(self.update in diff_res[self.update][vmDisks])
self.assertTrue('disk-01' in diff_res[self.update][vmDisks][
self.update])
self.assertTrue(self.update in diff_res[self.update][vmDisks][
self.update]['disk-01'])
self.assertTrue('storageVolumeId' in diff_res[self.update][vmDisks][
self.update]['disk-01'][self.update])
self.assertEquals(diff_res[self.update][vmDisks][self.update][
'disk-01'][self.update]['storageVolumeId'],
'datastore-939-999')
self.assertTrue('vmHostId' in diff_res[self.update])
self.assertEquals(diff_res[self.update]['vmHostId'], 'host-329-999')