Changeset 438 for trunk/packages


Ignore:
Timestamp:
Apr 21, 2008, 7:22:21 PM (17 years ago)
Author:
ecprice
Message:

Remove extraneous whitespace and add documentation

File:
1 edited

Legend:

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

    r437 r438  
    6060def helppopup(subj):
    6161    """Return HTML code for a (?) link to a specified help topic"""
    62     return ('<span class="helplink"><a href="help?subject=' + subj + 
    63             '&amp;simple=true" target="_blank" ' + 
     62    return ('<span class="helplink"><a href="help?subject=' + subj +
     63            '&amp;simple=true" target="_blank" ' +
    6464            'onclick="return helppopup(\'' + subj + '\')">(?)</a></span>')
    6565
     
    143143        raise InvalidInput('name', name,
    144144                           "Name already exists.")
    145    
     145
    146146    owner = validation.testOwner(user, fields.getfirst('owner'))
    147147
    148148    memory = fields.getfirst('memory')
    149149    memory = validation.validMemory(owner, memory, on=True)
    150    
     150
    151151    disk_size = fields.getfirst('disk')
    152152    disk_size = validation.validDisk(owner, disk_size)
     
    162162    if clone_from and clone_from != 'ice3':
    163163        raise CodeError("Invalid clone image '%s'" % clone_from)
    164    
     164
    165165    return dict(contact=user, name=name, memory=memory, disk_size=disk_size,
    166166                owner=owner, machine_type=vm_type, cdrom=cdrom, clone_from=clone_from)
     
    187187
    188188def getListDict(user):
     189    """Gets the list of local variables used by list.tmpl."""
    189190    machines = g.machines
    190191    checkpoint.checkpoint('Got my machines')
     
    229230    checkpoint.checkpoint('Got list dict')
    230231    return templates.list(searchList=[d])
    231            
     232
    232233def vnc(user, fields):
    233234    """VNC applet page.
     
    241242
    242243    -t nat -A PREROUTING -s ! 18.181.0.60 -i eth1 -p tcp -m tcp \
    243       --dport 10003 -j DNAT --to-destination 18.181.0.60:10003 
     244      --dport 10003 -j DNAT --to-destination 18.181.0.60:10003
    244245    -t nat -A POSTROUTING -d 18.181.0.60 -o eth1 -p tcp -m tcp \
    245       --dport 10003 -j SNAT --to-source 18.187.7.142 
     246      --dport 10003 -j SNAT --to-source 18.187.7.142
    246247    -A FORWARD -d 18.181.0.60 -i eth1 -o eth1 -p tcp -m tcp \
    247248      --dport 10003 -j ACCEPT
     
    251252    """
    252253    machine = validation.testMachineId(user, fields.getfirst('machine_id'))
    253    
     254
    254255    TOKEN_KEY = "0M6W0U1IXexThi5idy8mnkqPKEq1LtEnlK/pZSn0cDrN"
    255256
     
    264265    token = cPickle.dumps(token)
    265266    token = base64.urlsafe_b64encode(token)
    266    
     267
    267268    status = controls.statusInfo(machine)
    268269    has_vnc = hasVnc(status)
    269    
     270
    270271    d = dict(user=user,
    271272             on=status,
     
    277278
    278279def getHostname(nic):
     280    """Find the hostname associated with a NIC.
     281
     282    XXX this should be merged with the similar logic in DNS and DHCP.
     283    """
    279284    if nic.hostname and '.' in nic.hostname:
    280285        return nic.hostname
     
    318323    for disk in machine.disks:
    319324        name = disk.guest_device_name
    320         disk_fields.extend([(x % name, y % name) for x, y in 
     325        disk_fields.extend([(x % name, y % name) for x, y in
    321326                            disk_fields_template])
    322327        data_dict['%s_size' % name] = "%0.1f GiB" % (disk.size / 1024.)
     
    353358
    354359def modifyDict(user, fields):
     360    """Modify a machine as specified by CGI arguments.
     361
     362    Return a list of local variables for modify.tmpl.
     363    """
    355364    olddisk = {}
    356365    transaction = ctx.current.create_transaction()
     
    370379            memory = validation.validMemory(user, memory, machine, on=False)
    371380            machine.memory = memory
    372  
     381
    373382        disksize = validation.testDisk(user, fields.getfirst('disk'))
    374383        if disksize is not None:
     
    379388                disk.size = disksize
    380389                ctx.current.save(disk)
    381        
     390
    382391        if owner is not None:
    383392            machine.owner = owner
     
    388397        if contact is not None:
    389398            machine.contact = contact
    390            
     399
    391400        ctx.current.save(machine)
    392401        transaction.commit()
     
    401410                command=command,
    402411                machine=machine)
    403    
     412
    404413def modify(user, fields):
    405414    """Handler for modifying attributes of a machine."""
     
    420429    info_dict['result'] = result
    421430    return templates.info(searchList=[info_dict])
    422    
     431
    423432
    424433def helpHandler(user, fields):
     
    426435    simple = fields.getfirst('simple')
    427436    subjects = fields.getlist('subject')
    428    
     437
    429438    help_mapping = dict(paravm_console="""
    430439ParaVM machines do not support local console access over VNC.  To
     
    461470"""
    462471                   )
    463    
     472
    464473    if not subjects:
    465474        subjects = sorted(help_mapping.keys())
    466        
     475
    467476    d = dict(user=user,
    468477             simple=simple,
    469478             subjects=subjects,
    470479             mapping=help_mapping)
    471    
     480
    472481    return templates.help(searchList=[d])
    473    
     482
    474483
    475484def badOperation(u, e):
     485    """Function called when accessing an unknown URI."""
    476486    raise CodeError("Unknown operation")
    477487
    478488def infoDict(user, machine):
     489    """Get the variables used by info.tmpl."""
    479490    status = controls.statusInfo(machine)
    480491    checkpoint.checkpoint('Getting status info')
     
    523534    nic_fields = getNicInfo(machine_info, machine)
    524535    nic_point = display_fields.index('NIC_INFO')
    525     display_fields = (display_fields[:nic_point] + nic_fields + 
     536    display_fields = (display_fields[:nic_point] + nic_fields +
    526537                      display_fields[nic_point+1:])
    527538
    528539    disk_fields = getDiskInfo(machine_info, machine)
    529540    disk_point = display_fields.index('DISK_INFO')
    530     display_fields = (display_fields[:disk_point] + disk_fields + 
     541    display_fields = (display_fields[:disk_point] + disk_fields +
    531542                      display_fields[disk_point+1:])
    532    
     543
    533544    main_status['memory'] += ' MiB'
    534545    for field, disp in display_fields:
     
    584595
    585596def printHeaders(headers):
     597    """Print a dictionary as HTTP headers."""
    586598    for key, value in headers.iteritems():
    587599        print '%s: %s' % (key, value)
     
    594606    return username
    595607
    596 def main(operation, user, fields):   
     608def main(operation, user, fields):
    597609    start_time = time.time()
    598610    fun = mapping.get(operation, badOperation)
Note: See TracChangeset for help on using the changeset viewer.