Commit 4082e6f9 authored by Iustin Pop's avatar Iustin Pop
Browse files

Some batcher fixes

Currently the batcher hypervisor parameter must be a dict with one
element (e.g. {"xen-hvm": { "acpi": true }}). This is overly complex and
hard to validate correctly; the patch splits it in two:
  - one "hypervisor" string parameter, with the name of the hypervisor
  - one "hvparams" dictionary, with the hypervisor parameters

The patch also changes the error handling in parsing the definition file
- since this is not a long-running file, we are less concerned with safe
closing of the file, and more with presenting meaningful error

Reviewed-by: killerfoxi
parent 5b460366
......@@ -418,6 +418,7 @@ def BatchCreate(opts, args):
"start": True,
"ip_check": True,
"hypervisor": None,
"hvparams": {},
"file_storage_dir": None,
"file_driver": 'loop'}
......@@ -444,16 +445,18 @@ def BatchCreate(opts, args):
raise errors.OpPrereqError('You have to provide at least a primary_node'
' or an iallocator.')
if (spec['hypervisor'] and
not isinstance(spec['hypervisor'], dict)):
if (spec['hvparams'] and
not isinstance(spec['hvparams'], dict)):
raise errors.OpPrereqError('Hypervisor parameters must be a dict.')
json_filename = args[0]
fd = open(json_filename, 'r')
fd = open(json_filename, 'r')
instance_data = simplejson.load(fd)
except Exception, err:
ToStderr("Can't parse the instance definition file: %s" % str(err))
return 1
# Iterate over the instances and do:
# * Populate the specs with default value
......@@ -464,10 +467,8 @@ def BatchCreate(opts, args):
specs = _PopulateWithDefaults(specs)
hypervisor = None
hvparams = {}
if specs['hypervisor']:
hypervisor, hvparams = specs['hypervisor'].iteritems()
hypervisor = specs['hypervisor']
hvparams = specs['hvparams']
disks = []
for elem in specs['disk_size']:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment