Revision 93384844

b/lib/backend.py
45 45

  
46 46

  
47 47
def _GetConfig():
48
  """Simple wrapper to return a ConfigReader.
48
  """Simple wrapper to return a SimpleStore.
49 49

  
50
  @rtype: L{ssconf.SimpleConfigReader}
51
  @return: a SimpleConfigReader instance
50
  @rtype: L{ssconf.SimpleStore}
51
  @return: a SimpleStore instance
52 52

  
53 53
  """
54
  return ssconf.SimpleConfigReader()
54
  return ssconf.SimpleStore()
55 55

  
56 56

  
57 57
def _GetSshRunner(cluster_name):
b/lib/constants.py
379 379
MAX_NICS = 8
380 380
MAX_DISKS = 16
381 381

  
382
# SSCONF keys
383
SS_CLUSTER_NAME = "cluster_name"
384
SS_FILE_STORAGE_DIR = "file_storage_dir"
385
SS_MASTER_IP = "master_ip"
386
SS_MASTER_NETDEV = "master_netdev"
387
SS_MASTER_NODE = "master_node"
388
SS_NODE_LIST = "node_list"
389

  
382 390
# cluster wide default parameters
383 391
DEFAULT_ENABLED_HYPERVISOR = HT_XEN_PVM
384 392

  
b/lib/ssconf.py
112 112
                    mode=0600)
113 113

  
114 114

  
115
class SimpleStore(object):
116
  """Interface to static cluster data.
117

  
118
  This is different that the config.ConfigWriter and
119
  SimpleConfigReader classes in that it holds data that will always be
120
  present, even on nodes which don't have all the cluster data.
121

  
122
  Other particularities of the datastore:
123
    - keys are restricted to predefined values
124

  
125
  """
126
  _SS_FILEPREFIX = "ssconf_"
127
  _VALID_KEYS = (
128
    constants.SS_CLUSTER_NAME,
129
    constants.SS_FILE_STORAGE_DIR,
130
    constants.SS_MASTER_IP,
131
    constants.SS_MASTER_NETDEV,
132
    constants.SS_MASTER_NODE,
133
    constants.SS_NODE_LIST,
134
    )
135
  _MAX_SIZE = 131072
136

  
137
  def __init__(self, cfg_location=None):
138
    if cfg_location is None:
139
      self._cfg_dir = constants.DATA_DIR
140
    else:
141
      self._cfg_dir = cfg_location
142

  
143
  def KeyToFilename(self, key):
144
    """Convert a given key into filename.
145

  
146
    """
147
    if key not in self._VALID_KEYS:
148
      raise errors.ProgrammerError("Invalid key requested from SSConf: '%s'"
149
                                   % str(key))
150

  
151
    filename = self._cfg_dir + '/' + self._SS_FILEPREFIX + key
152
    return filename
153

  
154
  def _ReadFile(self, key):
155
    """Generic routine to read keys.
156

  
157
    This will read the file which holds the value requested. Errors
158
    will be changed into ConfigurationErrors.
159

  
160
    """
161
    filename = self.KeyToFilename(key)
162
    try:
163
      fh = file(filename, 'r')
164
      try:
165
        data = fh.read(self._MAX_SIZE)
166
        data = data.rstrip('\n')
167
      finally:
168
        fh.close()
169
    except EnvironmentError, err:
170
      raise errors.ConfigurationError("Can't read from the ssconf file:"
171
                                      " '%s'" % str(err))
172
    return data
173

  
174
  def GetFileList(self):
175
    """Return the list of all config files.
176

  
177
    This is used for computing node replication data.
178

  
179
    """
180
    return [self.KeyToFilename(key) for key in self._VALID_KEYS]
181

  
182
  def GetClusterName(self):
183
    """Get the cluster name.
184

  
185
    """
186
    return self._ReadFile(constants.SS_CLUSTER_NAME)
187

  
188
  def GetFileStorageDir(self):
189
    """Get the file storage dir.
190

  
191
    """
192
    return self._ReadFile(constants.SS_FILE_STORAGE_DIR)
193

  
194
  def GetMasterIP(self):
195
    """Get the IP of the master node for this cluster.
196

  
197
    """
198
    return self._ReadFile(constants.SS_MASTER_IP)
199

  
200
  def GetMasterNetdev(self):
201
    """Get the netdev to which we'll add the master ip.
202

  
203
    """
204
    return self._ReadFile(constants.SS_MASTER_NETDEV)
205

  
206
  def GetMasterNode(self):
207
    """Get the hostname of the master node for this cluster.
208

  
209
    """
210
    return self._ReadFile(constants.SS_MASTER_NODE)
211

  
212
  def GetNodeList(self):
213
    """Return the list of cluster nodes.
214

  
215
    """
216
    data = self._ReadFile(constants.SS_NODE_LIST)
217
    nl = data.splitlines(False)
218
    return nl
219

  
220

  
115 221
def _SsconfPath(name):
116 222
  if not RE_VALID_SSCONF_NAME.match(name):
117 223
    raise errors.ParameterError("Invalid ssconf name: %s" % name)
......
150 256

  
151 257
  """
152 258
  if ss is None:
153
    ss = SimpleConfigReader()
259
    ss = SimpleStore()
154 260
  return ss.GetMasterNode(), utils.HostInfo().name
155 261

  
156 262

  

Also available in: Unified diff