Revision 856c67e1 lib/ssconf.py

b/lib/ssconf.py
1 1
#
2 2
#
3 3

  
4
# Copyright (C) 2006, 2007 Google Inc.
4
# Copyright (C) 2006, 2007, 2008 Google Inc.
5 5
#
6 6
# This program is free software; you can redistribute it and/or modify
7 7
# it under the terms of the GNU General Public License as published by
......
32 32
from ganeti import errors
33 33
from ganeti import constants
34 34
from ganeti import utils
35
from ganeti import serializer
35 36

  
36 37

  
37 38
class SimpleStore:
......
201 202
                    uid=0, gid=0, mode=0400)
202 203

  
203 204

  
205
class SimpleConfigReader:
206
  """Simple class to read configuration file.
207

  
208
  """
209
  def __init__(self, file_name=constants.CLUSTER_CONF_FILE):
210
    """Initializes this class.
211

  
212
    @type file_name: string
213
    @param file_name: Configuration file path
214

  
215
    """
216
    self._file_name = file_name
217
    self._config_data = serializer.Load(utils.ReadFile(file_name))
218
    # TODO: Error handling
219

  
220
  def GetClusterName(self):
221
    return self._config_data["cluster"]["cluster_name"]
222

  
223
  def GetHostKey(self):
224
    return self._config_data["cluster"]["rsahostkeypub"]
225

  
226
  def GetMasterNode(self):
227
    return self._config_data["cluster"]["master_node"]
228

  
229
  def GetMasterIP(self):
230
    return self._config_data["cluster"]["master_ip"]
231

  
232
  def GetMasterNetdev(self):
233
    return self._config_data["cluster"]["master_netdev"]
234

  
235
  def GetFileStorageDir(self):
236
    return self._config_data["cluster"]["file_storage_dir"]
237

  
238
  def GetHypervisorType(self):
239
    return self._config_data["cluster"]["hypervisor"]
240

  
241
  def GetNodeList(self):
242
    return self._config_data["nodes"].keys()
243

  
244

  
245
class SimpleConfigWriter(SimpleConfigReader):
246
  """Simple class to write configuration file.
247

  
248
  """
249
  def SetMasterNode(self, node):
250
    """Change master node.
251

  
252
    """
253
    self._config_data["cluster"]["master_node"] = node
254

  
255
  def Save(self):
256
    """Writes configuration file.
257

  
258
    Warning: Doesn't take care of locking or synchronizing with other
259
    processes.
260

  
261
    """
262
    utils.WriteFile(self._file_name,
263
                    data=serializer.Dump(self._config_data),
264
                    mode=0600)
265

  
266

  
204 267
def GetMasterAndMyself(ss=None):
205 268
  """Get the master node and my own hostname.
206 269

  

Also available in: Unified diff