From eb9adb539fb47ab4b5c4e859cf119b554b9116cb Mon Sep 17 00:00:00 2001 From: Greg Price Date: Sun, 30 Mar 2008 04:28:10 -0400 Subject: [PATCH] expose cloning autoinstaller in web interface svn path=/trunk/packages/sipb-xen-www/; revision=340 --- code/controls.py | 8 +++++++- code/main.py | 7 ++++++- code/templates/list.tmpl | 6 ++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/code/controls.py b/code/controls.py index 7134668..b2c60d5 100644 --- a/code/controls.py +++ b/code/controls.py @@ -68,6 +68,10 @@ def makeDisks(machine): for disk in machine.disks: lvcreate(machine, disk) +def lvcopy(machine_orig_name, machine, rootpw): + """Copy a golden image onto a machine's disk""" + remctl('web', 'lvcopy', machine_orig_name, machine.name, rootpw) + def bootMachine(machine, cdtype): """Boot a machine with a given boot CD. @@ -95,7 +99,7 @@ def unregisterMachine(machine): """Unregister a machine to not be controlled by the web interface""" remctl('web', 'unregister', machine.name) -def createVm(owner, contact, name, memory, disk_size, is_hvm, cdrom): +def createVm(owner, contact, name, memory, disk_size, is_hvm, cdrom, clone_from): """Create a VM and put it in the database""" # put stuff in the table transaction = ctx.current.create_transaction() @@ -136,6 +140,8 @@ def createVm(owner, contact, name, memory, disk_size, is_hvm, cdrom): raise registerMachine(machine) makeDisks(machine) + if clone_from: + lvcopy(clone_from, machine, 'password') # tell it to boot with cdrom bootMachine(machine, cdrom) return machine diff --git a/code/main.py b/code/main.py index 31465f6..8bc9ece 100755 --- a/code/main.py +++ b/code/main.py @@ -159,8 +159,13 @@ def parseCreate(user, fields): cdrom = fields.getfirst('cdrom') if cdrom is not None and not CDROM.get(cdrom): raise CodeError("Invalid cdrom type '%s'" % cdrom) + + clone_from = fields.getfirst('clone_from') + if clone_from and clone_from != 'ice3': + raise CodeError("Invalid clone image '%s'" % clone_from) + return dict(contact=user, name=name, memory=memory, disk_size=disk_size, - owner=owner, is_hvm=is_hvm, cdrom=cdrom) + owner=owner, is_hvm=is_hvm, cdrom=cdrom, clone_from=clone_from) def create(user, fields): """Handler for create requests.""" diff --git a/code/templates/list.tmpl b/code/templates/list.tmpl index 6e06c53..b6e9e33 100644 --- a/code/templates/list.tmpl +++ b/code/templates/list.tmpl @@ -52,6 +52,12 @@ $errorRow('vmtype', $err) $errorRow('cdrom', $err) + Clone image? + + (experimental; 1-2 minutes, and you have an etch machine; root pw is 'password'.) + +$errorRow('cdrom', $err) + Owner -- 1.7.9.5