cnfparse.py 1.23 KB
Newer Older
1
import ConfigParser as configparser
2

3

4
def importConf(path_to_file):
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
	config = configparser.RawConfigParser(allow_no_value=False)
	try:
		config.read(path_to_file)
		params = {}
		metrics = {}
		params["debugMode"] = config.get("Client", "Debug")
		metrics["cpu.usage"] = int(config.get("Metrics", "cpuUsage"))
		metrics["memory.usage"] = int(config.get("Metrics", "memoryUsage"))
		metrics["user.count"] = int(config.get("Metrics", "userCount"))
		metrics["swap.usage"] = int(config.get("Metrics", "swapUsage"))
		metrics["system.boot_time"] = int(config.get("Metrics",
		                                             "systemBootTime"))
		metrics["network"] = int(config.get("Metrics", "dataTraffic"))
		params["kvmCpuUsage"] = int(config.get("KVM", "cpuUsage"))
		params["kvmMemoryUsage"] = int(config.get("KVM", "memoryUsage"))
20
		params["kvmNetworkUsage"] = int(config.get("KVM", "networkUsage"))
21 22 23 24 25 26 27 28 29
	except configparser.NoSectionError:
		print("Config file contains error! Reason: Missing section.")
		raise
	except configparser.ParsingError:
		print("Config file contains error! Reason: Cannot parse.")
		raise
	except configparser.MissingSectionHeaderError:
		print("Config file contains error! Reason: Missing section-header.")
		raise
30

31
	return params, metrics