Nir Soffer has uploaded a new change for review.

Change subject: virt: Extract Vm.__extendDriveReplica method
......................................................................

virt: Extract Vm.__extendDriveReplica method

Vm.extendDriveVolume() was either calling Vm.__extendDriveVolume, or
implementing extending of drive replica. This is mixing different level of
abstraction in one method which makes the code harder to understand and
lead to code duplication.

Now replica extension is handled in new Vm.__extendDriveReplica()
method, simplifying Vm.extendDriveVolume().

Before we use getattr(drive, "DiskReplicate", None) to check if drive
has an attribute. Now using hasattr to make the intent of the code more
clear.

Change-Id: I82182f126c754c3a63d650396d78c5e361be2aa9
Signed-off-by: Nir Soffer <[email protected]>
---
M vdsm/virt/vm.py
1 file changed, 16 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/28/38028/1

diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py
index eb49eb3..8c11759 100644
--- a/vdsm/virt/vm.py
+++ b/vdsm/virt/vm.py
@@ -1477,17 +1477,8 @@
         """
         newSize = vmDrive.getNextVolumeSize(curSize, capacity)
 
-        if getattr(vmDrive, 'diskReplicate', None):
-            volInfo = {'poolID': vmDrive.diskReplicate['poolID'],
-                       'domainID': vmDrive.diskReplicate['domainID'],
-                       'imageID': vmDrive.diskReplicate['imageID'],
-                       'volumeID': vmDrive.diskReplicate['volumeID'],
-                       'name': vmDrive.name, 'newSize': newSize}
-            self.log.debug("Requesting an extension for the volume "
-                           "replication: %s", volInfo)
-            self.cif.irs.sendExtendMsg(vmDrive.poolID, volInfo,
-                                       newSize,
-                                       self.__afterReplicaExtension)
+        if hasattr(vmDrive, 'diskReplicate'):
+            self.__extendDriveReplica(vmDrive, newSize)
         else:
             self.__extendDriveVolume(vmDrive, volumeID, newSize)
 
@@ -1535,6 +1526,20 @@
             newSize,
             self.__afterVolumeExtension)
 
+    def __extendDriveReplica(self, drive, newSize):
+        volInfo = {'poolID': drive.diskReplicate['poolID'],
+                   'domainID': drive.diskReplicate['domainID'],
+                   'imageID': drive.diskReplicate['imageID'],
+                   'volumeID': drive.diskReplicate['volumeID'],
+                   'name': drive.name,
+                   'newSize': newSize}
+        self.log.debug("Requesting an extension for the volume "
+                       "replication: %s", volInfo)
+        self.cif.irs.sendExtendMsg(drive.poolID,
+                                   volInfo,
+                                   newSize,
+                                   self.__afterReplicaExtension)
+
     def __afterVolumeExtension(self, volInfo):
         # Check if the extension succeeded.  On failure an exception is raised
         # TODO: Report failure to the engine.


-- 
To view, visit http://gerrit.ovirt.org/38028
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I82182f126c754c3a63d650396d78c5e361be2aa9
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to