Beispiel #1
0
def vds_get_hdd(conn, dom, storages):
    """

    Function return vds hdd info.

    """

    xml = dom.XMLDesc(0)
    hdd = util.get_xml_path(xml, "/domain/devices/disk[1]/source/@file")

    # If xml create custom
    if not hdd:
        hdd = util.get_xml_path(xml, "/domain/devices/disk[1]/source/@dev")
    try:
        img = conn.storageVolLookupByPath(hdd)
        img_vol = img.name()
        for storage in storages:
            stg = conn.storagePoolLookupByName(storage)
            if stg.info()[0] != 0:
                stg.refresh(0)
                for img in stg.listVolumes():
                    if img == img_vol:
                        vol = img
                        vol_stg = storage
        return vol, vol_stg
    except:
        return hdd, 'Not in the pool'
Beispiel #2
0
    def vds_get_hdd(self, vname):
        """

        Function return vds hdd info.

        """

        all_hdd_dev = {}
        storages = self.storages_get_node()
        dom = self.lookupVM(vname)
        xml = dom.XMLDesc(0)

        for num in range(1, 5):
            hdd_dev = util.get_xml_path(xml, "/domain/devices/disk[%s]/@device" % (num))
            if hdd_dev == 'disk':
                dev_bus = util.get_xml_path(xml, "/domain/devices/disk[%s]/target/@dev" % (num))
                hdd = util.get_xml_path(xml, "/domain/devices/disk[%s]/source/@file" % (num))
                # If xml create custom
                if not hdd:
                    hdd = util.get_xml_path(xml, "/domain/devices/disk[%s]/source/@dev" % (num))
                try:
                    img = self.storageVolPath(hdd)
                    img_vol = img.name()
                    for storage in storages:
                        stg = self.storagePool(storage)
                        if stg.info()[0] != 0:
                            stg.refresh(0)
                            for img in stg.listVolumes():
                                if img == img_vol:
                                    vol = img
                                    vol_stg = storage
                    all_hdd_dev[dev_bus] = vol, vol_stg
                except:
                    all_hdd_dev[dev_bus] = hdd, 'Not in the pool'
        return all_hdd_dev
Beispiel #3
0
	def vms_on_host():
		import virtinst.util as util
		import libvirt
		host_mem = conn.getInfo()[1] * 1048576
		try:
			vname = {}
			for id in conn.listDomainsID():
				id = int(id)
				dom = conn.lookupByID(id)
				mem = util.get_xml_path(dom.XMLDesc(0), "/domain/memory")
				mem = int(mem) * 1024
				mem_usage = (mem * 100) / host_mem
				vcpu = util.get_xml_path(dom.XMLDesc(0), "/domain/vcpu")
				vname[dom.name()] = (dom.info()[0], vcpu, mem, mem_usage)
			for id in conn.listDefinedDomains():
				dom = conn.lookupByName(id)
				mem = util.get_xml_path(dom.XMLDesc(0), "/domain/memory")
				mem = int(mem) * 1024
				mem_usage = (mem * 100) / host_mem
				vcpu = util.get_xml_path(dom.XMLDesc(0), "/domain/vcpu")
				vname[dom.name()] = (dom.info()[0], vcpu, mem, mem_usage)
			return vname
		except libvirt.libvirtError as e:
			add_error(e, 'libvirt')
			return "error"
Beispiel #4
0
 def get_ipv4_forward():
     try:
         xml = net.XMLDesc(0)
         fw = util.get_xml_path(xml, "/network/forward/@mode")
         forwardDev = util.get_xml_path(xml, "/network/forward/@dev")
         return [fw, forwardDev]
     except libvirt.libvirtError as e:
         add_error(e, 'libvirt')
         return "error"
Beispiel #5
0
	def get_ipv4_forward():
		try:
			xml = net.XMLDesc(0)
			fw = util.get_xml_path(xml, "/network/forward/@mode")
			forwardDev = util.get_xml_path(xml, "/network/forward/@dev")
			return [fw, forwardDev]
		except libvirt.libvirtError as e:
			add_error(e, 'libvirt')
			return "error"
Beispiel #6
0
 def get_vm_nic():
    try:
       xml = dom.XMLDesc(0)
       mac = util.get_xml_path(xml, "/domain/devices/interface/mac/@address")
       nic = util.get_xml_path(xml, "/domain/devices/interface/source/@network")
       if nic is None:
       	nic = util.get_xml_path(xml, "/domain/devices/interface/source/@bridge")
       return mac, nic
    except libvirt.libvirtError as e:
       add_error(e, 'libvirt')
       return "error"
Beispiel #7
0
 def get_vm_hdd():
    try:
       xml = dom.XMLDesc(0)
       hdd_path = util.get_xml_path(xml, "/domain/devices/disk[1]/source/@file")
       hdd_fmt = util.get_xml_path(xml, "/domain/devices/disk[1]/driver/@type")
       #image = re.sub('\/.*\/', '', hdd_path)
       size = dom.blockInfo(hdd_path, 0)[0]
       #return image, size, hdd_fmt
       return hdd_path, size, hdd_fmt
    except libvirt.libvirtError as e:
       add_error(e, 'libvirt')
       return "error"
Beispiel #8
0
	def get_ipv4_dhcp_range():
		try:
			net = conn.networkLookupByName(pool)
			xml = net.XMLDesc(0)
			dhcpstart = util.get_xml_path(xml, "/network/ip/dhcp/range[1]/@start")
			dhcpend = util.get_xml_path(xml, "/network/ip/dhcp/range[1]/@end")
			if not dhcpstart or not dhcpend:
				return None
			
			return [IP(dhcpstart), IP(dhcpend)]
		except libvirt.libvirtError as e:
			add_error(e, 'libvirt')
			return "error"
Beispiel #9
0
	def get_ipv4_dhcp_range():
		try:
			net = conn.networkLookupByName(pool)
			xml = net.XMLDesc(0)
			dhcpstart = util.get_xml_path(xml, "/network/ip/dhcp/range[1]/@start")
			dhcpend = util.get_xml_path(xml, "/network/ip/dhcp/range[1]/@end")
			if not dhcpstart or not dhcpend:
				return None
			
			return [IP(dhcpstart), IP(dhcpend)]
		except libvirt.libvirtError as e:
			add_error(e, 'libvirt')
			return "error"
Beispiel #10
0
 def get_vm_hdd():
     try:
         xml = dom.XMLDesc(0)
         hdd_path = util.get_xml_path(
             xml, "/domain/devices/disk[1]/source/@file")
         hdd_fmt = util.get_xml_path(
             xml, "/domain/devices/disk[1]/driver/@type")
         #image = re.sub('\/.*\/', '', hdd_path)
         size = dom.blockInfo(hdd_path, 0)[0]
         #return image, size, hdd_fmt
         return hdd_path, size, hdd_fmt
     except libvirt.libvirtError as e:
         add_error(e, 'libvirt')
         return "error"
Beispiel #11
0
 def get_vm_nic():
     try:
         xml = dom.XMLDesc(0)
         mac = util.get_xml_path(xml,
                                 "/domain/devices/interface/mac/@address")
         nic = util.get_xml_path(
             xml, "/domain/devices/interface/source/@network")
         if nic is None:
             nic = util.get_xml_path(
                 xml, "/domain/devices/interface/source/@bridge")
         return mac, nic
     except libvirt.libvirtError as e:
         add_error(e, 'libvirt')
         return "error"
Beispiel #12
0
	def get_emulator():
		try:
			emulator = []
			xml = conn.getCapabilities()
			arch = conn.getInfo()[0]
			if arch == 'x86_64':
				emulator.append(util.get_xml_path(xml,"/capabilities/guest[1]/arch/emulator"))
				emulator.append(util.get_xml_path(xml,"/capabilities/guest[2]/arch/emulator"))
			else:
				emulator = util.get_xml_path(xml,"/capabilities/guest/arch/emulator")
			return emulator
		except libvirt.libvirtError as e:
			add_error(e, 'libvirt')
			return "error"
Beispiel #13
0
	def get_ipv4_net():
		try:
			net = conn.networkLookupByName(pool)
			xml = net.XMLDesc(0)
			addrStr = util.get_xml_path(xml, "/network/ip/@address")
			netmaskStr = util.get_xml_path(xml, "/network/ip/@netmask")

			netmask = IP(netmaskStr)
			gateway = IP(addrStr)

			network = IP(gateway.int() & netmask.int())
			return IP(str(network) + "/" + netmaskStr)
		except libvirt.libvirtError as e:
			add_error(e, 'libvirt')
			return "error"
Beispiel #14
0
    def get_ipv4_net():
        try:
            net = conn.networkLookupByName(pool)
            xml = net.XMLDesc(0)
            addrStr = util.get_xml_path(xml, "/network/ip/@address")
            netmaskStr = util.get_xml_path(xml, "/network/ip/@netmask")

            netmask = IP(netmaskStr)
            gateway = IP(addrStr)

            network = IP(gateway.int() & netmask.int())
            return IP(str(network) + "/" + netmaskStr)
        except libvirt.libvirtError as e:
            add_error(e, 'libvirt')
            return "error"
Beispiel #15
0
	def get_target_path():
		try:
			xml = stg.XMLDesc(0)
			return util.get_xml_path(xml, "/pool/target/path")
		except libvirt.libvirtError as e:
			add_error(e,'libvirt')
			return "error"
Beispiel #16
0
 def get_vm_vnc():
     try:
         xml = dom.XMLDesc(0)
         vnc = util.get_xml_path(xml, "/domain/devices/graphics/@port")
         return vnc
     except:
         print "Get vnc port failed"
Beispiel #17
0
    def new_volume(self, storage, name, size):
        """

        Add new volume in storage

        """

        stg = self.storagePool(storage)
        size = int(size) * 1073741824
        stg_type = util.get_xml_path(stg.XMLDesc(0), "/pool/@type")
        if stg_type == 'dir':
            name = name + '.img'
            alloc = 0
        else:
            alloc = size
        xml = """
            <volume>
                <name>%s</name>
                <capacity>%s</capacity>
                <allocation>%s</allocation>
                <target>
                    <format type='qcow2'/>
                </target>
            </volume>""" % (name, size, alloc)
        stg.createXML(xml, 0)
Beispiel #18
0
    def stg_info():
        import virtinst.util as util

        if stg.info()[3] == 0:
            percent = 0
        else:
            percent = (stg.info()[2] * 100) / stg.info()[1]
        info = stg.info()
        info.append(int(percent))
        info.append(stg.isActive())
        xml = stg.XMLDesc(0)
        info.append(util.get_xml_path(xml, "/pool/@type"))
        info.append(util.get_xml_path(xml, "/pool/target/path"))
        info.append(util.get_xml_path(xml, "/pool/source/device/@path"))
        info.append(util.get_xml_path(xml, "/pool/source/format/@type"))
        return info
Beispiel #19
0
    def get_dom_info():
        import virtinst.util as util

        info = []

        xml = dom.XMLDesc(0)
        info.append(util.get_xml_path(xml, "/domain/vcpu"))
        mem = util.get_xml_path(xml, "/domain/memory")
        mem = int(mem) / 1024
        info.append(int(mem))
        info.append(util.get_xml_path(xml, "/domain/devices/interface/mac/@address"))
        nic = util.get_xml_path(xml, "/domain/devices/interface/source/@network")
        if nic is None:
            nic = util.get_xml_path(xml, "/domain/devices/interface/source/@bridge")
        info.append(nic)
        return info
Beispiel #20
0
 def get_target_path():
     try:
         xml = stg.XMLDesc(0)
         return util.get_xml_path(xml, "/pool/target/path")
     except libvirt.libvirtError as e:
         add_error(e, 'libvirt')
         return "error"
Beispiel #21
0
 def get_type():
     try:
         xml = stg.XMLDesc(0)
         return util.get_xml_path(xml, "/pool/@type")
     except libvirt.libvirtError as e:
         add_error(e, "libvirt")
         return "error"
Beispiel #22
0
 def get_vm_vnc():
    try:
       xml = dom.XMLDesc(0)
       vnc = util.get_xml_path(xml, "/domain/devices/graphics/@port")
       return vnc
    except:
       print "Get vnc port failed"
Beispiel #23
0
 def get_vm_uuid():
     try:
         xml = dom.XMLDesc(0)
         uuid = util.get_xml_path(xml, "/domain/uuid")
         return uuid
     except libvirt.libvirtError as e:
         add_error(e, 'libvirt')
         return "error"
Beispiel #24
0
 def get_volume_for_pool(pool_object=None, pool_name=None, conn=None):
     """
     Returns volume class associated with passed pool_object/name
     """
     pool_object = StorageVolume.lookup_pool_by_name(pool_object=pool_object,
                                                     pool_name=pool_name,
                                                     conn=conn)
     return StoragePool.get_volume_for_pool(util.get_xml_path(pool_object.XMLDesc(0), "/pool/@type"))
Beispiel #25
0
 def get_vm_vnc():
     try:
         xml = dom.XMLDesc(0)
         vnc = util.get_xml_path(xml, "/domain/devices/graphics/@port")
         return vnc
     except libvirt.libvirtError as e:
         add_error(e, 'libvirt')
         return "error"
Beispiel #26
0
 def get_vm_core():
     try:
         xml = dom.XMLDesc(0)
         cpu = util.get_xml_path(xml, "/domain/vcpu")
         return cpu
     except libvirt.libvirtError as e:
         add_error(e, 'libvirt')
         return "error"
Beispiel #27
0
 def get_vm_vnc():
    try:
       xml = dom.XMLDesc(0)
       vnc = util.get_xml_path(xml, "/domain/devices/graphics/@port")
       return vnc
    except libvirt.libvirtError as e:
       add_error(e, 'libvirt')
       return "error"
Beispiel #28
0
 def get_vm_boot_menu():
    try:
       xml = dom.XMLDesc(0)
       boot_menu = util.get_xml_path(xml, "/domain/os/bootmenu/@enable")
       return boot_menu
    except libvirt.libvirtError as e:
       add_error(e, 'libvirt')
       return "error"
Beispiel #29
0
	def get_machine():
		try:
			xml = conn.getCapabilities()
			machine = util.get_xml_path(xml,"/capabilities/guest/arch/machine/@canonical")
			return machine
		except libvirt.libvirtError as e:
			add_error(e, 'libvirt')
			return "error"
Beispiel #30
0
 def get_vm_arch():
    try:
       xml = dom.XMLDesc(0)
       arch = util.get_xml_path(xml, "/domain/os/type/@arch")
       return arch
    except libvirt.libvirtError as e:
       add_error(e, 'libvirt')
       return "error"
Beispiel #31
0
 def get_vm_uuid():
    try:
       xml = dom.XMLDesc(0)
       uuid = util.get_xml_path(xml, "/domain/uuid")
       return uuid
    except libvirt.libvirtError as e:
       add_error(e, 'libvirt')
       return "error"
Beispiel #32
0
 def get_vm_core():
    try:
       xml = dom.XMLDesc(0)
       cpu = util.get_xml_path(xml, "/domain/vcpu")
       return cpu
    except libvirt.libvirtError as e:
       add_error(e, 'libvirt')
       return "error"
Beispiel #33
0
 def get_vm_boot_menu():
     try:
         xml = dom.XMLDesc(0)
         boot_menu = util.get_xml_path(xml, "/domain/os/bootmenu/@enable")
         return boot_menu
     except libvirt.libvirtError as e:
         add_error(e, 'libvirt')
         return "error"
Beispiel #34
0
 def get_vm_arch():
     try:
         xml = dom.XMLDesc(0)
         arch = util.get_xml_path(xml, "/domain/os/type/@arch")
         return arch
     except libvirt.libvirtError as e:
         add_error(e, 'libvirt')
         return "error"
Beispiel #35
0
 def get_vm_mem():
     try:
         xml = dom.XMLDesc(0)
         mem = util.get_xml_path(xml, "/domain/currentMemory")
         mem = int(mem) * 1024
         return mem
     except libvirt.libvirtError as e:
         add_error(e, 'libvirt')
         return "error"
Beispiel #36
0
 def get_vm_mem():
    try:
       xml = dom.XMLDesc(0)
       mem = util.get_xml_path(xml, "/domain/currentMemory")
       mem = int(mem) * 1024
       return mem
    except libvirt.libvirtError as e:
       add_error(e, 'libvirt')
       return "error"
Beispiel #37
0
    def vnc_get_port(self, vname):
        """

        Function rever vds snaphots.

        """

        dom = self.conn.lookupByName(vname)
        port = util.get_xml_path(dom.XMLDesc(0), "/domain/devices/graphics/@port")
        return port
Beispiel #38
0
def vds_remove_hdd(conn, dom):
    """

    Function delete vds hdd.

    """

    img = util.get_xml_path(dom.XMLDesc(0), "/domain/devices/disk[1]/source/@file")
    vol = conn.storageVolLookupByPath(img)
    vol.delete(0)
Beispiel #39
0
 def vds_on_cluster(self):
     vname = {}
     host_mem = self.conn.getInfo()[1] * 1048576
     for vm_id in self.conn.listDomainsID():
         vm_id = int(vm_id)
         dom = self.conn.lookupByID(vm_id)
         mem = util.get_xml_path(dom.XMLDesc(0), "/domain/memory")
         mem = int(mem) * 1024
         mem_usage = (mem * 100) / host_mem
         vcpu = util.get_xml_path(dom.XMLDesc(0), "/domain/vcpu")
         vname[dom.name()] = (dom.info()[0], vcpu, mem, mem_usage)
     for vm in self.conn.listDefinedDomains():
         dom = self.conn.lookupByName(vm)
         mem = util.get_xml_path(dom.XMLDesc(0), "/domain/memory")
         mem = int(mem) * 1024
         mem_usage = (mem * 100) / host_mem
         vcpu = util.get_xml_path(dom.XMLDesc(0), "/domain/vcpu")
         vname[dom.name()] = (dom.info()[0], vcpu, mem, mem_usage)
     return vname
Beispiel #40
0
def vds_get_info(dom):
    """

    Function return vds info.

    """

    info = []
    xml = dom.XMLDesc(0)
    info.append(util.get_xml_path(xml, "/domain/vcpu"))
    mem = util.get_xml_path(xml, "/domain/memory")
    mem = int(mem) / 1024
    info.append(int(mem))
    info.append(util.get_xml_path(xml, "/domain/devices/interface/mac/@address"))
    nic = util.get_xml_path(xml, "/domain/devices/interface/source/@network")
    if nic is None:
        nic = util.get_xml_path(xml, "/domain/devices/interface/source/@bridge")
    info.append(nic)
    return info
Beispiel #41
0
    def vds_get_media(self, vname):
        """

        Function return vds media info.

        """

        dom = self.lookupVM(vname)
        xml = dom.XMLDesc(0)
        for num in range(1, 5):
            hdd_dev = util.get_xml_path(xml, "/domain/devices/disk[%s]/@device" % (num))
            if hdd_dev == 'cdrom':
                media = util.get_xml_path(xml, "/domain/devices/disk[%s]/source/@file" % (num))
                if media:
                    vol = self.storageVolPath(media)
                    img = re.sub('.iso', '', vol.name())
                    return img
                else:
                    return None
Beispiel #42
0
def vnc_get_port(conn, vname):
    """

    Function rever vds snaphots.

    """

    dom = conn.lookupByName(vname)
    port = util.get_xml_path(dom.XMLDesc(0), "/domain/devices/graphics/@port")
    return port
Beispiel #43
0
    def storage_get_info(self, storage):
        """

        Function return storage info.

        """

        stg = self.storagePool(storage)
        if stg.info()[3] == 0:
            percent = 0
        else:
            percent = (stg.info()[2] * 100) / stg.info()[1]
        info = stg.info()[1:4]
        info.append(int(percent))
        info.append(stg.isActive())
        xml = stg.XMLDesc(0)
        info.append(util.get_xml_path(xml, "/pool/@type"))
        info.append(util.get_xml_path(xml, "/pool/target/path"))
        return info
Beispiel #44
0
    def vds_remove_hdd(self, vname):
        """

        Function delete vds hdd.

        """

        dom = self.lookupVM(vname)
        img = util.get_xml_path(dom.XMLDesc(0), "/domain/devices/disk[1]/source/@file")
        vol = self.storageVolPath(img)
        vol.delete(0)
Beispiel #45
0
def storage_get_info(storage):
    """

    Function return storage info.

    """

    if storage.info()[3] == 0:
        percent = 0
    else:
        percent = (storage.info()[2] * 100) / storage.info()[1]
    info = storage.info()
    info.append(int(percent))
    info.append(storage.isActive())
    xml = storage.XMLDesc(0)
    info.append(util.get_xml_path(xml, "/pool/@type"))
    info.append(util.get_xml_path(xml, "/pool/target/path"))
    info.append(util.get_xml_path(xml, "/pool/source/device/@path"))
    info.append(util.get_xml_path(xml, "/pool/source/format/@type"))
    return info
Beispiel #46
0
    def __init__(self, name, input_vol):
        if not isinstance(input_vol, libvirt.virStorageVol):
            raise ValueError(_("input_vol must be a virStorageVol"))

        pool = input_vol.storagePoolLookupByVolume()

        # Populate some basic info
        xml  = input_vol.XMLDesc(0)
        typ  = input_vol.info()[0]
        cap  = int(util.get_xml_path(xml, "/volume/capacity"))
        alc  = int(util.get_xml_path(xml, "/volume/allocation"))
        fmt  = util.get_xml_path(xml, "/volume/target/format/@type")

        StorageVolume.__init__(self, name=name, pool=pool,
                               pool_name=pool.name(),
                               allocation=alc, capacity=cap)

        self.input_vol = input_vol
        self._file_type = typ
        self._format = fmt
Beispiel #47
0
 def get_info():
     try:
         info = []
         xml_inf = conn.getSysinfo(0)
         info.append(conn.getHostname())
         info.append(conn.getInfo()[0])
         info.append(conn.getInfo()[2])
         info.append(
             util.get_xml_path(xml_inf, "/sysinfo/processor/entry[6]"))
         return info
     except libvirt.libvirtError as e:
         add_error(e, 'libvirt')
         return "error"
Beispiel #48
0
	def get_img_format(vol):
		try:
			for storage in storages:
				stg = conn.storagePoolLookupByName(storage)
				for img in stg.listVolumes():
					if vol == img:
						vl = stg.storageVolLookupByName(vol)
						xml = vl.XMLDesc(0)
						format = util.get_xml_path(xml, "/volume/target/format/@type")
						return format
		except libvirt.libvirtError as e:
			add_error(e, 'libvirt')
			return "error"
Beispiel #49
0
 def vds_on_host():
     import virtinst.util as util
     host_mem = conn.getInfo()[1] * 1048576
     try:
         vname = {}
         for vm_id in conn.listDomainsID():
             vm_id = int(vm_id)
             dom = conn.lookupByID(vm_id)
             mem = util.get_xml_path(dom.XMLDesc(0), "/domain/memory")
             mem = int(mem) * 1024
             mem_usage = (mem * 100) / host_mem
             vcpu = util.get_xml_path(dom.XMLDesc(0), "/domain/vcpu")
             vname[dom.name()] = (dom.info()[0], vcpu, mem, mem_usage)
         for vm in conn.listDefinedDomains():
             dom = conn.lookupByName(vm)
             mem = util.get_xml_path(dom.XMLDesc(0), "/domain/memory")
             mem = int(mem) * 1024
             mem_usage = (mem * 100) / host_mem
             vcpu = util.get_xml_path(dom.XMLDesc(0), "/domain/vcpu")
             vname[dom.name()] = (dom.info()[0], vcpu, mem, mem_usage)
         return vname
     except libvirtError as e:
         return e.message
Beispiel #50
0
 def get_vm_cdrom():
     try:
         xml = dom.XMLDesc(0)
         cdr_path = util.get_xml_path(
             xml, "/domain/devices/disk[2]/source/@file")
         if cdr_path:
             #image = re.sub('\/.*\/', '', cdr_path)
             size = dom.blockInfo(cdr_path, 0)[0]
             #return image, cdr_path, size
             return cdr_path, cdr_path, size
         else:
             return cdr_path
     except libvirt.libvirtError as e:
         add_error(e, 'libvirt')
         return "error"
Beispiel #51
0
def volumes_get_info(storage):
    """

    Function return volume info.

    """

    volinfo = {}
    for name in storage.listVolumes():
        vol = storage.storageVolLookupByName(name)
        xml = vol.XMLDesc(0)
        size = vol.info()[1]
        format = util.get_xml_path(xml, "/volume/target/format/@type")
        volinfo[name] = size, format
    return volinfo
Beispiel #52
0
def vds_get_media(conn, dom):
    """

    Function return vds media info.

    """

    xml = dom.XMLDesc(0)
    media = util.get_xml_path(xml, "/domain/devices/disk[2]/source/@file")
    if media:
        vol = conn.storageVolLookupByPath(media)
        img = re.sub('.iso', '', vol.name())
        return img
    else:
        return None
Beispiel #53
0
 def get_vl_info(listvol):
     try:
         volinfo = {}
         if stg.isActive() != 0:
             for name in listvol:
                 vol = stg.storageVolLookupByName(name)
                 xml = vol.XMLDesc(0)
                 size = vol.info()[1]
                 format = util.get_xml_path(xml,
                                            "/volume/target/format/@type")
                 volinfo[name] = size, format
         return volinfo
     except libvirt.libvirtError as e:
         add_error(e, 'libvirt')
         return "error"
def _countMACaddr(vms, searchmac):
    if not searchmac:
        return

    def count_cb(ctx):
        c = 0

        for mac in ctx.xpathEval("/domain/devices/interface/mac"):
            macaddr = mac.xpathEval("attribute::address")[0].content
            if macaddr and _compareMAC(searchmac, macaddr) == 0:
                c += 1
        return c

    count = 0
    for vm in vms:
        xml = vm.XMLDesc(0)
        count += util.get_xml_path(xml, func=count_cb)
    return count