Ignore:
Timestamp:
Oct 6, 2008 4:00:19 PM (16 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master, version-1.30, version-2.00, version-3.01, version-3.02
Children:
a97394b
Parents:
ea0a821
Message:

save state

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/fedd_experiment_control.py

    rea0a821 reee2b2e  
    1616import tempfile
    1717import copy
     18import pickle
    1819
    1920import traceback
     
    113114        self.trusted_certs = None
    114115
    115         if config.create_experiment_cert_file:
    116             self.cert_file = config.create_experiment_cert_file
    117             self.cert_pwd = config.create_experiment_cert_pwd
    118         if config.create_experiment_trusted_certs:
    119             self.trusted_certs = config.create_experiment_trusted_certs
    120 
    121         if config.proxy_cert_file:
    122             if not self.cert_file:
    123                 self.cert_file = config.proxy_cert_file
    124                 self.cert_pwd = config.proxy_cert_pwd
    125         if config.proxy_trusted_certs:
    126             if not self.trusted_certs:
    127                 self.trusted_certs = config.proxy_trusted_certs
    128 
    129         if config.cert_file:
    130             if not self.cert_file:
    131                 self.cert_file = config.cert_file
    132                 self.cert_pwd = config.cert_pwd
    133         if config.trusted_certs:
    134             if not self.trusted_certs:
    135                 self.trusted_certs = config.trusted_certs
     116        # Walk through the various relevant certificat specifying config
     117        # attributes until the local certificate attributes can be resolved.
     118        # The walk is from omst specific to most general specification.
     119        for p in ("create_experiment_", "proxy_", ""):
     120            filen = "%scert_file" % p
     121            pwn = "%scert_pwd" % p
     122            trustn = "%strusted_certs" % p
     123
     124            if getattr(config, filen, None):
     125                if not self.cert_file:
     126                    self.cert_file = getattr(config, filen, None)
     127                    self.cert_pwd = getattr(config, pwn, None)
     128
     129            if getattr(config, trustn, None):
     130                if not self.trusted_certs:
     131                    self.trusted_certs = getattr(config, trustn, None)
    136132
    137133        self.exp_stem = "fed-stem"
     
    150146        self.ssh_type = "rsa"
    151147        self.state = { }
     148        self.state_filename = config.experiment_state_file
    152149        self.tclsh = "/usr/local/bin/otclsh"
    153150        self.tcl_splitter = "/usr/testbed/lib/ns2ir/parse.tcl"
     
    178175                raise service_error(service_error.internal,
    179176                        "Cannot read sshpubkey")
     177
     178        # Grab saved state
     179        if self.state_filename:
     180            self.read_state()
    180181
    181182        # Confirm federation scripts in the right place
     
    250251        s.close()
    251252        d.close()
     253
     254    def write_state(self):
     255        if os.access(self.state_filename, os.W_OK):
     256            self.copy_file(self.state_filename, \
     257                    "%s.bak" % self.state_filename)
     258        try:
     259            f = open(self.state_filename, 'w')
     260            pickle.dump(self.state, f)
     261        except IOError, e:
     262            print >>sys.stderr, "Can't write file %s: %s" % \
     263                    (self.state_filename, e)
     264        except pickle.PicklingError, e:
     265            print >>sys.stderr, "Pickling problem: %s" % e
     266
     267    def read_state(self):
     268        try:
     269            f = open(self.state_filename, "r")
     270            self.state = pickle.load(f)
     271        except IOError, e:
     272            print >>sys.stderr, "Can't open %s: %s" % \
     273                    (self.state_filename, e)
     274        except pickle.UnpicklingError, e:
     275            print >>sys.stderr, "Unpickling failed: %s" % e
    252276
    253277    def scp_file(self, file, user, host, dest=""):
     
    13811405                }
    13821406        self.state[eid] = self.state[expid]
     1407        if self.state_filename: self.write_state()
    13831408        return resp
    13841409
     
    14861511
    14871512        if fed_exp:
     1513            ids = []
     1514            #  experimentID is a list of dicts that are self-describing
     1515            #  identifiers.  This finds all the fedids and localnames - the
     1516            #  keys of self.state - and puts them into ids.
     1517            for id in fed_exp.get('experimentID', []):
     1518                if id.has_key('fedid'): ids.append(id['fedid'])
     1519                if id.has_key('localname'): ids.append(id['localname'])
     1520
    14881521            # Construct enough of the tbparams to make the stop_segment calls
    14891522            # work
     
    15161549            for tb in tbparams.keys():
    15171550                self.stop_segment(tb, tbparams[tb]['eid'], tbparams)
     1551
     1552            for id in ids:
     1553                if self.state.has_key(id): del self.state[id]
     1554
     1555            if self.state_filename: self.write_state()
    15181556            return { 'experiment': exp }
    15191557        else:
Note: See TracChangeset for help on using the changeset viewer.