- Timestamp:
- Jun 25, 2008 2:56:12 PM (16 years ago)
- Branches:
- axis_example, compt_changes, info-ops, master, version-1.30, version-2.00, version-3.01, version-3.02
- Children:
- 8922e1b
- Parents:
- d26d52e
- Location:
- fedd
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
fedd/fedd.py
rd26d52e r2106ed1 131 131 sys.exit("Must supply certificate file (probably in config)") 132 132 133 bad_password = True134 while bad_password:133 ctx = None 134 while ctx == None: 135 135 try: 136 136 ctx = fedd_ssl_context(impl.cert_file, impl.trusted_certs, 137 137 password=impl.cert_pwd) 138 bad_password = False139 138 except SSL.SSLError, e: 140 if e.message == "bad decrypt" and impl.cert_pwd == None: 141 bad_password = True 142 else: 139 if str(e) != "bad decrypt" or impl.cert_pwd != None: 143 140 raise 144 141 -
fedd/fedd_client.py
rd26d52e r2106ed1 11 11 from ZSI import SoapWriter 12 12 13 from fedd_util import fedid, fedd_ssl_context, pack_soap, pack_id 13 from fedd_util import fedid, fedd_ssl_context, pack_soap, unpack_soap, \ 14 pack_id, unpack_id 14 15 15 16 from optparse import OptionParser, OptionValueError … … 108 109 const=sys.stderr, help="Print SOAP exchange to stderr") 109 110 110 111 112 def print_ID(id, out=sys.stdout, prefix=None, no_nl=False):113 """Print an ID element (which may have many types) to as a string114 115 If out is given, that is the output destination. If prefix is given that116 string is prepended. If no_nl is given, the newline is not printed.117 """118 # This comprehension selects all accessors from id of the form119 # get_element_*, calls those in turn and returns a list of non-None ones.120 # For valid ID elements that will contain exactly one element, which we121 # print. Anything else is an error.122 names = [ getattr(id, method)() for method in dir(id) \123 if method.startswith("get_element_") \124 and callable(getattr(id, method))125 and getattr(id,method)() != None ]126 if len(names) == 1:127 if prefix == None: print >>out, names[0],128 else: print >>out, "%s%s" % (prefix,names[0]),129 if not no_nl: print >>out130 else:131 raise IDFormatException()132 133 134 def print_users(ul, out=sys.stdout):135 """136 Print a list of users, with "User: " prepended, one to a line on out.137 138 @param ul sequence of user elements139 @param out output object. Defaults to sys.stdout140 """141 if ul != None:142 for u in ul:143 print_ID(u.get_element_userID(), out, "User: ")144 145 146 111 def print_response_as_testbed(resp, label, out=sys.stdout): 147 112 """Print the response as input to the splitter script""" 148 emulab_data = { 149 "Boss: ": "get_element_boss", 150 "OpsNode: ": "get_element_ops", 151 "Domain: ": "get_element_domain", 152 "FileServer: ": "get_element_fileServer", 153 "EventServer: ": "get_element_eventServer", 113 114 e = resp['emulab'] 115 p = e['project'] 116 fields = { 117 "Boss": e['boss'], 118 "OpsNode": e['ops'], 119 "Domain": e['domain'], 120 "FileServer": e['fileServer'], 121 "EventServer": e['eventServer'], 122 "Project": unpack_id(p['name']) 154 123 } 155 124 if (label != None): print >> out, "[%s]" % label 156 e = resp.get_element_emulab() 157 if ( e != None): 158 p = e.get_element_project() 159 if ( p != None ): 160 print_ID(p.get_element_name(), out, "Project: ") 161 print_users(p.get_element_user(), out) 162 for k, m in emulab_data.iteritems(): 163 method = getattr(e, m); 164 if method != None and callable(method): 165 print >> out, "%s%s" % (k, method()) 166 for a in e.get_element_fedAttr(): 167 print >>out, "%s: %s" % \ 168 (a.get_element_attribute(), a.get_element_value()) 125 126 for l, v in fields.iteritems(): 127 print >>out, "%s: %s" % (l, v) 128 129 for u in p['user']: 130 print >>out, "User: %s" % unpack_id(u['userID']) 131 132 for a in e['fedAttr']: 133 print >>out, "%s: %s" % (a['attribute'], a['value']) 134 169 135 def add_ssh_key(option, opt_str, value, parser, access_keys): 170 136 try: … … 256 222 # Yes, doing this on message type is not ideal. The string comes from 257 223 # OpenSSL, so check there is this stops working. 258 if e.message== "bad decrypt":224 if str(e) == "bad decrypt": 259 225 print >>sys.stderr, "Bad Passphrase given." 260 226 else: raise … … 301 267 pack_soap(req, "RequestAccessRequestBody", msg)) 302 268 303 if opts.debug > 1: 304 print msg 269 if opts.debug > 1: print >>sys.stderr, msg 305 270 306 271 if opts.serialize_only: … … 315 280 sys.exit("Fault: %s" % e) 316 281 282 317 283 if (resp != None): 318 284 resp_body = resp.get_element_RequestAccessResponseBody() 319 285 if ( resp_body != None): 320 286 try: 321 print_response_as_testbed(resp_body, opts.label) 287 resp_dict = unpack_soap(resp_body) 288 if opts.debug > 1: print >>sys.stderr, resp_dict 289 print_response_as_testbed(resp_dict, opts.label) 322 290 except RuntimeError, e: 323 291 sys.exit("Bad response. %s" % e.messgae) -
fedd/fedd_util.py
rd26d52e r2106ed1 163 163 elif id.startswith("http:") or id.startswith("https:"): return { 'uri': id } 164 164 else: return { 'username': id} 165 166 def unpack_id(id): 167 """return id as a type determined by the key""" 168 if id.has_key("fedid"): return fedid(id["fedid"]) 169 else: 170 for k in ("username", "uri", "kerberosUsername"): 171 if id.has_key(k): return id[k] 172 return None 165 173 166 174 def pack_soap(container, name, contents):
Note: See TracChangeset
for help on using the changeset viewer.