in ansible/roles/slurm/files/scripts/util.py [0:0]
def template_info(self, template_link, project=None):
project = project or self.project
template_name = trim_self_link(template_link)
# split read and write access to minimize write-lock. This might be a
# bit slower? TODO measure
if self.template_cache_path.exists():
with self.template_cache() 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
machine_info = self.machine_type(template.machineType, project=project)
if machine_info.accelerators:
template.gpu_type = machine_info.accelerators[0].guestAcceleratorType
template.gpu_count = machine_info.accelerators[0].guestAcceleratorCount
elif 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 self.template_cache(writeback=True) as cache:
cache[template_name] = template.to_dict()
# cache should be owned by slurm
chown_slurm(self.template_cache_path)
return template