예제 #1
0
파일: vm.py 프로젝트: bellle/lago
    def extract_paths_dead(self, paths, ignore_nopath):
        """
        Extract the given paths from the domain using guestfs.
        Using guestfs can have side-effects and should be used as a second
        option, mainly when SSH is not available.

        Args:
            paths(list of str): paths to extract
            ignore_nopath(boolean): if True will ignore none existing paths.

        Returns:
            None

        Raises:
            :exc:`~lago.utils.LagoException`: if :mod:`guestfs` is not
                importable.
            :exc:`~lago.plugins.vm.ExtractPathNoPathError`: if a none existing
                path was found on the VM, and `ignore_nopath` is True.
            :exc:`~lago.plugins.vm.ExtractPathError`: on failure extracting
                the files.
        """
        if not self._has_guestfs:
            raise LagoException(('guestfs module not available, cannot '
                                 )('extract files with libguestfs'))

        LOGGER.debug('%s: attempting to extract files with libguestfs',
                     self.vm.name())
        guestfs_tools.extract_paths(
            disk_path=self.vm.spec['disks'][0]['path'],
            disk_root=self.vm.spec['disks'][0]['metadata'].get(
                'root-partition', 'root'),
            paths=paths,
            ignore_nopath=ignore_nopath)
예제 #2
0
파일: cpu.py 프로젝트: tinez/lago
    def get_cpus_by_arch(cls, arch):
        """
        Get all CPUs info by arch

        Args:
            arch(str): CPU architecture

        Returns:
            lxml.etree.element: CPUs by arch XML

        Raises:
            :exc:`~LagoException`: If no such ARCH is found
        """

        cpu_map_xml = "/usr/share/libvirt/cpu_map.xml"
        cpu_map_dir = "/usr/share/libvirt/cpu_map/"
        cpu_map_index_xml = cpu_map_dir + "index.xml"
        if not os.path.exists(cpu_map_xml):
            cpu_xml = ET.ElementTree(
                ET.fromstring(create_xml_map(cpu_map_index_xml, cpu_map_dir)))
        else:
            with open(cpu_map_xml, 'r') as cpu_map:
                cpu_xml = ET.parse(cpu_map)
        try:
            return cpu_xml.xpath('/cpus/arch[@name="{0}"]'.format(arch))[0]
        except IndexError:
            raise LagoException('No such arch: {0}'.format(arch))
예제 #3
0
    def get_cpus_by_arch(cls, arch):
        """
        Get all CPUs info by arch

        Args:
            arch(str): CPU architecture

        Returns:
            lxml.etree.element: CPUs by arch XML

        Raises:
            :exc:`~LagoException`: If no such ARCH is found
        """

        with open('/usr/share/libvirt/cpu_map.xml', 'r') as cpu_map:
            cpu_xml = ET.parse(cpu_map)
        try:
            return cpu_xml.xpath('/cpus/arch[@name="{0}"]'.format(arch))[0]
        except IndexError:
            raise LagoException('No such arch: {0}'.format(arch))
예제 #4
0
    def get_cpu_props(cls, family, arch='x86'):
        """
        Get CPU info XML

        Args:
            family(str): CPU family
            arch(str): CPU arch

        Returns:
            lxml.etree.Element: CPU xml

        Raises:
            :exc:`~LagoException`: If no such CPU family exists
        """

        cpus = cls.get_cpus_by_arch(arch)
        try:
            return cpus.xpath('model[@name="{0}"]'.format(family))[0]
        except IndexError:
            raise LagoException('No such CPU family: {0}'.format(family))