Add a description field.
authorAnders Kaseorg <andersk@mit.edu>
Wed, 18 Jun 2008 07:50:31 +0000 (03:50 -0400)
committerAnders Kaseorg <andersk@mit.edu>
Wed, 18 Jun 2008 07:50:31 +0000 (03:50 -0400)
svn path=/trunk/packages/sipb-xen-www/; revision=609

code/controls.py
code/main.py
code/templates/info.tmpl
code/templates/list.tmpl
code/validation.py

index 57107ef..622dd50 100644 (file)
@@ -92,18 +92,19 @@ def bootMachine(machine, cdtype):
         raise CodeError('"%s" on "control %s create %s' 
                         % (err, machine.name, cdtype))
 
-def createVm(username, state, owner, contact, name, memory, disksize, machine_type, cdrom, clone_from):
+def createVm(username, state, owner, contact, name, description, memory, disksize, machine_type, cdrom, clone_from):
     """Create a VM and put it in the database"""
     # put stuff in the table
     transaction = ctx.current.create_transaction()
     try:
-        validation.Validate(username, state, name=name, owner=owner, memory=memory, disksize=disksize/1024.)
+        validation.Validate(username, state, name=name, description=description, owner=owner, memory=memory, disksize=disksize/1024.)
         res = meta.engine.execute('select nextval('
                                   '\'"machines_machine_id_seq"\')')
         id = res.fetchone()[0]
         machine = Machine()
         machine.machine_id = id
         machine.name = name
+        machine.description = description
         machine.memory = memory
         machine.owner = owner
         machine.administrator = owner
index 2b7cf07..248f0f6 100755 (executable)
@@ -103,6 +103,7 @@ class Defaults:
     cdrom = ''
     autoinstall = ''
     name = ''
+    description = ''
     type = 'linux-hvm'
 
     def __init__(self, max_memory=None, max_disk=None, **kws):
@@ -135,9 +136,9 @@ def hasVnc(status):
     return False
 
 def parseCreate(username, state, fields):
-    kws = dict([(kw, fields.getfirst(kw)) for kw in 'name owner memory disksize vmtype cdrom clone_from'.split()])
+    kws = dict([(kw, fields.getfirst(kw)) for kw in 'name description owner memory disksize vmtype cdrom clone_from'.split()])
     validate = validation.Validate(username, state, strict=True, **kws)
-    return dict(contact=username, name=validate.name, memory=validate.memory,
+    return dict(contact=username, name=validate.name, description=validate.description, memory=validate.memory,
                 disksize=validate.disksize, owner=validate.owner, machine_type=validate.vmtype,
                 cdrom=getattr(validate, 'cdrom', None),
                 clone_from=getattr(validate, 'clone_from', None))
@@ -346,7 +347,7 @@ def modifyDict(username, state, fields):
     olddisk = {}
     transaction = ctx.current.create_transaction()
     try:
-        kws = dict([(kw, fields.getfirst(kw)) for kw in 'machine_id owner admin contact name memory vmtype disksize'.split()])
+        kws = dict([(kw, fields.getfirst(kw)) for kw in 'machine_id owner admin contact name description memory vmtype disksize'.split()])
         validate = validation.Validate(username, state, **kws)
         machine = validate.machine
         oldname = machine.name
@@ -371,6 +372,8 @@ def modifyDict(username, state, fields):
             update_acl = True
         if hasattr(validate, 'name'):
             machine.name = validate.name
+        if hasattr(validate, 'description'):
+            machine.description = validate.description
         if hasattr(validate, 'admin') and validate.admin != machine.administrator:
             machine.administrator = validate.admin
             update_acl = True
@@ -488,6 +491,7 @@ def infoDict(username, state, machine):
     display_fields = """name uptime memory state cpu_weight on_reboot 
      on_poweroff on_crash on_xend_start on_xend_stop bootloader""".split()
     display_fields = [('name', 'Name'),
+                      ('description', 'Description'),
                       ('owner', 'Owner'),
                       ('administrator', 'Administrator'),
                       ('contact', 'Contact'),
@@ -509,6 +513,7 @@ def infoDict(username, state, machine):
     fields = []
     machine_info = {}
     machine_info['name'] = machine.name
+    machine_info['description'] = machine.description
     machine_info['type'] = machine.type.hvm and 'HVM' or 'ParaVM'
     machine_info['owner'] = machine.owner
     machine_info['administrator'] = machine.administrator
@@ -543,7 +548,7 @@ def infoDict(username, state, machine):
     checkpoint.checkpoint('Got mem')
     max_disk = validation.maxDisk(machine.owner, machine)
     defaults = Defaults()
-    for name in 'machine_id name administrator owner memory contact'.split():
+    for name in 'machine_id name description administrator owner memory contact'.split():
         setattr(defaults, name, getattr(machine, name))
     defaults.type = machine.type.type_id
     defaults.disk = "%0.2f" % (machine.disks[0].size/1024.)
@@ -612,8 +617,6 @@ def show_error(op, username, fields, err, emsg, traceback):
     d = dict(op=op, user=username, fields=fields,
              errorMessage=str(err), stderr=emsg, traceback=traceback)
     details = templates.error_raw(searchList=[d])
-    send_error_mail('xvm error on %s for %s: %s' % (op, username, err),
-                    details)
     d['details'] = details
     return templates.error(searchList=[d])
 
index b65299c..2c3d28c 100644 (file)
@@ -65,6 +65,7 @@ $cdromList()#slurp
 <form action="modify" method="POST">
   <input type="hidden" name="machine_id" value="$defaults.machine_id"/>
   <table>
+    <tr><td>Description:</td><td colspan="2"><textarea name="description" rows="4" cols="60">$defaults.description</textarea></td></tr>
     <tr><td>Owner#slurp
 #filter None
 $helppopup("Owner")#slurp
index 2242c2f..8d8b8f6 100644 (file)
@@ -31,6 +31,13 @@ VM List
 $errorRow('name', $err)
 #end filter
        <tr>
+         <td>Description</td>
+         <td><textarea name="description" rows="4" cols="60">$defaults.description</textarea></td>
+       </tr>
+#filter None
+$errorRow('description', $err)
+#end filter
+       <tr>
          <td>Memory</td>
          <td><input type="text" name="memory" value="$defaults.memory" size=3/> MiB ($max_memory max)</td>
        </tr>
@@ -135,7 +142,7 @@ $has_vnc[$machine]
 #end filter
 #end if
 </td>
-       <td>
+       <td rowspan="2">
          <form action="command" method="post">
            <input type="hidden" name="back" value="list"/>
            <input type="hidden" name="machine_id"
@@ -146,6 +153,9 @@ $has_vnc[$machine]
          </form>
        </td>
       </tr>
+      <tr>
+        <td colspan="7" style="padding-left: 1em; color: #666">$machine.description</td>
+      </tr>
 #end def
 
 #def machineList($machines)
index 37080bc..dc0fd8c 100644 (file)
@@ -17,7 +17,7 @@ MAX_VMS_TOTAL = 10
 MAX_VMS_ACTIVE = 4
 
 class Validate:
-    def __init__(self, username, state, machine_id=None, name=None, owner=None,
+    def __init__(self, username, state, machine_id=None, name=None, description=None, owner=None,
                  admin=None, contact=None, memory=None, disksize=None,
                  vmtype=None, cdrom=None, clone_from=None, strict=False):
         # XXX Successive quota checks aren't a good idea, since you
@@ -28,6 +28,8 @@ class Validate:
         if strict:
             if name is None:
                 raise InvalidInput('name', name, "You must provide a machine name.")
+            if description is None:
+                raise InvalidInput('description', description, "You must provide a description.")
             if memory is None:
                 raise InvalidInput('memory', memory, "You must provide a memory size.")
             if disksize is None:
@@ -49,6 +51,9 @@ class Validate:
         name = testName(username, name, machine)
         if name is not None:
             self.name = name
+        description = testDescription(username, description, machine)
+        if description is not None:
+            self.description = description
         if memory is not None:
             self.memory = validMemory(self.owner, state, memory, machine,
                                       on=not created_new)
@@ -269,6 +274,11 @@ def testName(user, name, machine=None):
         return name
     raise InvalidInput('name', name, "Name is already taken.")
 
+def testDescription(user, description, machine=None):
+    if description is None or description.strip() == '':
+        return None
+    return description.strip()
+
 def testHostname(user, hostname, machine):
     for nic in machine.nics:
         if hostname == nic.hostname: