+
+ olddisk = {}
+ transaction = ctx.current.create_transaction()
+ try:
+ machine = testMachineId(user, fields.getfirst('machine_id'))
+ owner = testOwner(user, fields.getfirst('owner'), machine)
+ contact = testContact(user, fields.getfirst('contact'))
+ hostname = testHostname(owner, fields.getfirst('hostname'),
+ machine)
+ name = testName(user, fields.getfirst('name'), machine)
+ oldname = machine.name
+ command="modify"
+
+ memory = fields.getfirst('memory')
+ if memory is not None:
+ memory = validMemory(user, memory, machine, on=False)
+ machine.memory = memory
+
+ disksize = testDisk(user, fields.getfirst('disk'))
+ if disksize is not None:
+ disksize = validDisk(user, disksize, machine)
+ disk = machine.disks[0]
+ if disk.size != disksize:
+ olddisk[disk.guest_device_name] = disksize
+ disk.size = disksize
+ ctx.current.save(disk)
+
+ # XXX first NIC gets hostname on change? Interface doesn't support more.
+ for nic in machine.nics[:1]:
+ nic.hostname = hostname
+ ctx.current.save(nic)
+
+ if owner is not None and owner != machine.owner:
+ machine.owner = owner
+ if name is not None and name != machine.name:
+ machine.name = name
+
+ ctx.current.save(machine)
+ transaction.commit()
+ except:
+ transaction.rollback()
+ raise
+ for diskname in olddisk:
+ remctl("web", "lvresize", oldname, diskname, str(olddisk[diskname]))
+ if name is not None and name != oldname:
+ for disk in machine.disks:
+ if oldname != name:
+ remctl("web", "lvrename", oldname, disk.guest_device_name, name)
+ remctl("web", "moveregister", oldname, name)
+ d = dict(user=user,
+ command=command,
+ machine=machine)
+ return Template(file="command.tmpl", searchList=[d, global_dict])
+
+