Commit ec91e24f by Gregory Nagy

pep8 conventions

parent 3faa2b8f
import ConfigParser as configparser import sys
if sys.version_info < (3, 0):
import ConfigParser as configparser
else:
import configparser
def importConf(path_to_file): def import_conf(path_to_file):
config = configparser.RawConfigParser(allow_no_value=False) config = configparser.RawConfigParser(allow_no_value=False)
try: try:
config.read(path_to_file) config.read(path_to_file)
params = {} params = {}
metrics = {} metrics = {}
params["debugMode"] = config.get("Client", "Debug") params["debugMode"] = config.get("Client", "Debug")
##
## Metrics
##
metrics["cpu.usage"] = int(config.get("Metrics", "cpuUsage")) metrics["cpu.usage"] = int(config.get("Metrics", "cpuUsage"))
metrics["cpu.times"] = int(config.get("Metrics", "cpuTimes")) metrics["cpu.times"] = int(config.get("Metrics", "cpuTimes"))
metrics["memory.usage"] = int(config.get("Metrics", "memoryUsage")) metrics["memory.usage"] = int(config.get("Metrics", "memoryUsage"))
...@@ -16,17 +23,23 @@ def importConf(path_to_file): ...@@ -16,17 +23,23 @@ def importConf(path_to_file):
metrics["system.boot_time"] = int(config.get("Metrics", metrics["system.boot_time"] = int(config.get("Metrics",
"systemBootTime")) "systemBootTime"))
metrics["network"] = int(config.get("Metrics", "dataTraffic")) metrics["network"] = int(config.get("Metrics", "dataTraffic"))
##
## Params
##
params["kvmCpuUsage"] = int(config.get("KVM", "cpuUsage")) params["kvmCpuUsage"] = int(config.get("KVM", "cpuUsage"))
params["kvmMemoryUsage"] = int(config.get("KVM", "memoryUsage")) params["kvmMemoryUsage"] = int(config.get("KVM", "memoryUsage"))
params["kvmNetworkUsage"] = int(config.get("KVM", "networkUsage")) params["kvmNetworkUsage"] = int(config.get("KVM", "networkUsage"))
except configparser.NoSectionError: except configparser.NoSectionError:
print("Config file contains error! Reason: Missing section.") print("[ERROR] Config file contains error! "
"Reason: Missing section.")
raise raise
except configparser.ParsingError: except configparser.ParsingError:
print("Config file contains error! Reason: Cannot parse.") print("[ERROR] Config file contains error! "
"Reason: Cannot parse.")
raise raise
except configparser.MissingSectionHeaderError: except configparser.MissingSectionHeaderError:
print("Config file contains error! Reason: Missing section-header.") print("[ERROR] Config file contains error! "
"Reason: Missing section-header.")
raise raise
return params, metrics return params, metrics
...@@ -18,20 +18,19 @@ class collectables: ...@@ -18,20 +18,19 @@ class collectables:
} }
@staticmethod @staticmethod
def listKeys(): def list_keys():
return list(collectables.__collectables.keys()) return list(collectables.__collectables.keys())
@staticmethod @staticmethod
def listMetricsToKey(key): def list_metrics_to_key(key):
return collectables.__collectables[key] return collectables.__collectables[key]
@staticmethod @staticmethod
def listMetricsNameToKey(key): def list_metrics_name_to_key(key):
return [x.name for x in collectables.__collectables[key]] return [x.name for x in collectables.__collectables[key]]
@staticmethod @staticmethod
def provide(requests=[]): def provide(requests=[]):
#valid_keys = collectables.listKeys()
reqs = [] reqs = []
for requests, value in requests.items(): for requests, value in requests.items():
if value > 0: if value > 0:
...@@ -44,4 +43,4 @@ class collectables: ...@@ -44,4 +43,4 @@ class collectables:
@staticmethod @staticmethod
def provideAll(): def provideAll():
return collectables.provide(collectables.listKeys()) return collectables.provide(collectables.list_keys())
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment