Index: fedd/federation/access.py
===================================================================
--- fedd/federation/access.py	(revision 1da6a2319ed0dba65680376213f874f1bd42d5db)
+++ fedd/federation/access.py	(revision 5ae3857d794c318c83d4c8aadae1660dcec2aa11)
@@ -67,4 +67,6 @@
 	self.certdir = config.get("access","certdir")
 	self.ssh_privkey_file = config.get("access","ssh_privkey_file")
+	self.create_debug = config.getboolean("access", "create_debug")
+	print self.create_debug
 
         self.attrs = { }
@@ -116,4 +118,5 @@
             'ReleaseAccess': soap_handler("ReleaseAccess", self.ReleaseAccess),
             'StartSegment': soap_handler("StartSegment", self.StartSegment),
+            'TerminateSegment': soap_handler("TerminateSegment", self.TerminateSegment),
             }
         self.xmlrpc_services =  {\
@@ -122,6 +125,7 @@
             'ReleaseAccess': xmlrpc_handler('ReleaseAccess',
                 self.ReleaseAccess),
-            'StartSegment': xmlrpc_handler('StartSegment',
-                self.StartSegment),
+            'StartSegment': xmlrpc_handler("StartSegment", self.StartSegment),
+            'TerminateSegment': xmlrpc_handler('TerminateSegment',
+                self.TerminateSegment),
             }
 
@@ -1083,22 +1087,18 @@
     class stop_segment(proxy_emulab_segment):
         def __init__(self, log=None, keyfile=None, debug=False):
-            experiment_control_local.emulab_segment.__init__(self,
+            access.proxy_emulab_segment.__init__(self,
                     log=log, keyfile=keyfile, debug=debug)
 
-        def __call__(self, tb, eid, tbparams):
+        def __call__(self, parent, user, pid, eid):
             """
             Stop a sub experiment by calling swapexp on the federant
             """
-            user = tbparams[tb]['user']
-            host = "%s%s" % (tbparams[tb]['host'], tbparams[tb]['domain'])
-            pid = tbparams[tb]['project']
-
-            self.log.info("[stop_segment]: Stopping %s on %s" % (eid, tb))
+            host = "%s%s" % (parent.ops, parent.domain)
+            self.log.info("[stop_segment]: Stopping %s" % eid)
             rv = False
             try:
                 # Clean out tar files: we've gone over quota in the past
-                self.ssh_cmd(user, host, "rm -rf /proj/%s/rpms/%s" % (pid, eid))
-                self.ssh_cmd(user, host, "rm -rf /proj/%s/tarfiles/%s" % \
-                        (pid, eid))
+                self.ssh_cmd(user, host, "rm -rf /proj/%s/software/%s" % \
+			(pid, eid))
                 rv = self.ssh_cmd(user, host,
                         "/usr/testbed/bin/swapexp -w %s %s out" % (pid, eid))
@@ -1335,4 +1335,6 @@
 		proj = self.allocation[aid].get('sproject', None)
 	    user = self.allocation[aid].get('user', None)
+	    self.allocation[aid]['experiment'] = ename
+	    self.write_state()
 	self.state_lock.release()
 
@@ -1351,6 +1353,45 @@
 	self.generate_ns2(topo, expfile, 
 		"/proj/%s/software/%s/" % (proj, ename), master)
-	starter = self.start_segment(keyfile=self.ssh_privkey_file, debug=False)
+	starter = self.start_segment(keyfile=self.ssh_privkey_file, debug=self.create_debug)
 	starter(self, ename, proj, user, expfile, tmpdir)
 
 	return { 'allocID': req['allocID'] }
+
+    def TerminateSegment(self, req, fid):
+	print "In terminate"
+	try:
+	    req = req['TerminateSegmentRequestBody']
+	except KeyError:
+	    raise service_error(server_error.req, "Badly formed request")
+
+	auth_attr = req['allocID']['fedid']
+	aid = "%s" % auth_attr
+	attrs = req.get('fedAttr', [])
+	print "in terminate %s" % auth_attr
+	if not self.auth.check_attribute(fid, auth_attr):
+	    print "access denied"
+	    raise service_error(service_error.access, "Access denied")
+
+	self.state_lock.acquire()
+	if self.allocation.has_key(aid):
+	    proj = self.allocation[aid].get('project', None)
+	    if not proj: 
+		proj = self.allocation[aid].get('sproject', None)
+	    user = self.allocation[aid].get('user', None)
+	    ename = self.allocation[aid].get('experiment', None)
+	self.state_lock.release()
+
+	if not proj:
+	    raise service_error(service_error.internal, 
+		    "Can't find project for %s" % aid)
+
+	if not user:
+	    raise service_error(service_error.internal, 
+		    "Can't find creation user for %s" % aid)
+	if not ename:
+	    raise service_error(service_error.internal, 
+		    "Can't find experiment name for %s" % aid)
+	stopper = self.stop_segment(keyfile=self.ssh_privkey_file, debug=self.create_debug)
+	stopper(self, user, proj, ename)
+	print { 'allocID': req['allocID'] }
+	return { 'allocID': req['allocID'] }
