source: fedd/fedd/split.py @ f069052

axis_examplecompt_changesinfo-opsversion-1.30version-2.00version-3.01version-3.02
Last change on this file since f069052 was f069052, checked in by Ted Faber <faber@…>, 15 years ago

Two changes. Get allow_any_CA checking to work (i.e., self signed certs or
certs signed by an unknown entity) and put more of the ZSI-dependent stuff into
the hidden parts or remote_services. Now those routines will find all the
relevant classes and part names from the naming conventions.

  • Property mode set to 100644
File size: 3.5 KB
Line 
1#!/usr/local/bin/python
2
3import os,sys
4import subprocess
5import tempfile
6import logging
7
8from util import *
9from fedid import fedid
10from remote_service import xmlrpc_handler, soap_handler
11from service_error import *
12
13
14class nullHandler(logging.Handler):
15    def emit(self, record): pass
16
17fl = logging.getLogger("fedd.splitter")
18fl.addHandler(nullHandler())
19
20class split_local:
21    def __init__(self, config=None, auth=None):
22        """
23        Intialize the various attributes, most from the config object
24        """
25        if config.has_section("splitter"):
26            self.debug = config.getboolean("splitter", "debug")
27            self.muxmax = config.getint("splitter", "muxmax", 3)
28            self.tclsh = config.get("splitter", "tclsh", 
29                    "/usr/local/bin/otclsh")
30            self.tcl_splitter = config.get("splitter", "tcl_splitter",
31                    "/usr/testbed/lib/ns2ir/parse.tcl")
32        else:
33            self.debug = False
34            self.muxmax = 3
35            self.tclsh = "/usr/local/bin/otclsh"
36            self.tcl_splitter = "/usr/testbed/lib/ns2ir/parse.tcl"
37
38        self.log = logging.getLogger("fedd.splitter")
39        set_log_level(config, "splitter", self.log)
40        self.trace_file = sys.stderr
41
42        set_log_level(config, "splitter", self.log)
43        # Dispatch tables
44        self.soap_services = {\
45                'Ns2Split': soap_handler("Ns2Split", self.run_splitter),
46        }
47
48        self.xmlrpc_services = {\
49                'Ns2Split': xmlrpc_handler('Ns2Split', self.run_splitter),
50        }
51
52    def run_splitter(self, req, fid):
53        """
54        The external interface to experiment creation called from the
55        dispatcher.
56
57        Creates a working directory, splits the incoming description using the
58        splitter script and parses out the avrious subsections using the
59        lcasses above.  Once each sub-experiment is created, use pooled threads
60        to instantiate them and start it all up.
61        """
62        try:
63            tmpdir = tempfile.mkdtemp(prefix="split-")
64        except IOError:
65            raise service_error(service_error.internal, "Cannot create tmp dir")
66
67        tclfile = tmpdir + "/experiment.tcl"
68        pid = "dummy"
69        gid = "dummy"
70        eid = "dummy"
71
72        req = req.get('Ns2SplitRequestBody', None)
73        if not req:
74            raise service_error(service_error.req,
75                    "Bad request format (no Ns2SplitRequestBody)")
76        # The tcl parser needs to read a file so put the content into that file
77        descr=req.get('description', None)
78        if descr:
79            file_content=descr.get('ns2description', None)
80            if file_content:
81                try:
82                    f = open(tclfile, 'w')
83                    f.write(file_content)
84                    f.close()
85                except IOError:
86                    raise service_error(service_error.internal,
87                            "Cannot write temp experiment description")
88            else:
89                raise service_error(service_error.req, 
90                        "Only ns2descriptions supported")
91        else:
92            raise service_error(service_error.req, "No description")
93
94        master = req.get('master', None)
95        if master == None:
96            raise service_error(service_error.req, "No master testbed label")
97       
98        include_fedkit = req.get('include_fedkit', None)
99        if include_fedkit == None:
100            raise service_error(service_error.req, 
101                    "No federation kit inclusion directive")
102       
103       
104        tclcmd = [self.tclsh, self.tcl_splitter, '-s', '-x', 
105            str(self.muxmax), '-m', master]
106        if include_fedkit: tclcmd.append('-k')
107        tclcmd.extend([pid, gid, eid, tclfile])
108        self.log.debug("Calling splitter %s" % " ".join(tclcmd))
109        tclparser = subprocess.Popen(tclcmd, stdout=subprocess.PIPE)
110
111        out = ""
112        # Package up the split data
113        for line in tclparser.stdout:
114            out += line
115
116        # Walk up tmpdir, deleting as we go
117        for path, dirs, files in os.walk(tmpdir, topdown=False):
118            for f in files:
119                os.remove(os.path.join(path, f))
120            for d in dirs:
121                os.rmdir(os.path.join(path, d))
122        os.rmdir(tmpdir)
123
124        resp = { 'output' : out }
125
126        return resp
127
128
Note: See TracBrowser for help on using the repository browser.