#!/usr/local/bin/python import os,sys import stat # for chmod constants import re import random import string import copy import pickle import logging import subprocess import traceback from threading import * from M2Crypto.SSL import SSLError from emulab_access import access as emulab_access from util import * from deter import fedid, generate_fedid from authorizer import authorizer, abac_authorizer from service_error import service_error from remote_service import xmlrpc_handler, soap_handler, service_caller from proof import proof as access_proof import httplib import tempfile from urlparse import urlparse from deter import topdl import list_log import containers_segment # Make log messages disappear if noone configures a fedd logger class nullHandler(logging.Handler): def emit(self, record): pass fl = logging.getLogger("fedd.access") fl.addHandler(nullHandler()) class access(emulab_access): """ The implementation of access control based on mapping users to projects. Users can be mapped to existing projects or have projects created dynamically. This implements both direct requests and proxies. """ max_name_len = 19 def __init__(self, config=None, auth=None): """ Initializer. Pulls parameters out of the ConfigParser's access section. """ emulab_access.__init__(self, config, auth) self.containerize = config.get('access', 'containerize') # Segment creation is where most of the differences are. self.start_segment = containers_segment.start_segment self.stop_segment = containers_segment.stop_segment self.info_segment = containers_segment.info_segment # These are subroutines for StartSegment def generate_ns2(self, topo, expfn, softdir, connInfo): """ Benito is expecting a topdl file, so this routine is misnamed. It does clean up the topdl, removing elements containers doesn't understand and writing out the file. """ # Main line of generate_ns2 t = topo.clone() # Weed out the things we aren't going to instantiate: Segments, portal # substrates, and portal interfaces. (The copy in the for loop allows # us to delete from e.elements in side the for loop). While we're # touching all the elements, we also adjust paths from the original # testbed to local testbed paths for e in [e for e in t.elements]: if isinstance(e, topdl.Segment): t.elements.remove(e) if not isinstance(e, topdl.Computer): continue if e.get_attribute('portal'): e.set_attribute('containers:node_type', 'embedded_pnode') # Fix software paths for s in getattr(e, 'software', []): s.location = re.sub("^.*/", softdir, s.location) t.substrates = [ s.clone() for s in t.substrates ] t.incorporate_elements() # Write it out expfile = topdl.topology_to_xml(t, top='experiment') try: f = open(expfn, "w") print >>f, expfile f.close() except EnvironmentError: raise service_error(service_error.internal, "Cannot write experiment file %s: %s" % (expfn,e))