Add method for retrieving VM nics
We need a way to retrieve VM nic names. This will allow the Nova Hyper-V driver to enable port metrics when receiving instance power on events. It's safer to query Hyper-V directly rather than relying on Nova's port cache. Change-Id: Ibe7409b392b91204f0cea2bdd32c86ec03d06b67 Partial-Bug: #1794456
This commit is contained in:
parent
865c1cfaa0
commit
c73b074042
@ -715,6 +715,30 @@ class VMUtilsTestCase(test_base.OsWinBaseTestCase):
|
||||
self._vmutils._jobutils.remove_virt_resource.assert_called_once_with(
|
||||
mock_nic_data)
|
||||
|
||||
@mock.patch.object(vmutils.VMUtils, '_lookup_vm_check')
|
||||
@mock.patch.object(_wqlutils, 'get_element_associated_class')
|
||||
def test_get_vm_nics(self, mock_get_assoc, mock_lookup_vm):
|
||||
vnics = self._vmutils._get_vm_nics(mock.sentinel.vm_name)
|
||||
|
||||
self.assertEqual(mock_get_assoc.return_value, vnics)
|
||||
mock_lookup_vm.assert_called_once_with(mock.sentinel.vm_name)
|
||||
mock_get_assoc.assert_called_once_with(
|
||||
self._vmutils._compat_conn,
|
||||
self._vmutils._SYNTHETIC_ETHERNET_PORT_SETTING_DATA_CLASS,
|
||||
element_instance_id=mock_lookup_vm.return_value.InstanceId)
|
||||
|
||||
@mock.patch.object(vmutils.VMUtils, '_get_vm_nics')
|
||||
def test_get_vm_nic_names(self, mock_get_vm_nics):
|
||||
exp_nic_names = ['port1', 'port2']
|
||||
|
||||
mock_get_vm_nics.return_value = [
|
||||
mock.Mock(ElementName=nic_name)
|
||||
for nic_name in exp_nic_names]
|
||||
nic_names = self._vmutils.get_vm_nic_names(mock.sentinel.vm_name)
|
||||
|
||||
self.assertEqual(exp_nic_names, nic_names)
|
||||
mock_get_vm_nics.assert_called_once_with(mock.sentinel.vm_name)
|
||||
|
||||
def test_set_vm_state(self):
|
||||
mock_vm = self._lookup_vm()
|
||||
mock_vm.RequestStateChange.return_value = (
|
||||
|
@ -628,6 +628,18 @@ class VMUtils(baseutils.BaseUtilsVirt):
|
||||
"to remove vm nic: '%s'. It may have been already "
|
||||
"deleted.", nic_name)
|
||||
|
||||
def _get_vm_nics(self, vm_name):
|
||||
vmsettings = self._lookup_vm_check(vm_name)
|
||||
nics = _wqlutils.get_element_associated_class(
|
||||
self._compat_conn,
|
||||
self._SYNTHETIC_ETHERNET_PORT_SETTING_DATA_CLASS,
|
||||
element_instance_id=vmsettings.InstanceId)
|
||||
return nics
|
||||
|
||||
def get_vm_nic_names(self, vm_name):
|
||||
nics = self._get_vm_nics(vm_name)
|
||||
return [nic.ElementName for nic in nics]
|
||||
|
||||
def soft_shutdown_vm(self, vm_name):
|
||||
vm = self._lookup_vm_check(vm_name, as_vssd=False)
|
||||
shutdown_component = self._conn.Msvm_ShutdownComponent(
|
||||
|
Loading…
Reference in New Issue
Block a user