+ ret = ''\r
+\r
+ config_file_path = '/tmp/skewmon.cfg'\r
+ configfile = open(config_file_path, 'a+')\r
+ try:\r
+ config = json.load(configfile)\r
+ except BaseException:\r
+ # not a valid json file or empty\r
+ config = {}\r
+\r
+ # initialize config file\r
+ if len(self.skewmon_metrics) == 0:\r
+ config = {}\r
+ json.dump(config, configfile)\r
+ configfile.close()\r
+\r
+ docker_name = 'mn.' + vnf_name\r
+ vnf_container = self.dockercli.containers.get(docker_name)\r
+ key = resource_name + '_' + vnf_container.short_id\r
+ vnf_id = vnf_container.id\r
+\r
+ if action == 'start':\r
+ # add a new vnf to monitor\r
+ config[key] = dict(VNF_NAME=vnf_name,\r
+ VNF_ID=vnf_id,\r
+ VNF_METRIC=resource_name)\r
+ ret = 'adding to skewness monitor: {0} {1} '.format(\r
+ vnf_name, resource_name)\r
+ logging.info(ret)\r
+ elif action == 'stop':\r
+ # remove vnf to monitor\r
+ config.pop(key)\r
+ ret = 'removing from skewness monitor: {0} {1} '.format(\r
+ vnf_name, resource_name)\r
+ logging.info(ret)\r
+\r
+ self.skewmon_metrics = config\r
+ configfile = open(config_file_path, 'w')\r
+ json.dump(config, configfile)\r
+ configfile.close()\r