Ignore:
Timestamp:
May 15, 2008, 9:55:17 PM (16 years ago)
Author:
ecprice
Message:

Use joins, new xmlist.py

File:
1 edited

Legend:

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

    r522 r535  
    1212import re
    1313import cache_acls
     14import cPickle
    1415
    1516# ... and stolen from xend/uuid.py
     
    114115        machine.type_id = machine_type.type_id
    115116        ctx.current.save(machine)
    116         disk = Disk(machine_id=machine.machine_id, 
     117        disk = Disk(machine_id=machine.machine_id,
    117118                    guest_device_name='hda', size=disk_size)
    118119        open_nics = NIC.select_by(machine_id=None)
     
    123124        nic.machine_id = machine.machine_id
    124125        nic.hostname = name
    125         ctx.current.save(nic)   
     126        ctx.current.save(nic)
    126127        ctx.current.save(disk)
    127128        cache_acls.refreshMachine(machine)
     
    137138    return machine
    138139
    139 def getUptimes(machines=None):
    140     """Return a dictionary mapping machine names to uptime strings"""
    141     value_string = remctl('web', 'listvms')
    142     lines = value_string.splitlines()
    143     d = {}
    144     for line in lines:
    145         lst = line.split()
    146         name, id = lst[:2]
    147         uptime = ' '.join(lst[2:])
    148         d[name] = uptime
    149     ans = {}
    150     for m in machines:
    151         ans[m] = d.get(m.name)
    152     return ans
     140def getList(machines):
     141    """Return a dictionary mapping machine  to dicts."""
     142    value_string = remctl('web', 'listvms', '--pickle')
     143    value_dict = cPickle.loads(value_string)
     144
     145    d = dict((m, value_dict[m.name]) for m in machines if m.name in value_dict)
     146    return d
    153147
    154148def parseStatus(s):
Note: See TracChangeset for help on using the changeset viewer.