Ignore:
Timestamp:
Mar 7, 2010 8:01:52 AM (14 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
Children:
062b991
Parents:
d101c8c
Message:

Add slice/sliver renewal

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/federation/protogeni_access.py

    rd101c8c rdd3e38b  
    44import stat # for chmod constants
    55import re
     6import time
    67import string
    78import copy
     
    7677        self.staging_host = config.get("access", "staging_host") \
    7778                or "ops.emulab.net"
     79
     80        self.renewal_interval = config.get("access", "renewal") or (3 * 60 * 60)
     81        self.renewal_interval = int(self.renewal_interval)
    7882
    7983        self.ch_url = config.get("access", "ch_url")
     
    131135        self.start_segment = proxy_protogeni_segment.start_segment
    132136        self.stop_segment = proxy_protogeni_segment.stop_segment
     137        self.renew_segment = proxy_protogeni_segment.renew_segment
    133138
    134139        self.call_SetValue = service_caller('SetValue')
    135140        self.call_GetValue = service_caller('GetValue')
     141
     142        self.RenewSlices()
    136143
    137144        self.soap_services = {\
     
    212219
    213220            # Access line (t, p, u) -> (a, pw) line
    214             # XXX: you are here
    215221            m = access_re.match(line)
    216222            if m != None:
     
    11141120        stopper(self, user, staging, slice_cred, cf, cpw)
    11151121        return { 'allocID': req['allocID'] }
     1122
     1123    def RenewSlices(self):
     1124        self.log.info("Scanning for slices to renew")
     1125        self.state_lock.acquire()
     1126        aids = self.allocation.keys()
     1127        self.state_lock.release()
     1128
     1129        for aid in aids:
     1130            self.state_lock.acquire()
     1131            if self.allocation.has_key(aid):
     1132                name = self.allocation[aid].get('slice_name', None)
     1133                scred = self.allocation[aid].get('slice_credential', None)
     1134                cf, user, ssh_key, cpw = self.allocation[aid]['credentials']
     1135            else:
     1136                name = None
     1137                scred = None
     1138            self.state_lock.release()
     1139
     1140            # There's a ProtoGENI slice associated with the segment; renew it.
     1141            if name and scred:
     1142                renewer = self.renew_segment(log=self.log,
     1143                        debug=self.create_debug, keyfile=ssh_key,
     1144                        cm_url = self.cm_url, sa_url = self.sa_url,
     1145                        ch_url = self.ch_url)
     1146                new_scred = renewer(name, scred, self.renewal_interval, cf, cpw)
     1147                if new_scred:
     1148                    self.log.info("Slice %s renewed until %s GMT" % \
     1149                            (name, time.asctime(time.gmtime(\
     1150                                time.time()+self.renewal_interval))))
     1151                    self.state_lock.acquire()
     1152                    if self.allocation.has_key(aid):
     1153                        self.allocation[aid]['slice_credential'] = new_scred
     1154                    self.state_lock.release()
     1155                else:
     1156                    self.log.info("Failed to renew slice %s " % name)
     1157
     1158        # Let's do this all again soon.  (4 tries before the slices time out)   
     1159        t = Timer(self.renewal_interval/4, self.RenewSlices)
     1160        t.start()
Note: See TracChangeset for help on using the changeset viewer.