Change in vdsm[master]: Adding API methods for CPU limit MOM integration
kobi at redhat.com
kobi at redhat.com
Sun Jun 8 13:14:54 UTC 2014
Kobi Ianko has uploaded a new change for review.
Change subject: Adding API methods for CPU limit MOM integration
......................................................................
Adding API methods for CPU limit MOM integration
Adding API methods to vm.py to integrate with MOM's collectors and controllers
Two new functions were added to the vdsm api:
VM.setCpuTuneQuota
This function sets a new quota value to the VM using the libvirt api.
Input: a Int value representing the quota as explained
at "http://libvirt.org/formatdomain.html#elementsCPUTuning".
VM.setCpuTunePeriod
This function sets a new period value to the VM using libvirt api.
Input: a Int value representing the period as explained
at "http://libvirt.org/formatdomain.html#elementsCPUTuning".
Change-Id: Ia78529b736ec0c841d232ba8aa1434bd0d0e8e08
Signed-off-by: Kobi Ianko <kianku at redhat.com>
---
M vdsm/API.py
M vdsm/virt/vm.py
M vdsm_api/vdsmapi-schema.json
3 files changed, 86 insertions(+), 14 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/62/28462/1
diff --git a/vdsm/API.py b/vdsm/API.py
index c43c1d0..f312a4a 100644
--- a/vdsm/API.py
+++ b/vdsm/API.py
@@ -690,6 +690,18 @@
return errCode['noVM']
return v.setBalloonTarget(target)
+ def setCpuTuneQuota(self, quota):
+ v = self._cif.vmContainer.get(self._UUID)
+ if not v:
+ return errCode['noVM']
+ return v.setCpuTuneQuota(quota)
+
+ def setCpuTunePeriod(self, period):
+ v = self._cif.vmContainer.get(self._UUID)
+ if not v:
+ return errCode['noVM']
+ return v.setCpuTunePeriod(period)
+
def getDiskAlignment(self, drive):
if self._UUID != VM.BLANK_UUID:
return errCode['noimpl']
diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py
index 4a6813e..d882fd2 100644
--- a/vdsm/virt/vm.py
+++ b/vdsm/virt/vm.py
@@ -4471,26 +4471,18 @@
def setBalloonTarget(self, target):
- def reportError(key='balloonErr', msg=None):
- self.log.error("Set new balloon target failed", exc_info=True)
- if msg is None:
- error = errCode[key]
- else:
- error = {'status': {'code': errCode[key]
- ['status']['code'], 'message': msg}}
- return error
-
if self._dom is None:
- return reportError()
+ return self._reportError(entity='balloon target')
+ target = int(target)
try:
- target = int(target)
self._dom.setMemory(target)
except ValueError:
- return reportError(msg='an integer is required for target')
+ return self._reportError(msg='an integer is required for target',
+ entity='balloon target')
except libvirt.libvirtError as e:
if e.get_error_code() == libvirt.VIR_ERR_NO_DOMAIN:
- return reportError(key='noVM')
- return reportError(msg=e.message)
+ return self._reportError(key='noVM', entity='balloon target')
+ return self._reportError(msg=e.message, entity='balloon target')
else:
for dev in self.conf['devices']:
if dev['type'] == BALLOON_DEVICES and \
@@ -4500,6 +4492,42 @@
self.saveState()
return {'status': doneCode}
+ def setCpuTuneQuota(self, quota):
+
+ if self._dom is None:
+ return self._reportError(entity='vcpu quota')
+
+ quota = int(quota)
+ try:
+ self._dom.setSchedulerParameters({'vcpu_quota': quota})
+ return {'status': doneCode}
+ except libvirt.libvirtError as e:
+ return self._reportError(msg=e.message, entity='vcpu quota')
+
+ def setCpuTunePeriod(self, period):
+
+ if self._dom is None:
+ return self._reportError(key='cpuTuneErr', entity='vcpu period')
+
+ period = int(period)
+ try:
+ self._dom.setSchedulerParameters({'vcpu_period': period})
+ return {'status': doneCode}
+ except ValueError:
+ return self._reportError(msg='an integer is required for period',
+ entity='vcpu period')
+ except libvirt.libvirtError as e:
+ return self._reportError(msg=e.message, entity='vcpu period')
+
+ def _reportError(self, key='Err', msg=None, entity=None):
+ self.log.error("Set new " + entity + " failed", exc_info=True)
+ if msg is None:
+ error = errCode[key]
+ else:
+ error = {'status': {'code': errCode[key]
+ ['status']['code'], 'message': msg}}
+ return error
+
def _getUnderlyingDeviceAddress(self, devXml):
"""
Obtain device's address from libvirt
diff --git a/vdsm_api/vdsmapi-schema.json b/vdsm_api/vdsmapi-schema.json
index 6457af8..e752cfa 100644
--- a/vdsm_api/vdsmapi-schema.json
+++ b/vdsm_api/vdsmapi-schema.json
@@ -7311,3 +7311,35 @@
{'command': {'class': 'VM', 'name': 'setNumberOfCpus'},
'data': {'vmID': 'UUID', 'numberOfCpus': 'int'},
'returns': 'VmDefinition'}
+
+
+##
+# @VM.setCpuTuneQuota:
+#
+# Set the vCpu quota tune parameter to the VM
+#
+# @quota: a number representing the quota to be set
+# Returns:
+# Status code
+#
+# Since: 4.15.0
+##
+{'command': {'class': 'VM', 'name': 'setCpuTuneQuota'},
+ 'data': {'quota': 'int'},
+ 'returns': 'TasksStatus'}
+
+
+##
+# @VM.setCpuTunePeriod:
+#
+# Set the vCpu period tune parameter to the VM
+#
+# @period: a number representing the period to be set
+# Returns:
+# Status code
+#
+# Since: 4.15.0
+##
+{'command': {'class': 'VM', 'name': 'setCpuTunePeriod'},
+ 'data': {'period': 'int'},
+ 'returns': 'TasksStatus'}
--
To view, visit http://gerrit.ovirt.org/28462
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia78529b736ec0c841d232ba8aa1434bd0d0e8e08
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Kobi Ianko <kobi at redhat.com>
More information about the vdsm-patches
mailing list