Commit 9939547b authored by Iustin Pop's avatar Iustin Pop
Browse files

Fix batcher for 2.0-style disks and nics

This patch fixes the gnt-instance batch-create command, and in doing so
also slightly changes two other functions:
  - we change utils.ParseUnit so that it accepts integer values also
    (both ParseUnit(5) and ParseUnit("5") return the same value)
  - a bridge 'None' in LUCreateInstance will be converted to the default
    bridge; currently only missing bridges will be accepted to mean the
    default one

The main changes to batcher were the change to variable number of disks
and NICs.

The patch also adds a batcher-instances.json example file copied from
the 1.2 branch and properly modified.

Reviewed-by: imsnah, killerfoxi
parent 1325da74
{
"instance1.example.com": {
"template": "drbd",
"os": "debootstrap",
"disk_size": ["25G"],
"ram_size": 512
},
"instance2.example.com": {
"template": "plain",
"os": "debootstrap",
"disk_size": ["100G"],
"ram_size": 512
}
}
......@@ -4193,7 +4193,9 @@ class LUCreateInstance(LogicalUnit):
raise errors.OpPrereqError("Invalid MAC address specified: %s" %
mac)
# bridge verification
bridge = nic.get("bridge", self.cfg.GetDefBridge())
bridge = nic.get("bridge", None)
if bridge is None:
bridge = self.cfg.GetDefBridge()
self.nics.append(objects.NIC(mac=mac, ip=nic_ip, bridge=bridge))
# disk checks/pre-build
......
......@@ -751,7 +751,7 @@ def ParseUnit(input_string):
is always an int in MiB.
"""
m = re.match('^([.\d]+)\s*([a-zA-Z]+)?$', input_string)
m = re.match('^([.\d]+)\s*([a-zA-Z]+)?$', str(input_string))
if not m:
raise errors.UnitParseError("Invalid format")
......
......@@ -375,13 +375,12 @@ def BatchCreate(opts, args):
in the form::
{"instance-name":{
"disk_size": 25,
"swap_size": 1024,
"disk_size": [20480],
"template": "drbd",
"backend": {
"memory": 512,
"vcpus": 1 },
"os": "etch-image",
"os": "debootstrap",
"primary_node": "firstnode",
"secondary_node": "secondnode",
"iallocator": "dumb"}
......@@ -397,8 +396,7 @@ def BatchCreate(opts, args):
@return: the desired exit code
"""
_DEFAULT_SPECS = {"disk_size": 20 * 1024,
"swap_size": 4 * 1024,
_DEFAULT_SPECS = {"disk_size": [20 * 1024],
"backend": {},
"iallocator": None,
"primary_node": None,
......@@ -458,19 +456,29 @@ def BatchCreate(opts, args):
if specs['hypervisor']:
hypervisor, hvparams = specs['hypervisor'].iteritems()
disks = []
for elem in specs['disk_size']:
try:
size = utils.ParseUnit(elem)
except ValueError, err:
raise errors.OpPrereqError("Invalid disk size '%s' for"
" instance %s: %s" %
(elem, name, err))
disks.append({"size": size})
nic0 = {'ip': specs['ip'], 'bridge': specs['bridge'], 'mac': specs['mac']}
op = opcodes.OpCreateInstance(instance_name=name,
disk_size=specs['disk_size'],
swap_size=specs['swap_size'],
disks=disks,
disk_template=specs['template'],
mode=constants.INSTANCE_CREATE,
os_type=specs['os'],
pnode=specs['primary_node'],
snode=specs['secondary_node'],
ip=specs['ip'], bridge=specs['bridge'],
nics=[nic0],
start=specs['start'],
ip_check=specs['ip_check'],
wait_for_sync=True,
mac=specs['mac'],
iallocator=specs['iallocator'],
hypervisor=hypervisor,
hvparams=hvparams,
......
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