import json
import yaml
+# We need to convert human readable sizes to INT in GB
+# we always round to 1GB (if puppet shows less than that)
+# we should always check with client documentation and make
+# sure proper sizes are set manually if incorrect
+# this is to make sure we do not have that much false positives
+UNITS = { "KiB": 1048576, "MiB": 1024, "GiB": 1}
+def readHumanReadable(filesize):
+ for key in UNITS.keys():
+ if key.lower() in filesize.lower():
+ return str(math.ceil(float(filesize.split(" ")[0]) / float(UNITS[key])))
+
# This is for debugging purposes, it helps track the HTTP requests'
# input and ouput and detect errors along the way. Better leave it here
# for debuggin purposes. The script will later be fixed so that debug mode
}
try:
- print(f"OS according to facts: {data['os']['value']['name']} {data['os']['value']['release']['full']}\n")
+ print(f"OS according to facts: {data['os']['value']['name']} {data['os']['value']['release']['full']}")
+ print(f"Memory according to facts: {data['memorysize']['value']}\n")
# Options resolv.conf
try:
sample_pre_tf["defaults"]["num_cpus"] = data["processorcount"]["value"]
# Memory
- sample_pre_tf["defaults"]["memory"] = str(math.ceil(float(data["memorysize"]["value"].split(" ")[0]))) + "GB"
+ sample_pre_tf["defaults"]["memory"] = readHumanReadable(data["memorysize"]["value"]) + "GB"
# Customer
sample_pre_tf["defaults"]["puppet"]["customer"] = data["customer"]["value"]