added: new method for load json file instead of yaml because of the performance issues

This commit is contained in:
adobdin 2016-06-07 20:03:45 +00:00
parent 286897835c
commit 69643472c2
2 changed files with 21 additions and 3 deletions

View File

@ -19,7 +19,7 @@
main module main module
""" """
import yaml import json
import os import os
import shutil import shutil
import logging import logging
@ -375,9 +375,9 @@ class NodeManager(object):
self.nodes = {} self.nodes = {}
self.fuel_init() self.fuel_init()
if nodes_json: if nodes_json:
self.nodes_json = tools.load_yaml_file(nodes_json) self.nodes_json = tools.load_json_file(nodes_json)
else: else:
self.nodes_json = yaml.load(self.get_nodes_json()) self.nodes_json = json.loads(self.get_nodes_json())
self.nodes_init() self.nodes_init()
# apply soft-filter on all nodes # apply soft-filter on all nodes
for node in self.nodes.values(): for node in self.nodes.values():

View File

@ -26,6 +26,7 @@ import threading
from multiprocessing import Process, Queue, BoundedSemaphore from multiprocessing import Process, Queue, BoundedSemaphore
import subprocess import subprocess
import yaml import yaml
import json
from flock import FLock from flock import FLock
from tempfile import gettempdir from tempfile import gettempdir
from pipes import quote from pipes import quote
@ -172,6 +173,23 @@ def get_dir_structure(rootdir):
return dir return dir
def load_json_file(filename):
"""
Loads json data from file
"""
logger = logging.getLogger(__name__)
try:
with open(filename, 'r') as f:
return json.load(f)
except IOError as e:
logger.critical("I/O error(%s): file: %s; msg: %s" %
(e.errno, e.filename, e.strerror))
sys.exit(1)
except ValueError:
logger.critical("Could not convert data")
sys.exit(1)
def load_yaml_file(filename): def load_yaml_file(filename):
""" """
Loads yaml data from file Loads yaml data from file