Change in vdsm[master]: Adding "updateVmDevicePolicy" api

gchaplik at redhat.com gchaplik at redhat.com
Tue Jun 10 19:07:06 UTC 2014


Gilad Chaplik has uploaded a new change for review.

Change subject: Adding "updateVmDevicePolicy" api
......................................................................

Adding "updateVmDevicePolicy" api

Adding "updateVmDevicePolicy".
The method will be called from the engine
when a VM's Device SLA parameters will change; for now
it will support blkio tune of a disk.

Change-Id: I43b25627e5365fdd1145ac5e91fb5b7714e46bbf
Signed-off-by: Gilad Chaplik <gchaplik at redhat.com>
---
M client/vdsClient.py
M lib/vdsm/define.py
M tests/functional/utils.py
M tests/functional/virtTests.py
M vdsm/API.py
M vdsm/BindingXMLRPC.py
M vdsm/virt/vm.py
M vdsm_api/Bridge.py
M vdsm_api/vdsmapi-schema.json
9 files changed, 120 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/77/28577/1

diff --git a/client/vdsClient.py b/client/vdsClient.py
index b17955e..3923ff6 100644
--- a/client/vdsClient.py
+++ b/client/vdsClient.py
@@ -262,6 +262,10 @@
         params = {'vmId': args[0], 'vcpuLimit': args[1]}
         return self.ExecAndExit(self.s.updateVmPolicy(params))
 
+    def updateVmDevicePolicy(self, args):
+        params = {'vmId': args[0], 'device': args[1], 'qosParamMap' = args[2] }
+        return self.ExecAndExit(self.s.updateVmDevicePolicy(params))
+
     def do_changeCD(self, args):
         vmId = args[0]
         file = self._parseDriveSpec(args[1])
@@ -2606,6 +2610,11 @@
                 '<vmId> <vcpuLimit>',
                 'set SLA parameter for a VM'
             )),
+        'updateVmDevicePolicy': (
+            serv.updateVmPolicy, (
+                '<vmId> <device> [<tuneParamMap>({totalBytesSec=int, readBytesSec=int, writeBytesSec=int, totalIopsSec=int, readIopsSec=int, writeIopsSec=int})],
+                'set SLA tune parameters for VM\'s device'
+            )),
     }
     if _glusterEnabled:
         commands.update(ge.getGlusterCmdDict(serv))
diff --git a/lib/vdsm/define.py b/lib/vdsm/define.py
index f31e60e..29d11b2 100644
--- a/lib/vdsm/define.py
+++ b/lib/vdsm/define.py
@@ -147,6 +147,9 @@
     'blkioTuneErr': {'status': {
         'code': 64,
         'message': 'BlkIoTune operation is not available'}},
+    'updateVmDevicePolicyErr': {'status': {
+        'code': 65,
+        'message': 'Failed to update VM\'s device SLA policy'}},
     'recovery': {'status': {
         'code': 99,
         'message': 'Recovering from crash or Initializing'}},
diff --git a/tests/functional/utils.py b/tests/functional/utils.py
index cc4cef7..cee1971 100644
--- a/tests/functional/utils.py
+++ b/tests/functional/utils.py
@@ -233,3 +233,8 @@
         result = self.vdscli.updateVmPolicy([vmId, vcpuLimit])
         return result['status']['code'], result['status']['message'],\
             result['info']
+
+    def updateVmDevicePolicy(self, vmId, deviceId, totalBytesSec, readBytesSec, writeBytesSec, totalIopsSec, readIopsSec, writeIopsSec):
+        result = self.vdscli.updateVmDevicePolicy([vmId, deviceId, totalBytesSec, readBytesSec, writeBytesSec, totalIopsSec, readIopsSec, writeIopsSec])
+        return result['status']['code'], result['status']['message'],\
+            result['info']
diff --git a/tests/functional/virtTests.py b/tests/functional/virtTests.py
index 0d8f00f..7ce9b14 100644
--- a/tests/functional/virtTests.py
+++ b/tests/functional/virtTests.py
@@ -412,3 +412,24 @@
             self.vdsm.updateVmPolicy('99999999-aaaa-ffff-bbbb-111111111111',
                                      '50')
             self.assertEqual(status, SUCCESS, msg)
+
+    def testVmDeviceWithSla(self, backendType):
+        devices = [{'type': 'disk'}]
+        customization = {'vmId': '99999999-aaaa-ffff-bbbb-111111111111',
+                         'vmName': 'testVmDeviceWithSla' + backendType,
+                         'devices': devices}
+
+        with RunningVm(self.vdsm, customization) as vm:
+            self._waitForStartup(vm, VM_MINIMAL_UPTIME)
+            status, msg, stats = self.vdsm.getVmStats(vm)
+            self.assertEqual(status, SUCCESS, msg)
+            self.vdsm.updateVmDevicePolicy('99999999-aaaa-ffff-bbbb-111111111111',
+                                           '99999999-aaaa-ffff-aaaa-111111111111',
+                                           '0',
+                                           '0',
+                                           '0',
+                                           '1',
+                                           '2',
+                                           '3')
+                                     )
+            self.assertEqual(status, SUCCESS, msg)
diff --git a/vdsm/API.py b/vdsm/API.py
index 5335231..73adf7f 100644
--- a/vdsm/API.py
+++ b/vdsm/API.py
@@ -500,6 +500,28 @@
 
         return curVm.updateVmPolicy(params)
 
+    def updateVmDevicePolicy(self, params):
+
+        if params['vmId'] is None or params['dev'] is None:
+            self.log.error('Missing one of required parameters: \
+                           vmId: (%s), dev: (%s), totalBytesSec: (%s), \
+                           readBytesSec: (%s), writeBytesSec: (%s), totalIopsSec: (%s), \
+                           readIopsSec: (%s), writeIopsSec: (%s)', params['vmId'],
+                           params['dev'], params['total_bytes_sec'],
+                           params['read_bytes_sec'], params['write_bytes_sec'],
+                           params['total_iops_sec'], params['read_iops_sec'],
+                           params['write_iops_sec'])
+            return {'status': {'code': errCode['MissParam']['status']['code'],
+                               'message': 'Missing one of required '
+                                          'parameters: vmId, vmDevice, blkio parameters'}}
+        try:
+            curVm = self._cif.vmContainer[self._UUID]
+        except KeyError:
+            self.log.warning("vm %s doesn't exist", self._UUID)
+            return errCode['noVM']
+
+        return curVm.updateVmDevicePolicy(dev, params)
+
     def migrate(self, params):
         """
         Migrate a VM to a remote host.
diff --git a/vdsm/BindingXMLRPC.py b/vdsm/BindingXMLRPC.py
index 33bb7d4..be4212f 100644
--- a/vdsm/BindingXMLRPC.py
+++ b/vdsm/BindingXMLRPC.py
@@ -440,6 +440,10 @@
         vm = API.VM(params['vmId'])
         return vm.updateVmPolicy(params)
 
+    def vmUpdateVmDevicePolicy(self, params):
+        vm = API.VM(params['vmId'])
+        return vm.updateVmDevicePolicy(params)
+
     def vmSnapshot(self, vmId, snapDrives, snapMemVolHandle=''):
         """
         Take snapshot of VM
@@ -1011,7 +1015,8 @@
                 (self.vmHotunplugNic, 'hotunplugNic'),
                 (self.vmUpdateDevice, 'vmUpdateDevice'),
                 (self.vmSetNumberOfCpus, 'setNumberOfCpus'),
-                (self.vmUpdateVmPolicy, 'updateVmPolicy'))
+                (self.vmUpdateVmPolicy, 'updateVmPolicy'),
+                (self.vmUpdateVmDevicePolicy, 'updateVmDevicePolicy'))
 
     def getIrsMethods(self):
         return ((self.domainActivate, 'activateStorageDomain'),
diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py
index 5c6db33..097c537 100644
--- a/vdsm/virt/vm.py
+++ b/vdsm/virt/vm.py
@@ -3524,6 +3524,26 @@
 
         return {'status': doneCode}
 
+    def updateVmDevicePolicy(self, dev, params):
+
+        if self.isMigrating():
+            return errCode['migInProgress']
+
+        try:
+            metadataType = libvirt.VIR_DOMAIN_METADATA_ELEMENT
+            self._dom.setMetadata(metadataType, '<vcpulimit>' +
+                                  params['vcpuLimit'] +
+                                  '</vcpulimit>', 'ovirt',
+                                  'http://ovirt.org/vm/device/tune/1.0', 0)
+        except libvirt.libvirtError as e:
+            self.log.error("updateVmDevicePolicy failed", exc_info=True)
+            if e.get_error_code() == libvirt.VIR_ERR_NO_DOMAIN:
+                return errCode['noVM']
+            return {'status': {'code': errCode['updateVmDevicePolicyErr']
+                    ['status']['code'], 'message': e.message}}
+
+        return {'status': doneCode}
+
     def _createTransientDisk(self, diskParams):
         if diskParams.get('shared', None) != DRIVE_SHARED_TYPE.TRANSIENT:
             return
@@ -4642,6 +4662,18 @@
             return self._reportError(key='cpuTuneErr', msg=str(e))
         return {'status': doneCode}
 
+     def _checkIoTuneInvalidParams(self, params):
+         validKeys = set(('total_bytes_sec', 'read_bytes_sec',
+                          'write_bytes_sec', 'total_iops_sec',
+                          'write_iops_sec', 'read_iops_sec'))
+         paramKeys = set(params)
+ 
+         invalidParams = paramKeys - validKeys
+         if invalidParams:
+             invalidParamNames = ', '.join(invalidParams)
+             raise ValueError('Parameter %s name(s) are invalid' %
+                              invalidParamNames)
+
     def setDiskBlkioTuneMap(self, disk, blkIoTuneMap):
         if not disk.device == 'disk' or not isVdsmImage(disk):
             return self._reportError(key='blkioTuneErr' msg=
diff --git a/vdsm_api/Bridge.py b/vdsm_api/Bridge.py
index dec602b..902ed66 100644
--- a/vdsm_api/Bridge.py
+++ b/vdsm_api/Bridge.py
@@ -365,6 +365,7 @@
     'VM_migrationCreate': {'ret': VM_migrationCreate_Ret},
     'VM_setNumberOfCpus': {'ret': 'vmList'},
     'VM_updateVmPolicy': {},
+    'VM_updateVmDevicePolicy': {},
     'Volume_copy': {'ret': 'uuid'},
     'Volume_create': {'ret': 'uuid'},
     'Volume_delete': {'ret': 'uuid'},
diff --git a/vdsm_api/vdsmapi-schema.json b/vdsm_api/vdsmapi-schema.json
index 9ce4bb0..caaf5a5 100644
--- a/vdsm_api/vdsmapi-schema.json
+++ b/vdsm_api/vdsmapi-schema.json
@@ -7380,3 +7380,24 @@
 ##
 {'command': {'class': 'VM', 'name': 'updateVmPolicy'},
  'data': {'vmID': 'UUID', 'vcpuLimit': 'int'}}
+
+##
+# @VM.updateVmDevicePolicy:
+#
+# Set VM\' Device SLA parameters
+#
+# @vmID:    The UUID of the VM
+#
+# @device:    Name or source file for one of the device attached to domain
+#
+# @params:  The VM device SLA tuning parameters
+#
+# Returns:
+# The VM definition, as updated
+#
+# Since: 4.15.0
+##
+{'command': {'class': 'VM', 'name': 'updateVmDevicePolicy'},
+ 'data': {'vmID': 'UUID', 
+          'device': 'str',
+          'params': 'SLATuneParameterMap'}}


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I43b25627e5365fdd1145ac5e91fb5b7714e46bbf
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Gilad Chaplik <gchaplik at redhat.com>


More information about the vdsm-patches mailing list