Francesco Romani has uploaded a new change for review.
Change subject: client: vm params from JSON ......................................................................
client: vm params from JSON
the 'create' parameter accepts a configuration file as source to define the parameters of the VM being created.
This patch add support to 1. use JSON for this configuration file, so there is little to no need to reformat data from Engine, for example took from VDSM logs 2. use stdin as input, avoiding the need to write (temporary) files.
Change-Id: Ic6a73bc0e5fe87eb1a48c708e7ea316c6d9df7e5 Signed-off-by: Francesco Romani fromani@redhat.com --- M client/vdsClient.py 1 file changed, 95 insertions(+), 68 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/92/35292/1
diff --git a/client/vdsClient.py b/client/vdsClient.py index aabf7a1..583a0a2 100644 --- a/client/vdsClient.py +++ b/client/vdsClient.py @@ -19,6 +19,7 @@
import sys import ast +import json import getopt import traceback import xmlrpclib @@ -204,74 +205,13 @@ sys.exit(response['status']['code'])
def do_create(self, args): - params = {} - drives = [] - devices = [] - cpuPinning = {} - numaTune = {} - guestNumaNodes = [] - confLines = [] - confFile = open(args[0]) - for line in confFile.readlines(): - line = re.sub("\s+", '', line) - line = re.sub("#.*", '', line) - if line: - confLines.append(line) - if len(args) > 1: - confLines.extend(args[1:]) - for line in confLines: - if '=' in line: - param, value = line.split("=", 1) - if param == 'devices': - devices.append(self._parseDriveSpec(value)) - elif param == 'drive': - drives.append(self._parseDriveSpec(value)) - elif param == 'cpuPinning': - cpuPinning, rStr = self._parseNestedSpec(value) - elif param == 'numaTune': - numaTune, rStr = self._parseNestedSpec(value) - elif param == 'guestNumaNodes': - guestNumaNodes.append(self._parseDriveSpec(value)) - elif param.startswith('custom_'): - if 'custom' not in params: - params['custom'] = {} - params['custom'][param[7:]] = value - else: - if param in ('cdrom', 'floppy'): - value = self._parseDriveSpec(value) - params[param] = value - else: - params[line.strip()] = '' - if cpuPinning: - params['cpuPinning'] = cpuPinning - if numaTune: - params['numaTune'] = numaTune - if guestNumaNodes: - params['guestNumaNodes'] = guestNumaNodes - if drives: - params['drives'] = drives - if devices: - params['devices'] = devices - # Backward compatibility for vdsClient users - if 'vt' in params: - params['kvmEnable'] = params['vt'] - - if 'imageFile' in params: - params['hda'] = params['imageFile'] - - drives = ['hdd', 'hdc', 'hdb'] - if 'moreImages' in params: - for image in params['moreImages'].split(','): - params[drives.pop()] = image - - if 'sysprepInf' in params: - infFile = open(params['sysprepInf'], 'rb') - try: - params['sysprepInf'] = xmlrpclib.Binary(infFile.read()) - finally: - infFile.close() - - return self.ExecAndExit(self.s.create(params)) + if args[0] == '-' or args[0].endswith('.json'): + params = self._readVmParamsFromJson(args) + else: + params = self._readVmParamsFromConf(args) + if params is not None: + return self.ExecAndExit(self.s.create(params)) + return sys.exit(1)
def vmUpdateDevice(self, args): params = self._eqSplit(args[1:]) @@ -1884,6 +1824,93 @@
return status['status']['code'], status['status']['message']
+ def _readVmParamsFromJson(self, args): + if args[0] == "-": + data = sys.stdin.read() + else: + try: + with open(args[0]) as f: + data = f.read() + except IOError as e: + print "failed to read VM config: %s" % str(e) + return None + try: + return json.loads(data) + except ValueError as e: + print "failed to decode VM config: %s" % str(e) + return None + + def _readVmParamsFromConf(self, args): + params = {} + drives = [] + devices = [] + cpuPinning = {} + numaTune = {} + guestNumaNodes = [] + confLines = [] + confFile = open(args[0]) + for line in confFile.readlines(): + line = re.sub("\s+", '', line) + line = re.sub("#.*", '', line) + if line: + confLines.append(line) + if len(args) > 1: + confLines.extend(args[1:]) + for line in confLines: + if '=' in line: + param, value = line.split("=", 1) + if param == 'devices': + devices.append(self._parseDriveSpec(value)) + elif param == 'drive': + drives.append(self._parseDriveSpec(value)) + elif param == 'cpuPinning': + cpuPinning, rStr = self._parseNestedSpec(value) + elif param == 'numaTune': + numaTune, rStr = self._parseNestedSpec(value) + elif param == 'guestNumaNodes': + guestNumaNodes.append(self._parseDriveSpec(value)) + elif param.startswith('custom_'): + if 'custom' not in params: + params['custom'] = {} + params['custom'][param[7:]] = value + else: + if param in ('cdrom', 'floppy'): + value = self._parseDriveSpec(value) + params[param] = value + else: + params[line.strip()] = '' + if cpuPinning: + params['cpuPinning'] = cpuPinning + if numaTune: + params['numaTune'] = numaTune + if guestNumaNodes: + params['guestNumaNodes'] = guestNumaNodes + if drives: + params['drives'] = drives + if devices: + params['devices'] = devices + # Backward compatibility for vdsClient users + if 'vt' in params: + params['kvmEnable'] = params['vt'] + + if 'imageFile' in params: + params['hda'] = params['imageFile'] + + drives = ['hdd', 'hdc', 'hdb'] + if 'moreImages' in params: + for image in params['moreImages'].split(','): + params[drives.pop()] = image + + if 'sysprepInf' in params: + infFile = open(params['sysprepInf'], 'rb') + try: + params['sysprepInf'] = xmlrpclib.Binary(infFile.read()) + finally: + infFile.close() + + return params + + if __name__ == '__main__': if _glusterEnabled: serv = ge.GlusterService()
oVirt Jenkins CI Server has posted comments on this change.
Change subject: client: vm params from JSON ......................................................................
Patch Set 1:
Build Failed
http://jenkins.ovirt.org/job/vdsm_master_unit_tests_gerrit_el/12694/ : FAILURE
http://jenkins.ovirt.org/job/vdsm_master_unit-tests_created/13645/ : FAILURE
http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/13483/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_unit-tests_created_staging/262/ : FAILURE
oVirt Jenkins CI Server has posted comments on this change.
Change subject: client: vm params from JSON ......................................................................
Patch Set 2:
Build Failed
http://jenkins.ovirt.org/job/vdsm_master_unit_tests_gerrit_el/12726/ : FAILURE
http://jenkins.ovirt.org/job/vdsm_master_unit-tests_created/13678/ : FAILURE
http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/13516/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_unit-tests_created_staging/295/ : ABORTED
automation@ovirt.org has posted comments on this change.
Change subject: client: vm params from JSON ......................................................................
Patch Set 3:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
oVirt Jenkins CI Server has posted comments on this change.
Change subject: client: vm params from JSON ......................................................................
Patch Set 3:
Build Successful
http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/16804/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_unit-tests_created/16976/ : SUCCESS
automation@ovirt.org has posted comments on this change.
Change subject: client: vm params from JSON ......................................................................
Patch Set 4:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
oVirt Jenkins CI Server has posted comments on this change.
Change subject: client: vm params from JSON ......................................................................
Patch Set 4:
Build Started http://jenkins.ovirt.org/job/vdsm_master_unit-tests_created/17049/
oVirt Jenkins CI Server has posted comments on this change.
Change subject: client: vm params from JSON ......................................................................
Patch Set 4:
Build Successful
http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/16877/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_unit-tests_created/17049/ : SUCCESS
Francesco Romani has abandoned this change.
Change subject: client: vm params from JSON ......................................................................
Abandoned
no interest
automation@ovirt.org has posted comments on this change.
Change subject: client: vm params from JSON ......................................................................
Patch Set 4:
* Update tracker::IGNORE, no Bug-Url found
vdsm-patches@lists.fedorahosted.org