Changeset eee2b2e


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

Location:
fedd
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • fedd/fedd_config_file.py

    rea0a821 reee2b2e  
    2929            "create_experiment_cert_file", "create_experiment_cert_pwd",
    3030            "create_experiment_trusted_certs", "federation_script_dir",
    31             "ssh_pubkey_file")
     31            "ssh_pubkey_file", "experiment_state_file")
     32    id_list_attrs = ("restricted",)
    3233
    3334
     
    4344        for a in config_file.emulab_attrs + config_file.id_attrs:
    4445            setattr(self, a, None)
     46       
     47        for a in config_file.id_list_attrs:
     48            setattr(self, a, [])
    4549
    4650        self.attrs = { }
     
    4852        self.fedid_default = "user"
    4953        self.access = { }
    50         self.restricted = []
    5154
    5255        if config:
     
    144147                '|'.join(config_file.emulab_attrs + config_file.id_attrs) + \
    145148                '):\s*(.*)', re.IGNORECASE)
     149        list_re = re.compile("(" + '|'.join(config_file.id_list_attrs) + \
     150                "):\s*(.*)", re.IGNORECASE)
    146151        attr_re = re.compile('attribute:\s*([\._\-a-z0-9]+)\s+value:\s*(.*)',
    147152                re.IGNORECASE)
     
    150155                access_name + '\s*\)', re.IGNORECASE)
    151156        trustfile_re = re.compile("trustfile:\s*(.*)", re.IGNORECASE)
    152         restricted_re = re.compile("restricted:\s*(.*)", re.IGNORECASE)
    153157
    154158        def parse_name(n):
     
    177181                continue
    178182
     183            # List attributes
     184            m = list_re.match(line)
     185            if m != None:
     186                attr, val = m.group(1,2)
     187                l = getattr(self, attr.lower())
     188                l.append(val)
     189                continue
     190
     191
    179192            # Extended (attribute: x value: y) attribute line
    180193            m = attr_re.match(line)
     
    206219            if m != None:
    207220                self.read_trust(m.group(1))
    208                 continue
    209             # Restricted node types
    210 
    211             m = restricted_re.match(line)
    212             if m != None:
    213                 self.restricted.append(m.group(1))
    214221                continue
    215222
  • 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.