Commit b9a6a071 authored by Antoine Millet's avatar Antoine Millet
Browse files

Added hkvmver and hkvmsetup tags

parent dcc18468
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ Just define a string or a function and it will be introspected and used as a
tag value.
"""
import re
import time
import datetime
import os as os_
import platform as platform_
from multiprocessing import cpu_count
@@ -207,3 +209,17 @@ def load():

def plugins(handler):
    return ' '.join(handler.plugins) or None


# HKVM related tags
def hkvmver():
    """HKVM version."""
    fields = dict(x.split(': ', 1) for x in open('/etc/isimage').read().split('\n') if x.strip())
    return int(fields['image version'])


def hkvmsetup():
    """HKVM setup date."""
    fields = dict(x.split(': ', 1) for x in open('/etc/isimage').read().split('\n') if x.strip())
    setup_date = datetime.datetime.strptime(fields['setup date'], '%a, %d %b %Y %H:%M:%S +0000')
    return int(time.mktime(setup_date.timetuple()))