Пример #1
0
    def _get_template_info(self, template_link, project):
        template_name = template_link.split("/")[-1]

        # split read and write access to minimize write-lock. This might be a
        # bit slower? TODO measure
        if self.template_cache_path.exists():
            with shelve.open(str(self.template_cache_path), flag="r") as cache:
                if template_name in cache:
                    return NSDict(cache[template_name])

        template = ensure_execute(
            self.compute.instanceTemplates().get(
                project=project, instanceTemplate=template_name
            )
        ).get("properties")
        template = NSDict(template)
        # name and link are not in properties, so stick them in
        template.name = template_name
        template.link = template_link
        # TODO delete metadata to reduce memory footprint?
        # del template.metadata

        # translate gpus into an easier-to-read format
        if template.guestAccelerators:
            template.gpu_type = template.guestAccelerators[0].acceleratorType
            template.gpu_count = template.guestAccelerators[0].acceleratorCount
        else:
            template.gpu_type = None
            template.gpu_count = 0

        # keep write access open for minimum time
        with shelve.open(str(self.template_cache_path), writeback=True) as cache:
            cache[template_name] = template.to_dict()

        return template
Пример #2
0
 def by_version(self, version: str, alt={}):
     """ Get the data by version. """
     self.check()
     query = self.setup_query(alt)
     current_settings = ADict()
     self.processor.storage.query(query, **current_settings.to_dict())
     self.changed_since_command = False
Пример #3
0
 def last(self, alt={}):
     self.check()
     query = self.setup_query(alt)
     current_settings = ADict()
     self.changed_since_command = False
     obj = self.processor.storage.query(query, **current_settings.to_dict())
     return obj
Пример #4
0
 def save(self, data: dict, alt={}, is_overwrite=False):
     self.check()
     query = self.setup_query(alt)
     # Put settings here
     current_settings = ADict()
     current_settings.overwrite = is_overwrite
     self.processor.storage.save(query, data, **current_settings.to_dict())
     self.changed_since_command = False
Пример #5
0
 def absolute_exists(self, alt={}):
     self.check()
     query = self.setup_query(alt)
     # Put settings here
     current_settings = ADict()
     current_settings.is_force = self.changed_since_command
     avs = self.processor.storage.absolute_exists(
         query, **current_settings.to_dict())
     self.changed_since_command = False
     return avs