diff --git a/cloudcontrol/node/host/tags.py b/cloudcontrol/node/host/tags.py index e4749e52bc4f5372e3db2d14520038357351b8a4..b88e5a16a04eff7bb5e111a532425b14cc41db6c 100644 --- a/cloudcontrol/node/host/tags.py +++ b/cloudcontrol/node/host/tags.py @@ -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()))