1 | #!/usr/local/bin/python |
---|
2 | |
---|
3 | import os,sys |
---|
4 | import stat # for chmod constants |
---|
5 | import re |
---|
6 | import random |
---|
7 | import string |
---|
8 | import copy |
---|
9 | import pickle |
---|
10 | import logging |
---|
11 | import subprocess |
---|
12 | import traceback |
---|
13 | |
---|
14 | from threading import * |
---|
15 | from M2Crypto.SSL import SSLError |
---|
16 | |
---|
17 | from emulab_access import access as emulab_access |
---|
18 | |
---|
19 | from util import * |
---|
20 | from deter import fedid, generate_fedid |
---|
21 | from authorizer import authorizer, abac_authorizer |
---|
22 | from service_error import service_error |
---|
23 | from remote_service import xmlrpc_handler, soap_handler, service_caller |
---|
24 | from proof import proof as access_proof |
---|
25 | |
---|
26 | import httplib |
---|
27 | import tempfile |
---|
28 | from urlparse import urlparse |
---|
29 | |
---|
30 | from deter import topdl |
---|
31 | import list_log |
---|
32 | import benito_segment |
---|
33 | |
---|
34 | |
---|
35 | # Make log messages disappear if noone configures a fedd logger |
---|
36 | class nullHandler(logging.Handler): |
---|
37 | def emit(self, record): pass |
---|
38 | |
---|
39 | fl = logging.getLogger("fedd.access") |
---|
40 | fl.addHandler(nullHandler()) |
---|
41 | |
---|
42 | class access(emulab_access): |
---|
43 | """ |
---|
44 | The implementation of access control based on mapping users to projects. |
---|
45 | |
---|
46 | Users can be mapped to existing projects or have projects created |
---|
47 | dynamically. This implements both direct requests and proxies. |
---|
48 | """ |
---|
49 | |
---|
50 | max_name_len = 19 |
---|
51 | |
---|
52 | def __init__(self, config=None, auth=None): |
---|
53 | """ |
---|
54 | Initializer. Pulls parameters out of the ConfigParser's access section. |
---|
55 | """ |
---|
56 | emulab_access.__init__(self, config, auth) |
---|
57 | |
---|
58 | # Segment creation is where most of the differences are. |
---|
59 | self.start_segment = benito_segment.start_segment |
---|
60 | self.stop_segment = benito_segment.stop_segment |
---|
61 | self.info_segment = benito_segment.info_segment |
---|
62 | |
---|
63 | # These are subroutines for StartSegment |
---|
64 | def generate_ns2(self, topo, expfn, softdir, connInfo): |
---|
65 | """ |
---|
66 | Benito is expecting a topdl file, so this routine is misnamed. It does |
---|
67 | clean up the topdl, removing elements benito doesn't understand and |
---|
68 | writing out the file. |
---|
69 | """ |
---|
70 | # Main line of generate_ns2 |
---|
71 | t = topo.clone() |
---|
72 | |
---|
73 | # Weed out the things we aren't going to instantiate: Segments, portal |
---|
74 | # substrates, and portal interfaces. (The copy in the for loop allows |
---|
75 | # us to delete from e.elements in side the for loop). While we're |
---|
76 | # touching all the elements, we also adjust paths from the original |
---|
77 | # testbed to local testbed paths |
---|
78 | for e in [e for e in t.elements]: |
---|
79 | if isinstance(e, topdl.Segment): |
---|
80 | t.elements.remove(e) |
---|
81 | # Fix software paths |
---|
82 | for s in getattr(e, 'software', []): |
---|
83 | s.location = re.sub("^.*/", softdir, s.location) |
---|
84 | |
---|
85 | t.substrates = [ s.clone() for s in t.substrates ] |
---|
86 | t.incorporate_elements() |
---|
87 | |
---|
88 | # Convert to ns and write it out |
---|
89 | expfile = topdl.topology_to_xml(t, top='experiment') |
---|
90 | try: |
---|
91 | f = open(expfn, "w") |
---|
92 | print >>f, expfile |
---|
93 | f.close() |
---|
94 | except EnvironmentError: |
---|
95 | raise service_error(service_error.internal, |
---|
96 | "Cannot write experiment file %s: %s" % (expfn,e)) |
---|