[Swift-commit] r4814 - SwiftApps/GOSwift/pykoa/tools

jonmon at ci.uchicago.edu jonmon at ci.uchicago.edu
Mon Jul 11 13:37:06 CDT 2011


Author: jonmon
Date: 2011-07-11 13:37:06 -0500 (Mon, 11 Jul 2011)
New Revision: 4814

Modified:
   SwiftApps/GOSwift/pykoa/tools/koa_goswift.py
Log:
goswift now creates and stores the proxy information(I think).


Modified: SwiftApps/GOSwift/pykoa/tools/koa_goswift.py
===================================================================
--- SwiftApps/GOSwift/pykoa/tools/koa_goswift.py	2011-07-11 13:49:07 UTC (rev 4813)
+++ SwiftApps/GOSwift/pykoa/tools/koa_goswift.py	2011-07-11 18:37:06 UTC (rev 4814)
@@ -1,33 +1,29 @@
 #!/usr/bin/python
 import commands
+import readline
+
 import os
+import re
 import sys
-import uuid
+import subprocess
 import datetime
-import readline
-import time
-import signal
-from optparse import OptionGroup
 
 from sqlalchemy.sql import text
 
 import pykoa
 import pykoa.tools
-from pykoa.constants import GroupStatusCodes as grpc
+from pykoa.process_observer import ProcessObserver
+from pykoa.signal_util import BlockInterrupt, enable_sigint
+from pykoa.tools import url_parse, myproxy
+from pykoa.tools import koa_transfer
+from pykoa.tools.koa_ep_activate import check_explicit_activate
 from pykoa.consumers import guc_util
-from pykoa.koaexception import ToolsException, cli_exception_handler
-from pykoa.tools.url_parse import SCPUrl
-from pykoa.tools.koa_ep_activate import check_explicit_activate
-from pykoa.tools import koa_cancel
-from pykoa.tools import koa_transfer
-from pykoa.tools import myproxy
-from pykoa.tools import koa_wait
-from pykoa.data import groups_dao
+from pykoa.constants import get_scheme
+from pykoa.lib.mlsd import MLSDEntry
 from pykoa.data import endpoint_dao
 from pykoa.data import creds_dao
-from pykoa.data import preflight_dao
+from pykoa.koaexception import ToolsException, cli_exception_handler
 
-
 def setup_opts(argv):
     # Set up help message
     help_screen = """ \
@@ -52,6 +48,10 @@
                       help="Set the time limit for this workflow.  " + \
                            "Default: 30m (30 minutes)")
 
+    parser.add_option("-g", dest="gsi_activation",
+                      default=False, action="store_true",
+                      help="Use gsi-ssh delegated credential")
+
     (options, args) = pykoa.tools.parse_args(parser, argv)
 
     return (parser, options, args)
@@ -221,20 +221,121 @@
     config_file.close()
     script_file.close()
 
-    # Execute the script
-    os.chdir( swift_dir+'/'+run_directory )
-    ( status, output ) = commands.getstatusoutput( home+'/swift-0.92/bin/swift -sites.file sites.xml -tc.file tc -config cf script.swift' )
-    sys.stdout.write( "\nSwift output: " + output + "\n" )
-    sys.stdout.write( "Swift exit status: " + str(status) + "\n" )
+    # A logical endpoint (no dots) can be a scp like path, if it has a :
+    if re.match("^[^.]+:", args[0]):
+        url = url_parse.SCPUrl(args[0], allow_empty_path=True)
+        url.update_relative_path()
+    else:
+        url = url_parse.TransferURL(args[0])
 
+    src_url = None
+    src_cred = None
+    default_myproxy = None
+    ep = None
+    myproxy_host = None
+
+    if not url.scheme:
+        # See if it's a logical endpoint
+        ep = endpoint_dao.get_logical_by_name(conn, user_id, url.name)
+        if not ep:
+            ep = endpoint_dao.get_public_by_name(conn, url.name)
+
+    if ep:
+	default_myproxy = ep.myproxy_server
+	# Get first physical ep, if exists
+	phys = endpoint_dao.get_physicals_for_logical(conn, ep.id)
+	if not phys:
+	    raise ToolsException("No physical server exists for '%s'" % (
+		url.name))
+	phys = phys[0]
+	scheme = get_scheme(phys.xfer_service_id)
+	src_url = "%s://%s:%d%s" % (scheme, phys.hostname, phys.port, url.path)
+	src_subject = phys.x509_dn
+
+	# See if LTA endpoint is connected
+	if phys.is_lta and phys.alive == 0:
+	    raise ToolsException("The requested Globus Connect endpoint is not currently connected to Globus Online")
+
+	# Get creds
+	row = creds_dao.get_cred_for_logical(conn, user_id, ep.id)
+	if row and row.exp_time > datetime.datetime.utcnow():
+	    src_cred = row.sec_info
+
+    if not src_url:
+        # Not a logical endpoint
+	if '.' not in url.name:
+	    raise ToolsException('EEXIST_ENDPOINT', url.name)
+        if not url.scheme:
+            url.scheme = "gsiftp"
+        if not url.port:
+            url.port = "2811"
+        src_url = url.full_name + url.path
+        src_subject = ""
+        src_cred = None
+
+    # Get creds
+    if options.gsi_activation:
+	if ep:
+	    check_explicit_activate([ep])
+        cred_file = os.environ["X509_USER_PROXY"]
+        src_cred = open(cred_file).read()
+
+    elif myproxy_host or ((not src_cred) and default_myproxy):
+        if not myproxy_host:
+            myproxy_host = default_myproxy
+	if ep:
+	    check_explicit_activate([ep], myproxy_host)
+
+        cred_file = myproxy.contact_myproxy_server(myproxy_host, 
+                options.myproxy_user, options.myproxy_dn,
+                lifetime=options.myproxy_lifetime)
+
+        if not cred_file:
+            return 1
+        try:
+            src_cred = open(cred_file).read()
+            if ep:
+                # Save cred to DB, re-entering passphrases is annoying
+                ep_cache = {'foo': ep.id}
+                koa_transfer.do_activate(conn, cred_file, ep_cache, user_id,
+                        quiet=True)
+        finally:
+            os.unlink(cred_file)
+
+    if not src_cred:
+        raise ToolsException("A credential is needed.  Try -g or -m.")
+
+    ret = execute_swift(user_id, options, src_url, src_cred, src_subject, swift_dir, run_directory, home)
+
+
     # clean up
 #    os.remove( swift_dir + "/" + run_directory + "/tc" )
 #    os.remove( swift_dir + "/" + run_directory + "/sites.xml" )
 #    os.remove( swift_dir + "/" + run_directory + "/cf" )
 #    os.remove( swift_dir + "/" + run_directory + "/script.swift" )
 
-    return 0
+    return ret
 
+def execute_swift(user_id, options, src_url, src_cred, src_subject, swift_dir, run_directory, home):
+
+    if src_subject:
+        os.environ['GLOBUS_FTP_CLIENT_TEST_SUBJECT'] = src_subject
+    if src_cred:
+        proxyfile = guc_util.sec_text_to_proxy_file(user_id, src_cred)
+        os.environ["X509_USER_CERT"] = proxyfile
+        os.environ["X509_USER_KEY"] = proxyfile
+
+    # Execute the script
+    os.chdir( swift_dir+'/'+run_directory )
+    ( status, output ) = commands.getstatusoutput( home+'/swift-0.92/bin/swift -sites.file sites.xml -tc.file tc -config cf script.swift' )
+    sys.stdout.write( "\nSwift output: " + output + "\n" )
+    sys.stdout.write( "Swift exit status: " + str(status) + "\n" )
+
+    if src_cred:
+        os.remove( proxyfile )
+       
+    return status
+
 if __name__ == "__main__":
     rc = main()
     sys.exit(rc)




More information about the Swift-commit mailing list