Change in vdsm[master]: [WIP] BZ#855924 fix VM config dictionary #2

peet at redhat.com peet at redhat.com
Tue Oct 16 21:10:09 UTC 2012


Peter V. Saveliev has uploaded a new change for review.

Change subject: [WIP] BZ#855924 fix VM config dictionary #2
......................................................................

[WIP] BZ#855924 fix VM config dictionary #2

Fix vm.conf dictionary when migrating from 3.1 to 3.0,
getting the target version with getCapabilities(fast=True) call.
The issue was that 3.0 defines cdrom and floppy as dedicated
dictionary keys, while 3.1 places them among other devices.

The idea is to add an optional parameter to getCapabilities().
It will save the backward compatibility, and will allow to get
basic capabilities without adding a new verb in API on the one
side, and on the other side -- without querying RPM database for
each call.

Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=855924
Signed-off-by: Peter V. Saveliev <peet at redhat.com>
Change-Id: I33e957f8daac4266d9e19cc008cf830bd395ffff
---
M vdsm/API.py
M vdsm/BindingXMLRPC.py
M vdsm/caps.py
M vdsm/vm.py
4 files changed, 40 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/12/8612/1

diff --git a/vdsm/API.py b/vdsm/API.py
index bbc3221..c131458 100644
--- a/vdsm/API.py
+++ b/vdsm/API.py
@@ -1068,11 +1068,11 @@
         "Ping the server. Useful for tests"
         return {'status': doneCode}
 
-    def getCapabilities(self):
+    def getCapabilities(self, fast=False):
         """
         Report host capabilities.
         """
-        c = caps.get()
+        c = caps.get(fast)
         c['netConfigDirty'] = str(self._cif._netConfigDirty)
 
         return {'status': doneCode, 'info': c}
diff --git a/vdsm/BindingXMLRPC.py b/vdsm/BindingXMLRPC.py
index fc57019..a1926d9 100644
--- a/vdsm/BindingXMLRPC.py
+++ b/vdsm/BindingXMLRPC.py
@@ -278,9 +278,9 @@
         vm = API.VM(vmId)
         return vm.setBalloonTarget(target)
 
-    def getCapabilities(self):
+    def getCapabilities(self, fast=False):
         api = API.Global()
-        ret = api.getCapabilities()
+        ret = api.getCapabilities(fast)
         ret['info'].update(self.getServerInfo())
         return ret
 
diff --git a/vdsm/caps.py b/vdsm/caps.py
index 295d4ed..4601f54 100644
--- a/vdsm/caps.py
+++ b/vdsm/caps.py
@@ -245,7 +245,15 @@
     return dict(release=release, version=version, name=osname)
 
 
-def get():
+def get(fast=False):
+    caps = {}
+    if not fast:
+        caps.update(get_all_caps())
+    caps.update(dsaversion.version_info)
+    return caps
+
+
+def get_all_caps():
     caps = {}
 
     caps['kvmEnabled'] = \
@@ -273,7 +281,6 @@
         caps['cpuFlags'] = ','.join(cpuInfo.flags() +
                                     _getCompatibleCpuModels())
 
-    caps.update(dsaversion.version_info)
     caps.update(netinfo.get())
 
     try:
diff --git a/vdsm/vm.py b/vdsm/vm.py
index de67420..d5ceb1a 100644
--- a/vdsm/vm.py
+++ b/vdsm/vm.py
@@ -34,6 +34,8 @@
 import libvirt
 from vdsm import vdscli
 
+from distutils.version import StrictVersion
+
 DEFAULT_BRIDGE = config.get("vars", "default_bridge")
 
 DISK_DEVICES = 'disk'
@@ -92,6 +94,8 @@
         self._mode = mode
         self._method = method
         self._dstparams = dstparams
+        # default destination version
+        self._dst_version = StrictVersion("3.0")
         self._machineParams = {}
         self._downtime = kwargs.get('downtime') or \
                             config.get('vars', 'migration_downtime')
@@ -125,6 +129,15 @@
         self.log.debug('Destination server is: ' + serverAddress)
         try:
             self.log.debug('Initiating connection with destination')
+            try:
+                capabilities = self.destServer.getVdsCapabilities(fast=True)
+                self._dst_version = StrictVersion(str(max(
+                    capabilities['info']['supportedRHEVMs']
+                    )))
+            except:
+                pass
+            self.log.info("Using VM config version '%s' in migration" %\
+                    (str(self._dest_version)))
             status = self.destServer.getVmStats(self._vm.id)
             if not status['status']['code']:
                 self.log.error("Machine already exists on the destination")
@@ -218,6 +231,20 @@
             MigrationSourceThread._ongoingMigrations.acquire()
             try:
                 self.log.debug("migration semaphore acquired")
+                # patch VM config for targets < 3.1
+                if self._dst_version < StrictVersion('3.1'):
+                    for i in ('cdrom', 'floppy'):
+                        try:
+                            # add cdrom and floppy as paths
+                            self._vm.conf[i] = [x['path'] for x in \
+                                self._vm.conf['drives'] if x['device'] == i][0]
+                            # remove them from 'devices' list
+                            [self._vm.conf['drives'].pop(
+                                self._vm.conf['drives'].index(z)) \
+                                for z in [x for x in \
+                                self._vm.conf['drives'] if x['device'] == i]]
+                        except:
+                            pass
                 if not mstate:
                     self._vm.conf['_migrationParams'] = {'dst': self._dst,
                                 'mode': self._mode, 'method': self._method,


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I33e957f8daac4266d9e19cc008cf830bd395ffff
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Peter V. Saveliev <peet at redhat.com>


More information about the vdsm-patches mailing list