From 57aab5de17ecc5ff7000eb07311e4143e37aa73c Mon Sep 17 00:00:00 2001 From: Martin Kletzander Date: Mon, 2 Sep 2013 16:56:22 +0200 Subject: [PATCH] Add support for multifunction address parameter --- virtinst/device.py | 3 ++- virtinst/xmlbuilder.py | 14 +++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/virtinst/device.py b/virtinst/device.py index 0cce561e..6bcebf41 100644 --- a/virtinst/device.py +++ b/virtinst/device.py @@ -136,7 +136,7 @@ class VirtualDeviceAddress(XMLBuilder): _XML_ROOT_XPATH = "/domain/devices/device/address" _XML_PROP_ORDER = ["type", "domain", "controller", "bus", "slot", - "function", "target", "unit"] + "function", "target", "unit", "multifunction"] def set_addrstr(self, addrstr): if addrstr is None: @@ -165,3 +165,4 @@ class VirtualDeviceAddress(XMLBuilder): unit = XMLProperty(xpath="./address/@unit", is_int=True) port = XMLProperty(xpath="./address/@port", is_int=True) target = XMLProperty(xpath="./address/@target", is_int=True) + multifunction = XMLProperty(xpath="./address/@multifunction", is_onoff=True) diff --git a/virtinst/xmlbuilder.py b/virtinst/xmlbuilder.py index 2c1f569b..3e7dde8d 100644 --- a/virtinst/xmlbuilder.py +++ b/virtinst/xmlbuilder.py @@ -1,7 +1,7 @@ # # Base class for all VM devices # -# Copyright 2008 Red Hat, Inc. +# Copyright 2008, 2013 Red Hat, Inc. # Cole Robinson # # This program is free software; you can redistribute it and/or modify @@ -251,7 +251,8 @@ class XMLProperty(property): set_converter=None, validate_cb=None, make_getter_xpath_cb=None, make_setter_xpath_cb=None, is_bool=False, is_int=False, is_yesno=False, - clear_first=None, default_cb=None, default_name=None): + clear_first=None, default_cb=None, default_name=None, + is_onoff=False): """ Set a XMLBuilder class property that represents a value in the XML. For example @@ -282,6 +283,7 @@ class XMLProperty(property): @param is_bool: Whether this is a boolean property in the XML @param is_int: Whethere this is an integer property in the XML @param is_yesno: Whethere this is a yes/no property in the XML + @param is_onoff: Whethere this is a on/off property in the XML @param clear_first: List of xpaths to unset before any 'set' operation. For those weird interdependent XML props like disk source type and path attribute. @@ -301,6 +303,7 @@ class XMLProperty(property): self._is_bool = is_bool self._is_int = is_int self._is_yesno = is_yesno + self._is_onoff = is_onoff self._xpath_for_getter_cb = make_getter_xpath_cb self._xpath_for_setter_cb = make_setter_xpath_cb @@ -312,7 +315,8 @@ class XMLProperty(property): self._default_name = default_name if sum([int(bool(i)) for i in - [self._is_bool, self._is_int, self._is_yesno]]) > 1: + [self._is_bool, self._is_int, + self._is_yesno, self._is_onoff]]) > 1: raise RuntimeError("Conflict property converter options.") if self._default_name and not self._default_cb: @@ -397,6 +401,8 @@ class XMLProperty(property): ret = int(val, **intkwargs) elif self._is_yesno and val is not None: ret = bool(val == "yes") + elif self._is_onoff and val is not None: + ret = bool(val == "on") else: ret = val return ret @@ -404,6 +410,8 @@ class XMLProperty(property): def _convert_set_value(self, xmlbuilder, val): if self._default_name and val == self._default_name: val = self._default_cb(xmlbuilder) + elif self._is_onoff and val is not None: + val = bool(val) and "on" or "off" elif self._is_yesno and val is not None: val = bool(val) and "yes" or "no" elif self._is_int and val is not None: