Changeset 161 for trunk


Ignore:
Timestamp:
Oct 9, 2007, 10:08:20 PM (17 years ago)
Author:
ecprice
Message:

Add support for
(A) modifying VM names, memory, disksize
(B) transferring ownership, hostname

Has issues with multiple disks/nics because of current interface.

(tabbott is the real author here)

Location:
trunk/web/templates
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/web/templates/info.tmpl

    r153 r161  
    6363  <input type="hidden" name="machine_id" value="$machine.machine_id"/>
    6464  <table>
    65     <tr><td>Owner:</td><td><input type="text" name="owner", value="$machine.owner"/></td></tr>
     65    <tr><td>Owner:</td><td><input type="text" name="owner", value="$machine.owner"/></td>
     66        <td>NOTE: The Owner must the name of a locker that you administer</td></tr>
    6667    <tr><td>Contact email:</td><td><input type="text" name="contact" value="$machine.contact"/></td></tr>
     68    <tr><td>Machine Name:</td><td><input type="text" name="name" value="$machine.name"/></td></tr>
    6769#if $machine.nics
    68     <tr><td>Hostname:</td><td><input type="text" name="hostname" value="$machine.nics[0].hostname"/>.servers.csail.mit.edu</td></tr>
     70    <tr><td>Hostname:</td><td><input type="text" name="hostname" value="$machine.nics[0].hostname"/>.servers.csail.mit.edu</td>
     71        <td>NOTE: The hostname must being with "Owner_".</td></tr>
    6972#end if
    7073#if not $on
  • trunk/web/templates/main.py

    r159 r161  
    1414import datetime
    1515import StringIO
     16import getafsgroups
    1617
    1718sys.stderr = StringIO.StringIO()
     
    118119    if user.username == 'moo':
    119120        return True
    120     return machine.owner == user.username
     121    return getafsgroups.checkLockerOwner(user.username,machine.owner)
    121122
    122123def error(op, user, fields, err, emsg):
     
    568569
    569570def testOwner(user, owner, machine=None):
    570     if owner != user.username:
     571    if not getafsgroups.checkLockerOwner(user.username, owner):
    571572        raise InvalidInput('owner', owner,
    572573                           "Invalid")
     
    579580    return contact
    580581
     582def testDisk(user, disksize, machine=None):
     583    return disksize
     584
     585def testName(user, name, machine=None):
     586    return name
     587
    581588def testHostname(user, hostname, machine):
    582589    for nic in machine.nics:
    583590        if hostname == nic.hostname:
    584591            return hostname
     592    # check if doesn't already exist
     593    if NIC.select_by(hostname=hostname) == []:
     594        return hostname
    585595    raise InvalidInput('hostname', hostname,
    586596                       "Different from before")
     
    590600    """Handler for modifying attributes of a machine."""
    591601    #XXX not written yet
    592     machine = testMachineId(user, fields.getfirst('machine_id'))
    593     owner = testOwner(user, fields.getfirst('owner'), machine)
    594     contact = testContact(user, fields.getfirst('contact'))
    595     hostname = testHostname(user, fields.getfirst('hostname'),
     602
     603    transaction = ctx.current.create_transaction()
     604    try:
     605        machine = testMachineId(user, fields.getfirst('machine_id'))
     606        owner = testOwner(user, fields.getfirst('owner'), machine)
     607        contact = testContact(user, fields.getfirst('contact'))
     608        hostname = testHostname(owner, fields.getfirst('hostname'),
    596609                            machine)
    597     ram = fields.getfirst('memory')
    598     if ram is not None:
    599         ram = validMemory(user, ram, machine)
    600     disk = testDisk(user, fields.getfirst('disk'))
    601     if disk is not None:
    602         disk = validDisk(user, disk, machine)
    603 
    604    
     610        name = testName(user, fields.getfirst('name'))
     611        oldname = machine.name
     612        olddisk = {}
     613
     614        memory = fields.getfirst('memory')
     615        if memory is not None:
     616            memory = validMemory(user, memory, machine)
     617        if memory != machine.memory:
     618            machine.memory = memory
     619
     620        disksize = testDisk(user, fields.getfirst('disk'))
     621        if disksize is not None:
     622            disksize = validDisk(user, disksize, machine)
     623       
     624        for disk in machine.disks:
     625            disk.size = disksize
     626            olddisk[disk.guest_device_name] = disk.size
     627            ctx.current.save(disk)
     628       
     629        # XXX all NICs get same hostname on change?  Interface doesn't support more.
     630        for nic in machine.nics:
     631            nic.hostname = hostname
     632            ctx.current.save(nic)
     633
     634        if owner != machine.owner:
     635            machine.owner = owner
     636        if name != machine.name:
     637            machine.name = name
     638           
     639        ctx.current.save(machine)
     640        transaction.commit()
     641    except:
     642        transaction.rollback()
     643    remctl("web", "moveregister", oldname, name)
     644    for disk in machine.disks:
     645        # XXX all disks get the same size on change?  Interface doesn't support more.
     646        if disk.size != olddisk[disk.guest_device_name]:
     647            remctl("web", "lvresize", oldname, disk.guest_device_name, str(disk.size))
     648        if oldname != name:
     649            remctl("web", "lvrename", oldname, disk.guest_device_name, name)
     650    d = dict(user=user,
     651             command="modify",
     652             machine=machine)
     653    return Template(file="command.tmpl", searchList=[d, global_dict])   
     654
    605655
    606656def help(user, fields):
Note: See TracChangeset for help on using the changeset viewer.