Module serverconf
[hide private]
[frames] | no frames]

Source Code for Module serverconf

  1  # -*- coding: utf-8 -*-
 
  2  
 
  3  ############################################################################
 
  4  # serverconf.py
 
  5  #
 
  6  # Main application server configuration class for MOCOP.
 
  7  #
 
  8  # (C) 2008 Likya Software Ltd.
 
  9  ############################################################################
 
 10  
 
 11  import os, sys, time 
 12  
 
 13  from ConfigParser import SafeConfigParser 
 14  from constants import Constants 
 15  
 
16 -class ServerConf(object):
17 ''' 18 The configuration of the application server. 19 '''
20 - def __init__(self, server):
21 self._server = server 22 self._name = None 23 self._numberOfWorkers = Constants.DEFAULT_NUMBER_OF_WORKERS 24 self._password = None 25 self._isMaster = None 26 self._masterAddress = 'localhost' 27 self._masterListeningPort = 0 28 self._serverList = []
29
30 - def load(self):
31 ''' 32 Reload the configuration from the conf file 33 ''' 34 try: 35 confParser = SafeConfigParser() 36 37 # Read the conf file for the server name 38 confParser.read(os.path.join(self._server.directory(), Constants.SERVER_CONF_FILE)) 39 for section in confParser.sections(): 40 for option in confParser.options(section): 41 if option == 'name': 42 self.setName(confParser.get(section, option)) 43 if option == 'workers': 44 self.setNumberOfWorkers(confParser.get(section, option)) 45 46 confParser = SafeConfigParser() 47 48 # Read all the servers info file 49 confParser.read(os.path.join(self._server.directory(), Constants.SERVER_LIST_CONF_FILE)) 50 for section in confParser.sections(): 51 if section == self.name(): 52 for option in confParser.options(section): 53 if option == 'password': 54 self.setPassword(confParser.get(section, option)) 55 elif option == 'master': 56 self.setIsMaster(confParser.get(section, option) == 'True') 57 elif option == 'masteraddress': 58 self.setMasterAddress(confParser.get(section, option)) 59 elif option == 'masterlisteningport': 60 self.setMasterListeningPort(confParser.get(section, option)) 61 self._serverList.append((section, confParser.get(section, 'password'))) 62 63 except Exception, e: 64 print 'ERROR: Error in ServerConf.load():', e 65 sys.exit(1)
66
67 - def server(self):
68 ''' 69 Returns the application server. 70 ''' 71 return self._server
72
73 - def serverList(self):
74 ''' 75 Returns the application server list. 76 ''' 77 return self._serverList
78
79 - def name(self):
80 ''' 81 Returns the name of the server 82 ''' 83 return self._name
84
85 - def setName(self, name):
86 ''' 87 Sets the name of the server 88 ''' 89 self._name = name
90
91 - def numberOfWorkers(self):
92 ''' 93 Returns the number of workers 94 ''' 95 return self._numberOfWorkers
96
97 - def setNumberOfWorkers(self, workers):
98 ''' 99 Sets the number of workers 100 ''' 101 self._numberOfWorkers = int(workers)
102
103 - def password(self):
104 ''' 105 Returns the password of the server to connect to the master server 106 ''' 107 return self._password
108
109 - def setPassword(self, password):
110 ''' 111 Sets the password of the server to connect to the master server 112 ''' 113 self._password = password
114
115 - def isMaster(self):
116 ''' 117 Returns if the server is master. 118 ''' 119 return self._isMaster
120
121 - def setIsMaster(self, isMaster):
122 ''' 123 Sets is the server is master 124 ''' 125 self._isMaster = isMaster
126
127 - def masterAddress(self):
128 ''' 129 Returns the master server address 130 ''' 131 return self._masterAddress
132
133 - def setMasterAddress(self, masterAddress):
134 ''' 135 Sets is the server is master 136 ''' 137 self._masterAddress = masterAddress
138
139 - def masterListeningPort(self):
140 ''' 141 Returns the master server listening port 142 ''' 143 return int(self._masterListeningPort)
144
145 - def setMasterListeningPort(self, masterListeningPort):
146 ''' 147 Sets is the server is master 148 ''' 149 self._masterListeningPort = masterListeningPort
150