def get_ipv4_dhcp_range(self): xml = self.get_xml() 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 return [IP(dhcpstart), IP(dhcpend)]
def xpath(self, *args, **kwargs): # Must use this function for ALL XML parsing 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 util.xpath(self.get_xml(inactive=True), *args, **kwargs)
def get_ipv4_network(self): xml = self.get_xml() if util.xpath(xml, "/network/ip") is None: return None addrStr = util.xpath(xml, "/network/ip/@address") netmaskStr = util.xpath(xml, "/network/ip/@netmask") netmask = IP(netmaskStr) gateway = IP(addrStr) network = IP(gateway.int() & netmask.int()) return IP(str(network) + "/" + netmaskStr)
def host_disk_space(conn): pool = util.get_default_pool(conn) path = util.get_default_dir(conn) avail = 0 if pool and pool.is_active(): # FIXME: make sure not inactive? # FIXME: use a conn specific function after we send pool-added pool.refresh() avail = int(util.xpath(pool.get_xml(), "/pool/available")) elif not conn.is_remote() and os.path.exists(path): vfs = os.statvfs(os.path.dirname(path)) avail = vfs[statvfs.F_FRSIZE] * vfs[statvfs.F_BAVAIL] return float(avail / 1024.0 / 1024.0 / 1024.0)
def get_type(self): return util.xpath(self.get_xml(), "/pool/@type")
def get_ipv6_route(self): xml = self.get_xml() ipv6_route = util.xpath(xml, "/network/@ipv6") return ipv6_route
def get_capacity(self): return long(util.xpath(self.get_xml(), "/volume/capacity"))
def get_format(self): return util.xpath(self.get_xml(), "/volume/target/format/@type")
def get_available(self): return long(util.xpath(self.get_xml(), "/pool/available"))
def get_target_path(self): return util.xpath(self.get_xml(), "/pool/target/path")
def get_ipv4_forward(self): xml = self.get_xml() fw = util.xpath(xml, "/network/forward/@mode") forwardDev = util.xpath(xml, "/network/forward/@dev") return [fw, forwardDev]
def get_allocation(self): return long(util.xpath(self.get_xml(), "/pool/allocation"))
def can_pxe(self): xml = self.get_xml() forward = self.get_ipv4_forward()[0] if forward and forward != "nat": return True return bool(util.xpath(xml, "/network/ip/dhcp/bootp/@file"))
def get_capacity(self): return long(util.xpath(self.get_xml(), "/pool/capacity"))
def get_target_path(self): return util.xpath(self.get_xml(), "/volume/target/path")
def get_allocation(self): return long(util.xpath(self.get_xml(), "/volume/allocation"))
def get_type(self): return util.xpath(self.get_xml(), "/volume/format/@type")
def get_name_domain(self): xml = self.get_xml() name_domain = util.xpath(xml, "/network/domain/@name") return name_domain
def get_ipv6_routing(self): xml = self.get_xml() ipv6_routing = util.xpath(xml, "/network/@ipv6") return ipv6_routing