def _WriteConfig(self, destination=None, releaselock=False):
    if destination is None:
      destination = self._cfg_file

    # Save the configuration data. If offline, write the file directly.
    # If online, call WConfd.
    if self._offline:
      self._BumpSerialNo()
      txt = serializer.DumpJson(
        self._ConfigData().ToDict(_with_private=True),
        private_encoder=serializer.EncodeWithPrivateFields
      )

      getents = self._getents()
      try:
        fd = utils.SafeWriteFile(destination, self._cfg_id, data=txt,
                                 close=False, gid=getents.confd_gid, mode=0640)
      except errors.LockError:
        raise errors.ConfigurationError("The configuration file has been"
                                        " modified since the last write, cannot"
                                        " update")
      try:
        self._cfg_id = utils.GetFileID(fd=fd)
      finally:
        os.close(fd)
    else:
      try:
        if releaselock:
          res = self._wconfd.WriteConfigAndUnlock(self._GetWConfdContext(),
                                                  self._ConfigData().ToDict())
          if not res:
            logging.warning("WriteConfigAndUnlock indicates we already have"
                            " released the lock; assuming this was just a retry"
                            " and the initial call succeeded")
        else:
          self._wconfd.WriteConfig(self._GetWConfdContext(),
                                   self._ConfigData().ToDict())
      except errors.LockError:
        raise errors.ConfigurationError("The configuration file has been"
                                        " modified since the last write, cannot"
                                        " update")

    self.write_count += 1
Write the configuration data to persistent storage.
dataset/ETHPy150Open ganeti/ganeti/lib/config/__init__.py/ConfigWriter._WriteConfig