Revision 25cf4130

b/lib/config.py
46 46
from ganeti import utils
47 47
from ganeti import constants
48 48
import ganeti.rpc.node as rpc
49
import ganeti.wconfd as wc
49 50
from ganeti import objects
50 51
from ganeti import serializer
51 52
from ganeti import uidpool
......
202 203
    self._last_cluster_serial = -1
203 204
    self._cfg_id = None
204 205
    self._context = None
206
    self._wconfd = None
205 207
    self._OpenConfig(accept_foreign)
206 208

  
207 209
  def _GetRpc(self, address_list):
......
2355 2357
    """Read the config data from disk.
2356 2358

  
2357 2359
    """
2358
    raw_data = utils.ReadFile(self._cfg_file)
2360
    # Read the configuration data. If offline, read the file directly.
2361
    # If online, call WConfd.
2362
    if self._offline:
2363
      raw_data = utils.ReadFile(self._cfg_file)
2364
      try:
2365
        dict_data = serializer.Load(raw_data)
2366
      except Exception, err:
2367
        raise errors.ConfigurationError(err)
2368
    else:
2369
      self._wconfd = wc.Client()
2370
      dict_data = self._wconfd.ReadConfig()
2359 2371

  
2360 2372
    try:
2361
      data = objects.ConfigData.FromDict(serializer.Load(raw_data))
2373
      data = objects.ConfigData.FromDict(dict_data)
2362 2374
    except Exception, err:
2363 2375
      raise errors.ConfigurationError(err)
2364 2376

  
......
2508 2520

  
2509 2521
    if destination is None:
2510 2522
      destination = self._cfg_file
2523

  
2511 2524
    self._BumpSerialNo()
2512
    txt = serializer.DumpJson(
2513
      self._config_data.ToDict(_with_private=True),
2514
      private_encoder=serializer.EncodeWithPrivateFields
2515
    )
2525
    # Save the configuration data. If offline, write the file directly.
2526
    # If online, call WConfd.
2527
    if self._offline:
2528
      txt = serializer.DumpJson(
2529
        self._config_data.ToDict(_with_private=True),
2530
        private_encoder=serializer.EncodeWithPrivateFields
2531
      )
2516 2532

  
2517
    getents = self._getents()
2518
    try:
2519
      fd = utils.SafeWriteFile(destination, self._cfg_id, data=txt,
2520
                               close=False, gid=getents.confd_gid, mode=0640)
2521
    except errors.LockError:
2522
      raise errors.ConfigurationError("The configuration file has been"
2523
                                      " modified since the last write, cannot"
2524
                                      " update")
2525
    try:
2526
      self._cfg_id = utils.GetFileID(fd=fd)
2527
    finally:
2528
      os.close(fd)
2533
      getents = self._getents()
2534
      try:
2535
        fd = utils.SafeWriteFile(destination, self._cfg_id, data=txt,
2536
                                 close=False, gid=getents.confd_gid, mode=0640)
2537
      except errors.LockError:
2538
        raise errors.ConfigurationError("The configuration file has been"
2539
                                        " modified since the last write, cannot"
2540
                                        " update")
2541
      try:
2542
        self._cfg_id = utils.GetFileID(fd=fd)
2543
      finally:
2544
        os.close(fd)
2545
    else:
2546
      try:
2547
        self._wconfd.WriteConfig(self._config_data.ToDict())
2548
      except errors.LockError:
2549
        raise errors.ConfigurationError("The configuration file has been"
2550
                                        " modified since the last write, cannot"
2551
                                        " update")
2529 2552

  
2530 2553
    self.write_count += 1
2531 2554

  

Also available in: Unified diff