Ignore:
Timestamp:
Nov 28, 2011 7:34:11 PM (13 years ago)
Author:
Ted Faber <faber@…>
Branches:
compt_changes, info-ops, master
Children:
ec3aa4d
Parents:
45e880d
Message:

InfoSegment? to emulab access controllers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/federation/experiment_info.py

    r45e880d r6e33086  
    22
    33import copy
     4from datetime import datetime, timedelta
     5from numbers import Number
    46
    57class allocation_info:
     
    3840        self.log = []
    3941        self.alloc = { }
     42        self.last_update = datetime.now()
    4043
    4144    def add_allocation(self, a):
     
    4750    def get_all_allocations(self):
    4851        return self.alloc.values()
     52
     53    def updated(self):
     54        self.last_update = datetime.now()
     55
     56    def older_than(self, secs=None, dt=None):
     57        """
     58        If the last update of this info was more than secs seconds ago, or
     59        before dt (a datetime), return True.  If both secs and dt or neither is
     60        given return False.  If the last update time is completelt unknown
     61        (which should never happen) return True.
     62        """
     63        if self.last_update is None:
     64            return True
     65        elif dt is None and isinstance(secs, Number):
     66            return self.last_update + timedelta(seconds=secs) < datetime.now()
     67        elif secs is None and isinstance(dt, datetime):
     68            return self.last_update < dt
     69        else:
     70            return False
     71
    4972
    5073    def get_info(self):
Note: See TracChangeset for help on using the changeset viewer.