Skip to content

Commit

Permalink
Add get_controllers func
Browse files Browse the repository at this point in the history
Also update del_controller func

Signed-off-by: Kylazhang <[email protected]>
  • Loading branch information
kylazhang committed May 20, 2019
1 parent ef129ab commit 1cee6f9
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions virttest/libvirt_xml/vm_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,21 +554,30 @@ def del_controller(self, controller_type=None):
:return: None if deleting all controllers
"""
all_controllers = self.xmltreefile.findall("devices/controller")
del_controllers = []
for controller in all_controllers:
if controller.get("type") != controller_type:
continue
del_controllers.append(controller)

# no seclabel tag found in xml.
del_controllers = self.get_controllers(controller_type=controller_type)
if del_controllers == []:
logging.debug("Controller %s for this domain does not "
"exist" % controller_type)

for controller in del_controllers:
self.xmltreefile.remove(controller)

def get_controllers(self, controller_type=None):
"""
Get controllers according controller type
:param controller_type: type of controllers need to get
:return: controller list
"""
all_controllers = self.xmltreefile.findall("devices/controller")
type_controllers = []
for controller in all_controllers:
if controller.get("type") != controller_type:
continue
type_controllers.append(controller)
return type_controllers


class VMXML(VMXMLBase):

Expand Down

0 comments on commit 1cee6f9

Please sign in to comment.