From 9f90c7268cc24e6c8b93858563a3aefa50d0fb56 Mon Sep 17 00:00:00 2001 From: Balazs Gibizer Date: Tue, 23 Feb 2021 17:29:37 +0100 Subject: [PATCH] Follow up type hints for a634103 It is a follow up patch for I86153d31b02e6b74b42d53a6800297cbd0e5cbb4 to add type hints to the functions that was touched by the original patch. Change-Id: I332ea49184200fcaf8d1480da9658fcbb2f325c5 Related-Bug: #1882521 (cherry picked from commit a7f2b65d17376710a311bd2f30a6524437bb3aa8) --- nova/virt/libvirt/guest.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/nova/virt/libvirt/guest.py b/nova/virt/libvirt/guest.py index e87188f264a3..54e63e42928c 100644 --- a/nova/virt/libvirt/guest.py +++ b/nova/virt/libvirt/guest.py @@ -231,13 +231,16 @@ class Guest(object): return interfaces - def get_interface_by_cfg(self, cfg, from_persistent_config=False): + def get_interface_by_cfg( + self, + cfg: vconfig.LibvirtConfigGuestDevice, + from_persistent_config: bool = False + ) -> ty.Optional[vconfig.LibvirtConfigGuestDevice]: """Lookup a full LibvirtConfigGuestDevice with LibvirtConfigGuesDevice generated by nova.virt.libvirt.vif.get_config. :param cfg: config object that represents the guest interface. - :type cfg: a subtype of LibvirtConfigGuestDevice object :param from_persistent_config: query the device from the persistent domain instead of the live domain configuration :returns: nova.virt.libvirt.config.LibvirtConfigGuestDevice instance @@ -255,6 +258,7 @@ class Guest(object): # equality check based on available information on nova side if cfg == interface: return interface + return None def get_vcpus_info(self): """Returns virtual cpus information of guest. @@ -341,10 +345,18 @@ class Guest(object): config.parse_str(self._domain.XMLDesc(0)) return config - def get_disk(self, device, from_persistent_config=False): + def get_disk( + self, + device: str, + from_persistent_config: bool = False + ) -> ty.Optional[vconfig.LibvirtConfigGuestDisk]: """Returns the disk mounted at device - :returns LivirtConfigGuestDisk: mounted at device or None + :param device: the name of either the source or the target device + :param from_persistent_config: query the device from the persistent + domain (i.e. inactive XML configuration that'll be used on next + start of the domain) instead of the live domain configuration + :returns LibvirtConfigGuestDisk: mounted at device or None """ flags = 0 if from_persistent_config: @@ -367,6 +379,8 @@ class Guest(object): conf.parse_dom(node) return conf + return None + def get_all_disks(self): """Returns all the disks for a guest @@ -375,7 +389,11 @@ class Guest(object): return self.get_all_devices(vconfig.LibvirtConfigGuestDisk) - def get_all_devices(self, devtype=None, from_persistent_config=False): + def get_all_devices( + self, + devtype: vconfig.LibvirtConfigGuestDevice = None, + from_persistent_config: bool = False + ) -> ty.List[vconfig.LibvirtConfigGuestDevice]: """Returns all devices for a guest :param devtype: a LibvirtConfigGuestDevice subclass class