util: Add a few duplicated functions
This commit is contained in:
parent
39fe2ed1f7
commit
75c3d4dc1a
|
@ -284,11 +284,7 @@ class vmmConnection(vmmGObject):
|
|||
def pretty_host_memory_size(self):
|
||||
if self.vmm is None:
|
||||
return ""
|
||||
mem = self.host_memory_size()
|
||||
if mem > (10 * 1024 * 1024):
|
||||
return "%2.2f GB" % (mem / (1024.0 * 1024.0))
|
||||
else:
|
||||
return "%2.0f MB" % (mem / 1024.0)
|
||||
return util.pretty_mem(self.host_memory_size())
|
||||
|
||||
def host_memory_size(self):
|
||||
if self.vmm is None:
|
||||
|
@ -1595,11 +1591,7 @@ class vmmConnection(vmmGObject):
|
|||
return self._get_record_helper("memory")
|
||||
|
||||
def pretty_stats_memory(self):
|
||||
mem = self.stats_memory()
|
||||
if mem > (10 * 1024 * 1024):
|
||||
return "%2.2f GB" % (mem / (1024.0 * 1024.0))
|
||||
else:
|
||||
return "%2.0f MB" % (mem / 1024.0)
|
||||
return util.pretty_mem(self.stats_memory())
|
||||
|
||||
def stats_memory_percentage(self):
|
||||
return self._get_record_helper("memoryPercent")
|
||||
|
|
|
@ -824,18 +824,10 @@ class vmmDomainBase(vmmLibvirtObject):
|
|||
return self.get_memory_pretty()
|
||||
|
||||
def get_memory_pretty(self):
|
||||
mem = self.get_memory()
|
||||
if mem > (10 * 1024 * 1024):
|
||||
return "%2.2f GB" % (mem / (1024.0 * 1024.0))
|
||||
else:
|
||||
return "%2.0f MB" % (mem / 1024.0)
|
||||
return util.pretty_mem(self.get_memory())
|
||||
|
||||
def maximum_memory_pretty(self):
|
||||
mem = self.maximum_memory()
|
||||
if mem > (10 * 1024 * 1024):
|
||||
return "%2.2f GB" % (mem / (1024.0 * 1024.0))
|
||||
else:
|
||||
return "%2.0f MB" % (mem / 1024.0)
|
||||
return util.pretty_mem(self.maximum_memory())
|
||||
|
||||
def cpu_time_pretty(self):
|
||||
return "%2.2f %%" % self.cpu_time_percentage()
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
# MA 02110-1301 USA.
|
||||
#
|
||||
|
||||
import virtinst
|
||||
from virtinst import Interface
|
||||
|
||||
from virtManager import util
|
||||
|
@ -52,15 +51,14 @@ class vmmInterface(vmmLibvirtObject):
|
|||
|
||||
def xpath(self, *args, **kwargs):
|
||||
# Must use this function for ALL XML parsing
|
||||
ret = virtinst.util.get_xml_path(self.get_xml(), *args, **kwargs)
|
||||
ret = util.xpath(self.get_xml(), *args, **kwargs)
|
||||
if ret:
|
||||
return ret
|
||||
if not self.is_active():
|
||||
return ret
|
||||
|
||||
# The running config did not have the info requested
|
||||
return virtinst.util.get_xml_path(self.get_xml(inactive=True),
|
||||
*args, **kwargs)
|
||||
return util.xpath(self.get_xml(inactive=True), *args, **kwargs)
|
||||
|
||||
def set_active(self, state):
|
||||
self.active = state
|
||||
|
|
|
@ -18,8 +18,7 @@
|
|||
# MA 02110-1301 USA.
|
||||
#
|
||||
|
||||
import virtinst.util as util
|
||||
|
||||
from virtManager import util
|
||||
from virtManager.IPy import IP
|
||||
from virtManager.libvirtobject import vmmLibvirtObject
|
||||
|
||||
|
@ -102,8 +101,8 @@ class vmmNetwork(vmmLibvirtObject):
|
|||
|
||||
def get_ipv4_network(self):
|
||||
xml = self.get_xml()
|
||||
addrStr = util.get_xml_path(xml, "/network/ip/@address")
|
||||
netmaskStr = util.get_xml_path(xml, "/network/ip/@netmask")
|
||||
addrStr = util.xpath(xml, "/network/ip/@address")
|
||||
netmaskStr = util.xpath(xml, "/network/ip/@netmask")
|
||||
|
||||
netmask = IP(netmaskStr)
|
||||
gateway = IP(addrStr)
|
||||
|
@ -113,14 +112,14 @@ class vmmNetwork(vmmLibvirtObject):
|
|||
|
||||
def get_ipv4_forward(self):
|
||||
xml = self.get_xml()
|
||||
fw = util.get_xml_path(xml, "/network/forward/@mode")
|
||||
forwardDev = util.get_xml_path(xml, "/network/forward/@dev")
|
||||
fw = util.xpath(xml, "/network/forward/@mode")
|
||||
forwardDev = util.xpath(xml, "/network/forward/@dev")
|
||||
return [fw, forwardDev]
|
||||
|
||||
def get_ipv4_dhcp_range(self):
|
||||
xml = self.get_xml()
|
||||
dhcpstart = util.get_xml_path(xml, "/network/ip/dhcp/range[1]/@start")
|
||||
dhcpend = util.get_xml_path(xml, "/network/ip/dhcp/range[1]/@end")
|
||||
dhcpstart = util.xpath(xml, "/network/ip/dhcp/range[1]/@start")
|
||||
dhcpend = util.xpath(xml, "/network/ip/dhcp/range[1]/@end")
|
||||
if not dhcpstart or not dhcpend:
|
||||
return None
|
||||
|
||||
|
@ -135,6 +134,6 @@ class vmmNetwork(vmmLibvirtObject):
|
|||
forward = self.get_ipv4_forward()[0]
|
||||
if forward and forward != "nat":
|
||||
return True
|
||||
return bool(util.get_xml_path(xml, "/network/ip/dhcp/bootp/@file"))
|
||||
return bool(util.xpath(xml, "/network/ip/dhcp/bootp/@file"))
|
||||
|
||||
vmmLibvirtObject.type_register(vmmNetwork)
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
|
||||
import gobject
|
||||
import virtinst
|
||||
import virtinst.util as util
|
||||
|
||||
from virtManager import util
|
||||
from virtManager.libvirtobject import vmmLibvirtObject
|
||||
from virtManager.storagevol import vmmStorageVolume
|
||||
|
||||
|
@ -87,24 +87,24 @@ class vmmStoragePool(vmmLibvirtObject):
|
|||
return self.pool.autostart()
|
||||
|
||||
def get_target_path(self):
|
||||
return util.get_xml_path(self.get_xml(), "/pool/target/path")
|
||||
return util.xpath(self.get_xml(), "/pool/target/path")
|
||||
|
||||
def get_allocation(self):
|
||||
return long(util.get_xml_path(self.get_xml(), "/pool/allocation"))
|
||||
return long(util.xpath(self.get_xml(), "/pool/allocation"))
|
||||
def get_available(self):
|
||||
return long(util.get_xml_path(self.get_xml(), "/pool/available"))
|
||||
return long(util.xpath(self.get_xml(), "/pool/available"))
|
||||
def get_capacity(self):
|
||||
return long(util.get_xml_path(self.get_xml(), "/pool/capacity"))
|
||||
return long(util.xpath(self.get_xml(), "/pool/capacity"))
|
||||
|
||||
def get_pretty_allocation(self):
|
||||
return self._prettyify(self.get_allocation())
|
||||
return util.pretty_bytes(self.get_allocation())
|
||||
def get_pretty_available(self):
|
||||
return self._prettyify(self.get_available())
|
||||
return util.pretty_bytes(self.get_available())
|
||||
def get_pretty_capacity(self):
|
||||
return self._prettyify(self.get_capacity())
|
||||
return util.pretty_bytes(self.get_capacity())
|
||||
|
||||
def get_type(self):
|
||||
return util.get_xml_path(self.get_xml(), "/pool/@type")
|
||||
return util.xpath(self.get_xml(), "/pool/@type")
|
||||
|
||||
def get_volumes(self):
|
||||
self.update_volumes()
|
||||
|
@ -139,11 +139,4 @@ class vmmStoragePool(vmmLibvirtObject):
|
|||
volname)
|
||||
self._volumes = new_vol_list
|
||||
|
||||
|
||||
def _prettyify(self, val):
|
||||
if val > (1024 * 1024 * 1024):
|
||||
return "%2.2f GB" % (val / (1024.0 * 1024.0 * 1024.0))
|
||||
else:
|
||||
return "%2.2f MB" % (val / (1024.0 * 1024.0))
|
||||
|
||||
vmmLibvirtObject.type_register(vmmStoragePool)
|
||||
|
|
|
@ -18,8 +18,7 @@
|
|||
# MA 02110-1301 USA.
|
||||
#
|
||||
|
||||
import virtinst.util as util
|
||||
|
||||
from virtManager import util
|
||||
from virtManager.libvirtobject import vmmLibvirtObject
|
||||
|
||||
class vmmStorageVolume(vmmLibvirtObject):
|
||||
|
@ -49,28 +48,22 @@ class vmmStorageVolume(vmmLibvirtObject):
|
|||
del(self.vol)
|
||||
|
||||
def get_target_path(self):
|
||||
return util.get_xml_path(self.get_xml(), "/volume/target/path")
|
||||
return util.xpath(self.get_xml(), "/volume/target/path")
|
||||
|
||||
def get_format(self):
|
||||
return util.get_xml_path(self.get_xml(), "/volume/target/format/@type")
|
||||
return util.xpath(self.get_xml(), "/volume/target/format/@type")
|
||||
|
||||
def get_allocation(self):
|
||||
return long(util.get_xml_path(self.get_xml(), "/volume/allocation"))
|
||||
return long(util.xpath(self.get_xml(), "/volume/allocation"))
|
||||
def get_capacity(self):
|
||||
return long(util.get_xml_path(self.get_xml(), "/volume/capacity"))
|
||||
return long(util.xpath(self.get_xml(), "/volume/capacity"))
|
||||
|
||||
def get_pretty_capacity(self):
|
||||
return self._prettyify(self.get_capacity())
|
||||
return util.pretty_bytes(self.get_capacity())
|
||||
def get_pretty_allocation(self):
|
||||
return self._prettyify(self.get_allocation())
|
||||
return util.pretty_bytes(self.get_allocation())
|
||||
|
||||
def get_type(self):
|
||||
return util.get_xml_path(self.get_xml(), "/volume/format/@type")
|
||||
|
||||
def _prettyify(self, val):
|
||||
if val > (1024 * 1024 * 1024):
|
||||
return "%2.2f GB" % (val / (1024.0 * 1024.0 * 1024.0))
|
||||
else:
|
||||
return "%2.2f MB" % (val / (1024.0 * 1024.0))
|
||||
return util.xpath(self.get_xml(), "/volume/format/@type")
|
||||
|
||||
vmmLibvirtObject.type_register(vmmStorageVolume)
|
||||
|
|
|
@ -71,8 +71,7 @@ def host_disk_space(conn):
|
|||
# FIXME: make sure not inactive?
|
||||
# FIXME: use a conn specific function after we send pool-added
|
||||
pool.refresh()
|
||||
avail = int(virtinst.util.get_xml_path(pool.get_xml(),
|
||||
"/pool/available"))
|
||||
avail = int(util.xpath(pool.get_xml(), "/pool/available"))
|
||||
|
||||
elif not conn.is_remote():
|
||||
vfs = os.statvfs(os.path.dirname(path))
|
||||
|
|
|
@ -400,3 +400,19 @@ def iface_in_use_by(conn, name):
|
|||
use_str += iface.get_name()
|
||||
|
||||
return use_str
|
||||
|
||||
def pretty_mem(val):
|
||||
val = int(val)
|
||||
if val > (10 * 1024 * 1024):
|
||||
return "%2.2f GB" % (val / (1024.0 * 1024.0))
|
||||
else:
|
||||
return "%2.0f MB" % (val / 1024.0)
|
||||
|
||||
def pretty_bytes(val):
|
||||
val = int(val)
|
||||
if val > (1024 * 1024 * 1024):
|
||||
return "%2.2f GB" % (val / (1024.0 * 1024.0 * 1024.0))
|
||||
else:
|
||||
return "%2.2f MB" % (val / (1024.0 * 1024.0))
|
||||
|
||||
xpath = virtinst.util.get_xml_path
|
||||
|
|
Loading…
Reference in New Issue