Ignore:
Timestamp:
Jun 18, 2008, 3:50:31 AM (17 years ago)
Author:
andersk
Message:

Add a description field.

Location:
trunk/packages/sipb-xen-www/code
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/sipb-xen-www/code/controls.py

    r589 r609  
    9393                        % (err, machine.name, cdtype))
    9494
    95 def createVm(username, state, owner, contact, name, memory, disksize, machine_type, cdrom, clone_from):
     95def createVm(username, state, owner, contact, name, description, memory, disksize, machine_type, cdrom, clone_from):
    9696    """Create a VM and put it in the database"""
    9797    # put stuff in the table
    9898    transaction = ctx.current.create_transaction()
    9999    try:
    100         validation.Validate(username, state, name=name, owner=owner, memory=memory, disksize=disksize/1024.)
     100        validation.Validate(username, state, name=name, description=description, owner=owner, memory=memory, disksize=disksize/1024.)
    101101        res = meta.engine.execute('select nextval('
    102102                                  '\'"machines_machine_id_seq"\')')
     
    105105        machine.machine_id = id
    106106        machine.name = name
     107        machine.description = description
    107108        machine.memory = memory
    108109        machine.owner = owner
  • trunk/packages/sipb-xen-www/code/main.py

    r607 r609  
    104104    autoinstall = ''
    105105    name = ''
     106    description = ''
    106107    type = 'linux-hvm'
    107108
     
    136137
    137138def parseCreate(username, state, fields):
    138     kws = dict([(kw, fields.getfirst(kw)) for kw in 'name owner memory disksize vmtype cdrom clone_from'.split()])
     139    kws = dict([(kw, fields.getfirst(kw)) for kw in 'name description owner memory disksize vmtype cdrom clone_from'.split()])
    139140    validate = validation.Validate(username, state, strict=True, **kws)
    140     return dict(contact=username, name=validate.name, memory=validate.memory,
     141    return dict(contact=username, name=validate.name, description=validate.description, memory=validate.memory,
    141142                disksize=validate.disksize, owner=validate.owner, machine_type=validate.vmtype,
    142143                cdrom=getattr(validate, 'cdrom', None),
     
    347348    transaction = ctx.current.create_transaction()
    348349    try:
    349         kws = dict([(kw, fields.getfirst(kw)) for kw in 'machine_id owner admin contact name memory vmtype disksize'.split()])
     350        kws = dict([(kw, fields.getfirst(kw)) for kw in 'machine_id owner admin contact name description memory vmtype disksize'.split()])
    350351        validate = validation.Validate(username, state, **kws)
    351352        machine = validate.machine
     
    372373        if hasattr(validate, 'name'):
    373374            machine.name = validate.name
     375        if hasattr(validate, 'description'):
     376            machine.description = validate.description
    374377        if hasattr(validate, 'admin') and validate.admin != machine.administrator:
    375378            machine.administrator = validate.admin
     
    489492     on_poweroff on_crash on_xend_start on_xend_stop bootloader""".split()
    490493    display_fields = [('name', 'Name'),
     494                      ('description', 'Description'),
    491495                      ('owner', 'Owner'),
    492496                      ('administrator', 'Administrator'),
     
    510514    machine_info = {}
    511515    machine_info['name'] = machine.name
     516    machine_info['description'] = machine.description
    512517    machine_info['type'] = machine.type.hvm and 'HVM' or 'ParaVM'
    513518    machine_info['owner'] = machine.owner
     
    544549    max_disk = validation.maxDisk(machine.owner, machine)
    545550    defaults = Defaults()
    546     for name in 'machine_id name administrator owner memory contact'.split():
     551    for name in 'machine_id name description administrator owner memory contact'.split():
    547552        setattr(defaults, name, getattr(machine, name))
    548553    defaults.type = machine.type.type_id
     
    613618             errorMessage=str(err), stderr=emsg, traceback=traceback)
    614619    details = templates.error_raw(searchList=[d])
    615     send_error_mail('xvm error on %s for %s: %s' % (op, username, err),
    616                     details)
    617620    d['details'] = details
    618621    return templates.error(searchList=[d])
  • trunk/packages/sipb-xen-www/code/templates/info.tmpl

    r572 r609  
    6666  <input type="hidden" name="machine_id" value="$defaults.machine_id"/>
    6767  <table>
     68    <tr><td>Description:</td><td colspan="2"><textarea name="description" rows="4" cols="60">$defaults.description</textarea></td></tr>
    6869    <tr><td>Owner#slurp
    6970#filter None
  • trunk/packages/sipb-xen-www/code/templates/list.tmpl

    r572 r609  
    3030#filter None
    3131$errorRow('name', $err)
     32#end filter
     33        <tr>
     34          <td>Description</td>
     35          <td><textarea name="description" rows="4" cols="60">$defaults.description</textarea></td>
     36        </tr>
     37#filter None
     38$errorRow('description', $err)
    3239#end filter
    3340        <tr>
     
    136143#end if
    137144</td>
    138         <td>
     145        <td rowspan="2">
    139146          <form action="command" method="post">
    140147            <input type="hidden" name="back" value="list"/>
     
    146153          </form>
    147154        </td>
     155      </tr>
     156      <tr>
     157        <td colspan="7" style="padding-left: 1em; color: #666">$machine.description</td>
    148158      </tr>
    149159#end def
  • trunk/packages/sipb-xen-www/code/validation.py

    r584 r609  
    1818
    1919class Validate:
    20     def __init__(self, username, state, machine_id=None, name=None, owner=None,
     20    def __init__(self, username, state, machine_id=None, name=None, description=None, owner=None,
    2121                 admin=None, contact=None, memory=None, disksize=None,
    2222                 vmtype=None, cdrom=None, clone_from=None, strict=False):
     
    2929            if name is None:
    3030                raise InvalidInput('name', name, "You must provide a machine name.")
     31            if description is None:
     32                raise InvalidInput('description', description, "You must provide a description.")
    3133            if memory is None:
    3234                raise InvalidInput('memory', memory, "You must provide a memory size.")
     
    5052        if name is not None:
    5153            self.name = name
     54        description = testDescription(username, description, machine)
     55        if description is not None:
     56            self.description = description
    5257        if memory is not None:
    5358            self.memory = validMemory(self.owner, state, memory, machine,
     
    270275    raise InvalidInput('name', name, "Name is already taken.")
    271276
     277def testDescription(user, description, machine=None):
     278    if description is None or description.strip() == '':
     279        return None
     280    return description.strip()
     281
    272282def testHostname(user, hostname, machine):
    273283    for nic in machine.nics:
Note: See TracChangeset for help on using the changeset viewer.