Config modifications are now done using
wconfd RPCs.

Added wrappers CommitTemporaryIps, and VerifyConfigAndLog
to perform read only config operations with lock.

Signed-off-by: BSRK Aditya <[email protected]>
---
 lib/config/__init__.py | 58 +++++++++++++++++++-------------------------------
 1 file changed, 22 insertions(+), 36 deletions(-)

diff --git a/lib/config/__init__.py b/lib/config/__init__.py
index cc6efe7..f0f8e8a 100644
--- a/lib/config/__init__.py
+++ b/lib/config/__init__.py
@@ -668,6 +668,11 @@ class ConfigWriter(object):
     """
     self._wconfd.ReserveMAC(self._GetWConfdContext(), mac)
 
+  @ConfigSync(shared=1)
+  def CommitTemporaryIps(self, _ec_id):
+    """A simple wrapper around L{_UnlockedCommitTemporaryIps}"""
+    self._UnlockedCommitTemporaryIps(_ec_id)
+
   def _UnlockedCommitTemporaryIps(self, _ec_id):
     """Commit all reserved IP address to their respective pools
 
@@ -1092,6 +1097,11 @@ class ConfigWriter(object):
 
     return result
 
+  @ConfigSync(shared=1)
+  def VerifyConfigAndLog(self, feedback_fn=None):
+    """A simple wrapper around L{_UnlockedVerifyConfigAndLog}"""
+    return self._UnlockedVerifyConfigAndLog(feedback_fn=feedback_fn)
+
   def _UnlockedVerifyConfigAndLog(self, feedback_fn=None):
     """Verify the configuration and log any errors.
 
@@ -3102,7 +3112,6 @@ class ConfigWriter(object):
     """
     return DetachedConfig(self._ConfigData())
 
-  @ConfigSync()
   def Update(self, target, feedback_fn, ec_id=None):
     """Notify function to be called after updates.
 
@@ -3118,60 +3127,37 @@ class ConfigWriter(object):
     @param feedback_fn: Callable feedback function
 
     """
-    if self._ConfigData() is None:
-      raise errors.ProgrammerError("Configuration file not read,"
-                                   " cannot save.")
 
-    def check_serial(target, current):
-      if current is None:
-        raise errors.ConfigurationError("Configuration object unknown")
-      elif current.serial_no != target.serial_no:
-        raise errors.ConfigurationError("Configuration object updated since"
-                                        " it has been read: %d != %d",
-                                        current.serial_no, target.serial_no)
-
-    def replace_in(target, tdict):
-      check_serial(target, tdict.get(target.uuid))
-      tdict[target.uuid] = target
-
-    update_serial = False
+    update_function = None
     if isinstance(target, objects.Cluster):
-      check_serial(target, self._ConfigData().cluster)
-      self._ConfigData().cluster = target
+      update_function = self._wconfd.UpdateCluster
     elif isinstance(target, objects.Node):
-      replace_in(target, self._ConfigData().nodes)
-      update_serial = True
+      update_function = self._wconfd.UpdateNode
     elif isinstance(target, objects.Instance):
-      replace_in(target, self._ConfigData().instances)
+      update_function = self._wconfd.UpdateInstance
     elif isinstance(target, objects.NodeGroup):
-      replace_in(target, self._ConfigData().nodegroups)
+      update_function = self._wconfd.UpdateNodeGroup
     elif isinstance(target, objects.Network):
-      replace_in(target, self._ConfigData().networks)
+      update_function = self._wconfd.UpdateNetwork
     elif isinstance(target, objects.Disk):
-      replace_in(target, self._ConfigData().disks)
+      update_function = self._wconfd.UpdateDisk
     else:
       raise errors.ProgrammerError("Invalid object type (%s) passed to"
                                    " ConfigWriter.Update" % type(target))
-    target.serial_no += 1
-    target.mtime = now = time.time()
 
-    if update_serial:
-      # for node updates, we need to increase the cluster serial too
-      self._ConfigData().cluster.serial_no += 1
-      self._ConfigData().cluster.mtime = now
-
-    if isinstance(target, objects.Disk):
-      self._UnlockedReleaseDRBDMinors(target.uuid)
+    utils.SimpleRetry(True, update_function, 0.1, 30,
+                      args=[target.ToDict()])
+    self.OutDate()
 
     if ec_id is not None:
       # Commit all ips reserved by OpInstanceSetParams and OpGroupSetParams
       # FIXME: After RemoveInstance is moved to WConfd, use its internal
       # functions from TempRes module.
-      self._UnlockedCommitTemporaryIps(ec_id)
+      self.CommitTemporaryIps(ec_id)
 
     # Just verify the configuration with our feedback function.
     # It will get written automatically by the decorator.
-    self._UnlockedVerifyConfigAndLog(feedback_fn=feedback_fn)
+    self.VerifyConfigAndLog(feedback_fn=feedback_fn)
 
   def _UnlockedDropECReservations(self, _ec_id):
     """Drop per-execution-context reservations
-- 
2.2.0.rc0.207.ga3a616c

Reply via email to