Browse Source

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 a7f2b65d17)
changes/23/788723/2
Balazs Gibizer 4 months ago
parent
commit
9f90c7268c
1 changed files with 23 additions and 5 deletions
  1. +23
    -5
      nova/virt/libvirt/guest.py

+ 23
- 5
nova/virt/libvirt/guest.py View File

@ -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


Loading…
Cancel
Save