def lookforurl(username, task_id):
    """
    Uses module global API client instance.
    """
    activer=[username,"-c",os.getcwd()+"/credential-"+username+".pem"]
    global api
    api, _ = create_client_from_args(activer)
    #print " Here: ",api.task_list()
    # See what is in the account before we make any submissions.
    #print "=== Before transfer ==="
    #display_tasksummary(); print
    #display_task_list(); print
    #display_endpoint_list(); print
    #status, reason, result = api.task(task_id)

    oldstdout=sys.stdout
    sys.stdout = open(os.devnull,'w')
    status, reason, result = api.task(task_id)
    sys.stdout = oldstdout # enable output
    if result["status"] != "SUCCEEDED":
        print "The process is not finished yet."
        print "Its status is "+result["status"]; print
        sys.exit(0)
    #else:
        #print "The task succeeded"

    #status, reason, result = api.subtask_list(task_id)
    destendpoint = []
    status, reason, result = api.get("/task/%s" % task_id)
    #print " ++++++++++++++++++++++++ "
    #print result["source_endpoint"], result["destination_endpoint"]
    #print " ++++++++++++++++++++++++ "
    try:
        destendpoint.append(re.split("#",result["destination_endpoint"])[1])
    except:
        destendpoint.append(result["destination_path"])

    inurllist    = []
    outurllist   = []
    
    status, reason, result = api.task_successful_transfers(task_id)
    for subtask in result["DATA"]:
        #print " ++++++++++++++++++++++++ "
        #print subtask["source_path"], subtask["destination_path"], subtask["destination_endpoint"]
        #print " ++++++++++++++++++++++++ "
        inurllist.append(subtask["source_path"])
        outurllist.append(subtask["destination_path"])
    
    while result["next_marker"] != [] and result["next_marker"] != None:
        #print result["next_marker"]
        #print "There are more pid..."
        status, reason, result = api.task_successful_transfers(task_id, marker=result["next_marker"])
        for subtask in result["DATA"]:
            #print subtask
            #print subtask["source_path"], subtask["destination_path"], subtask["destination_endpoint"]
            inurllist.append(subtask["source_path"])
            outurllist.append(subtask["destination_path"])

    return inurllist, outurllist, destendpoint
def defineurlendpoint(username):
    """
    Uses module global API client instance.
    """
    activer=[username,"-c",os.getcwd()+"/credential-"+username+".pem"]
    global api
    api, _ = create_client_from_args(activer)
     
    urlendpoint={} 

    #print; print "============= Retrieving  endpoint-list =============="
    status, message, data = api.endpoint_list(filter="username:"******"99")
    for ep_data in data["DATA"]:
        value = ep_data["canonical_name"]
        key   = ep_data["DATA"][0]["hostname"]
        urlendpoint[key]=value
    #print "============= endpoint-list retrivied =============="

    return urlendpoint
def detailsoftask(username, task_id):
    """
    Uses module global API client instance.
    """
    activer=[username,"-c",os.getcwd()+"/credential-"+username+".pem"]
    global api
    global interactivity
    api, _ = create_client_from_args(activer)

    oldstdout=sys.stdout
    sys.stdout = open(os.devnull,'w')
    status, reason, result = api.task(task_id)
    sys.stdout = oldstdout # enable output
    if result["status"] != "SUCCEEDED":
        print "The process is not finished yet: its status is "+result["status"]; print
        status, reason, result = api.task_event_list(task_id)

        #print "====== File info ======"
        #print result
        #for data in result["DATA"]:
            #matchObj=re.search( r'(.*)Command(.*) .*',data["details"])
            #if matchObj:
                #containingfilename=matchObj.group(0)
                #break
        #filename=containingfilename.split()[2]    
        #print filename
        #api.file_list(filename) 
        #print "====== File info end ======"; print

        print "The operation has the following details:"; print
        try:
            data=result["DATA"][0]
        except:
            print "The data are not available yet. Try in a few seconds again."
            sys.exit(0)
        for key, value in data.iteritems():    
            print key, value; print
        print    
        if not interactivity: full_exit("Done!")
    else:
        print "The task already succeeded"
        if not interactivity: full_exit("Done!")
def canceltask(username, task_id):
    """
    Uses module global API client instance.
    """
    activer=[username,"-c",os.getcwd()+"/credential-"+username+".pem"]
    global api
    global interactivity
    api, _ = create_client_from_args(activer)

    oldstdout=sys.stdout
    sys.stdout = open(os.devnull,'w')
    status, reason, result = api.task(task_id)
    sys.stdout = oldstdout # enable output
    if result["status"] != "SUCCEEDED":
        print "The process is not finished yet: its status is "+result["status"]; print
        print "It is going to be cancelled."; print
        status, reason, result = api.task_cancel(task_id)
        print "The cancel operation exited with the following message from GO:"
        print result["message"]; print
        if not interactivity: full_exit("Done!")
    else:
        print "The task already succeeded"
        if not interactivity: full_exit("Done!")
Exemplo n.º 5
0
def globus_transfer(image_id, cfg):
    packages_directory = os.path.join(os.path.expanduser("~"), ".gdclient","packages")
    package_directory = os.path.join(packages_directory, image_id)

    if not os.path.isdir(package_directory):
        print "Cannot find image "+image_id+" for transfer; please run --package level collaboration"
        return

    if not cfg.config['GLOBUS']['local-folder']:
        print "Cannot obtain from config file: local folder shared in GLOBUS "
        return
    if not cfg.config['GLOBUS']['local-endpoint']:
        print "Cannot obtain from config file: GLOBUS local endpoint"
        return
    if not cfg.config['GLOBUS']['remote-endpoint']:
        print "Cannot obtain from config file: GLOBUS remote endpoint"
        return
    if not cfg.config['GLOBUS']['globus-remote-folder']:
        print "Cannot obtain from config file: globus folder shared in remote GLOBUS endpoint"
        return
    if not cfg.config['GLOBUS']['globus-local-folder']:
        print "Cannot obtain from config file: globus folder shared in local GLOBUS endpoint"
        return

    print "Please wait. Saving image ..."
    short_image_name = image_id.strip()+".tgz"
    image_file = cfg.config['GLOBUS']['local-folder']+"/"+short_image_name

    command = "cd "+packages_directory+";tar czf "+image_file+" "+ image_id
    # print "will run: ",command
    run_command(command)
    source_endpoint  = cfg.config['GLOBUS']['local-endpoint'] # 'globuspublish#cirlab'
    source_folder= cfg.config['GLOBUS']['globus-local-folder'] # '/globuspublication_52/'
    remote_endpoint  = cfg.config['GLOBUS']['remote-endpoint'] # 'globuspublish#cirlab'
    remote_folder= cfg.config['GLOBUS']['globus-remote-folder'] # '/globuspublication_52/'

    # # command = "ssh [email protected] scp cvlaescx#test_2:/docker_image/dockeraf8db02049ae25d3e64436769411206258b3b003.tar cvlaescx#test:/home/cristian/Installs/new3.tar"
    # source = "%s%s%s" %(source_endpoint,source_folder, short_image_name)
    # destination = "%s%s%s" %(remote_endpoint,remote_folder, short_image_name)
    # command = "ssh %[email protected] transfer -- %s %s" % (cfg.config['Default']['uname'], source, destination)
    # # print "will run: ",command
    # run_command(command)
    # #print "USAGE: transfer [destination_endpoint:destination_folder]"

    transfer_args = [cfg.config['Default']['uname'], '-g', cfg.config['Default']['goauth-token']]

    TransferAPIClient, _ = create_client_from_args(transfer_args)

    activate_endpoint(TransferAPIClient, source_endpoint)
    activate_endpoint(TransferAPIClient, remote_endpoint)

    # submit the transfer
    code, message, data = TransferAPIClient.transfer_submission_id()
    submission_id = data["value"]
    deadline = datetime.utcnow() + timedelta(minutes=10)
    t = Transfer(submission_id, source_endpoint, remote_endpoint, deadline)
    source_image_name = "%s%s"%(source_folder,short_image_name)
    destination_image_name = "%s%s"%(remote_folder,short_image_name)
    t.add_item(source_image_name, destination_image_name)
    code, reason, data = TransferAPIClient.transfer(t)
    task_id = data["task_id"]
    print "Submitted transfer id: ", task_id
    return "globus://%s%s%s"%(remote_endpoint,remote_folder,short_image_name)
Exemplo n.º 6
0
            print " (%s)" % s["subject"]
        else:
            print

def unicode_(data):
    """
    Coerce any type to unicode, assuming utf-8 encoding for strings.
    """
    if isinstance(data, unicode):
        return data
    if isinstance(data, str):
        return unicode(data, "utf-8")
    else:
        return unicode(data)

def display_ls(endpoint_name, path=""):
    code, reason, data = api.endpoint_ls(endpoint_name, path)
    # Server returns canonical path; "" maps to the users default path,
    # which is typically their home directory "/~/".
    path = data["path"]
    print "Contents of %s on %s:" % (path, endpoint_name)
    headers = "name, type, permissions, size, user, group, last_modified"
    headers_list = headers.split(", ")
    print headers
    for f in data["DATA"]:
        print ", ".join([unicode_(f[k]) for k in headers_list])

if __name__ == '__main__':
    api, _ = create_client_from_args()
    tutorial()
Exemplo n.º 7
0
The credential passed as the third argument is what is used to activate the
endpoint, and may be the same or different from the credential used to
authenticate to the API (passed with -k/-c).

The endpoint name may contain a # which is a shell comment, so be sure to
quote the endpoint name.
"""

import sys

from globusonline.transfer.api_client import create_client_from_args
from globusonline.transfer.api_client import x509_proxy

if __name__ == '__main__':
    api, args = create_client_from_args()
    if len(args) < 2:
        sys.stderr.write(
            "username, endpoint, cred_file arguments are required")
        sys.exit(1)

    ep = args[0]
    cred_file = args[1]

    print "Using x509_proxy implementation '%s'" % x509_proxy.implementation

    _, _, reqs = api.endpoint_activation_requirements(ep,
                                                      type="delegate_proxy")
    public_key = reqs.get_requirement_value("delegate_proxy", "public_key")
    proxy = x509_proxy.create_proxy_from_file(cred_file, public_key)
    reqs.set_requirement_value("delegate_proxy", "proxy_chain", proxy)

def unicode_(data):
    """
    Coerce any type to unicode, assuming utf-8 encoding for strings.
    """
    if isinstance(data, unicode):
        return data
    if isinstance(data, str):
        return unicode(data, "utf-8")
    else:
        return unicode(data)


def display_ls(endpoint_name, path=""):
    code, reason, data = api.endpoint_ls(endpoint_name, path)
    # Server returns canonical path; "" maps to the users default path,
    # which is typically their home directory "/~/".
    path = data["path"]
    print "Contents of %s on %s:" % (path, endpoint_name)
    headers = "name, type, permissions, size, user, group, last_modified"
    headers_list = headers.split(", ")
    print headers
    for f in data["DATA"]:
        print ", ".join([unicode_(f[k]) for k in headers_list])


if __name__ == '__main__':
    api, _ = create_client_from_args()
    tutorial()
Exemplo n.º 9
0
def globus_transfer(image_id, cfg):
    packages_directory = os.path.join(os.path.expanduser("~"), ".gdclient","packages")
    package_directory = os.path.join(packages_directory, image_id)

    if not os.path.isdir(package_directory):
        print "Cannot find image "+image_id+" for transfer; please run --package level collaboration"
        return

    if not cfg.config['GLOBUS']['local-folder']:
        print "Cannot obtain from config file: local folder shared in GLOBUS "
        return
    if not cfg.config['GLOBUS']['local-endpoint']:
        print "Cannot obtain from config file: GLOBUS local endpoint"
        return
    if not cfg.config['GLOBUS']['remote-endpoint']:
        print "Cannot obtain from config file: GLOBUS remote endpoint"
        return
    if not cfg.config['GLOBUS']['globus-remote-folder']:
        print "Cannot obtain from config file: globus folder shared in remote GLOBUS endpoint"
        return
    if not cfg.config['GLOBUS']['globus-local-folder']:
        print "Cannot obtain from config file: globus folder shared in local GLOBUS endpoint"
        return

    print "Please wait. Saving image ..."
    short_image_name = image_id.strip()+".tgz"
    image_file = cfg.config['GLOBUS']['local-folder']+"/"+short_image_name

    command = "cd "+packages_directory+";tar czf "+image_file+" "+ image_id
    # print "will run: ",command
    run_command(command)
    source_endpoint  = cfg.config['GLOBUS']['local-endpoint'] # 'globuspublish#cirlab'
    source_folder= cfg.config['GLOBUS']['globus-local-folder'] # '/globuspublication_52/'
    remote_endpoint  = cfg.config['GLOBUS']['remote-endpoint'] # 'globuspublish#cirlab'
    remote_folder= cfg.config['GLOBUS']['globus-remote-folder'] # '/globuspublication_52/'

    # # command = "ssh [email protected] scp cvlaescx#test_2:/docker_image/dockeraf8db02049ae25d3e64436769411206258b3b003.tar cvlaescx#test:/home/cristian/Installs/new3.tar"
    # source = "%s%s%s" %(source_endpoint,source_folder, short_image_name)
    # destination = "%s%s%s" %(remote_endpoint,remote_folder, short_image_name)
    # command = "ssh %[email protected] transfer -- %s %s" % (cfg.config['Default']['uname'], source, destination)
    # # print "will run: ",command
    # run_command(command)
    # #print "USAGE: transfer [destination_endpoint:destination_folder]"

    transfer_args = [cfg.config['Default']['uname'], '-g', cfg.config['Default']['goauth-token']]

    TransferAPIClient, _ = create_client_from_args(transfer_args)

    activate_endpoint(TransferAPIClient, source_endpoint)
    activate_endpoint(TransferAPIClient, remote_endpoint)

    # submit the transfer
    code, message, data = TransferAPIClient.transfer_submission_id()
    submission_id = data["value"]
    deadline = datetime.utcnow() + timedelta(minutes=10)
    t = Transfer(submission_id, source_endpoint, remote_endpoint, deadline)
    source_image_name = "%s%s"%(source_folder,short_image_name)
    destination_image_name = "%s%s"%(remote_folder,short_image_name)
    t.add_item(source_image_name, destination_image_name)
    code, reason, data = TransferAPIClient.transfer(t)
    task_id = data["task_id"]
    print "Submitted transfer id: ", task_id
    return "globus://%s%s%s"%(remote_endpoint,remote_folder,short_image_name)