From 5a6972d3f11f724859b983bf2a11cf35635632d6 Mon Sep 17 00:00:00 2001 From: Tony Mack Date: Tue, 18 Mar 2008 21:05:07 +0000 Subject: [PATCH] -support multiple plc instances with different configurations. - added load() method to handle updating the config instance with object from a python config file --- qaapi/qa/Config.py | 85 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 64 insertions(+), 21 deletions(-) diff --git a/qaapi/qa/Config.py b/qaapi/qa/Config.py index 0e3c747..570957a 100644 --- a/qaapi/qa/Config.py +++ b/qaapi/qa/Config.py @@ -4,30 +4,47 @@ import sys import re import socket import utils +import copy +from PLCs import PLC, PLCs +from Sites import Site, Sites +from Nodes import Node, Nodes +from Slices import Slice, Slices +from Persons import Person, Persons class Config: path = os.path.dirname(os.path.abspath(__file__)) - tests_path = path + os.sep + 'tests' - node_tests_path = tests_path + os.sep + 'node' - slice_tests_path = tests_path + os.sep + 'slice' + tests_path = path + os.sep + 'tests' + os.sep + node_tests_path = tests_path + os.sep + 'node' + os.sep + slice_tests_path = tests_path + os.sep + 'slice' + os.sep + vserver_scripts_path = path + os.sep + 'vserver' + os.sep + qemu_scripts_path = path + os.sep + 'qemu' + os.sep - def update_api(self): + def update_api(self, plc = None): # Set up API acccess - # Try importing the API shell for direct api access. - # If that fails fall back to using xmlrpm - try: - sys.path.append('/usr/share/plc_api') - from PLC.Shell import Shell - shell = Shell(globals = globals()) + # If plc is specified, find its configuration + # and use its API + if plc is not None: + host, path, port = plc['host'], plc['api_path'], plc['port'] + api_server = "https://%(host)s:%(port)s/%(path)s" % locals() + self.api = xmlrpclib.Server(api_server, allow_none = 1) + self.api_type = 'xmlrpc' + else: + + # Try importing the API shell for direct api access. + # If that fails fall back to using xmlrpm + try: + sys.path.append('/usr/share/plc_api') + from PLC.Shell import Shell + shell = Shell(globals = globals()) - # test it - shell.GetRoles() - self.api = shell - self.api_type = 'direct' - except: - self.api = xmlrpclib.Server('https://%s/PLCAPI/' % self.PLC_API_HOST, allow_none = 1) - self.api_type = 'xmlrpc' + # test it + shell.GetRoles() + self.api = shell + self.api_type = 'direct' + except: + self.api = xmlrpclib.Server('https://%s/PLCAPI/' % self.PLC_API_HOST, allow_none = 1) + self.api_type = 'xmlrpc' def __init__(self, config_file = path+os.sep+'qa_config'): # Load config file @@ -44,10 +61,13 @@ class Config: # try setting hostname and ip self.hostname = socket.gethostname() - (stdout, stderr) = utils.popen("/sbin/ifconfig eth0 | grep 'inet addr'") - inet_addr = re.findall('inet addr:[0-9\.^\w]*', stdout[0])[0] - parts = inet_addr.split(":") - self.ip = parts[1] + try: + (stdout, stderr) = utils.popen("/sbin/ifconfig eth0 | grep 'inet addr'") + inet_addr = re.findall('inet addr:[0-9\.^\w]*', stdout[0])[0] + parts = inet_addr.split(":") + self.ip = parts[1] + except: + self.ip = '127.0.0.1' api_host = self.__dict__.get("PLC_API_HOST",self.ip) self.PLC_API_HOST=api_host @@ -60,3 +80,26 @@ class Config: node_test_files = os.listdir(self.node_tests_path) self.node_test_files = filter(valid_node_test_files, node_test_files) + def load(self, conffile): + + confdata = {} + try: execfile(conffile, confdata) + except: raise + + from Nodes import Nodes + from PLCs import PLCs + loadables = ['plcs', 'sites', 'nodes', 'slices', 'persons'] + config = Config() + for loadable in loadables: + if loadable in confdata and loadable in ['plcs']: + setattr(self, loadable, PLCs(config, confdata[loadable])) + elif loadable in confdata and loadable in ['nodes']: + setattr(self, loadable, Nodes(config, confdata[loadable])) + elif loadable in confdata and loadable in ['sites']: + setattr(self, loadable, Sites(confdata[loadable])) + elif loadable in confdata and loadable in ['slices']: + setattr(self, loadable, Slices(confdata[loadable])) + elif loadable in confdata and loadable in ['persons']: + setattr(self, loadable, Persons(confdata[loadable])) + + -- 2.47.0