Exemplo n.º 1
0
 def __read_config(self, device_bdf, offset, size):
     sizes = {8: "Q", 4: "I", 2: "H", 1: "B"}
     pci_config_path = "/sys/bus/pci/devices/{}/config".format(device_bdf)
     v = None
     try:
         fd = os.open(pci_config_path, os.O_RDONLY)
         os.lseek(fd, offset, os.SEEK_SET)
         v = struct.unpack(sizes[size], os.read(fd, size))[0]
     except Exception as e:
         logger.error("read_config: {}".format(e))
     finally:
         return v
Exemplo n.º 2
0
 def __read_config(self, device_bdf, offset, size):
     sizes = {8: "Q", 4: "I", 2: "H", 1: "B"}
     pci_config_path = "/sys/bus/pci/devices/{}/config".format(device_bdf)
     v = None
     try:
         fd = os.open(pci_config_path, os.O_RDONLY)
         os.lseek(fd, offset, os.SEEK_SET)
         v = struct.unpack(sizes[size], os.read(fd, size))[0]
     except Exception as e:
         logger.error("read_config: {}".format(e))
     finally:
         return v
Exemplo n.º 3
0
    def init(self):
        if self.__update_cache:
            for retry in range(3):
                try:
                    self.__cache.update(apt.progress.text.AcquireProgress())
                    break
                except apt.cache.FetchFailedException as e:
                    logger.exception(e)
                    continue
            else:
                logger.error("Failed to update apt cache")

            self.__cache.open(progress=None)
Exemplo n.º 4
0
    def init(self):
        if self.__update_cache:
            for retry in range(3):
                try:
                    self.__cache.update(apt.progress.text.AcquireProgress())
                    break
                except apt.cache.FetchFailedException as e:
                    logger.exception(e)
                    continue
            else:
                logger.error("Failed to update apt cache")

            self.__cache.open(progress=None)
Exemplo n.º 5
0
    def __add_entry(self, entry):
        """
        add single entry in /etc/apt/sources.list
        """
        if entry is None:
            # set to defaut entry
            entry = "deb https://dl.bintray.com/infrasim/deb xenial main"

        if self.__check_if_entry_exists(entry):
            print "{} exists".format(entry)
            return

        source_entry = aptsources.sourceslist.SourceEntry(entry)
        source_list = source_entry.mysplit(entry)
        if (source_list[0] not in ["deb", "deb-src"
                                   ]) or (len(source_list) < 4):
            logger.error("Invalid entry ({}).".format(entry))
            return

        typ = source_list[0]
        uri = None
        distribution = None
        attribute = None
        components = []
        for source in source_list:
            if source in ["deb", "deb-src"]:
                continue
            elif re.search(r'^https?:\/\/\w+', source):
                uri = source
            elif re.search(r'^\[.*\]', source):
                attribute = source
            elif source in ["trusty", "xenial"]:
                distribution = source
            else:
                components.append(source)

        if uri is None or distribution is None:
            return

        if attribute:
            uri = " ".join([attribute, uri])
        sources_list = aptsources.sourceslist.SourcesList()
        sources_list.backup(".orig")
        logger.info("adding source list entry: {} {} {} {}".format(
            typ, uri, distribution, " ".join(components)))
        sources_list.add(typ, uri, distribution, components)
        sources_list.save()
Exemplo n.º 6
0
    def __add_entry(self, entry):
        """
        add single entry in /etc/apt/sources.list
        """
        if entry is None:
            # set to defaut entry
            entry = "deb https://dl.bintray.com/infrasim/deb xenial main"

        if self.__check_if_entry_exists(entry):
            print "{} exists".format(entry)
            return

        source_entry = aptsources.sourceslist.SourceEntry(entry)
        source_list = source_entry.mysplit(entry)
        if (source_list[0] not in ["deb", "deb-src"]) or (len(source_list) < 4):
            logger.error("Invalid entry ({}).".format(entry))
            return

        typ = source_list[0]
        uri = None
        distribution = None
        attribute = None
        components = []
        for source in source_list:
            if source in ["deb", "deb-src"]:
                continue
            elif re.search(r'^https?:\/\/\w+', source):
                uri = source
            elif re.search(r'^\[.*\]', source):
                attribute = source
            elif source in ["trusty", "xenial"]:
                distribution = source
            else:
                components.append(source)

        if uri is None or distribution is None:
            return

        if attribute:
            uri = " ".join([attribute, uri])
        sources_list = aptsources.sourceslist.SourcesList()
        sources_list.backup(".orig")
        logger.info("adding source list entry: {} {} {} {}".format(typ, uri, distribution, " ".join(components)))
        sources_list.add(typ, uri, distribution, components)
        sources_list.save()