Difference between revisions of "Swestore/Lund Seminar Apr18"

From SNIC Documentation
Jump to: navigation, search
(proxy_upload script)
(proxy_upload script)
Line 13: Line 13:
 
[http://download.nordugrid.org/repos-13.02.html Installing NorduGrid Client]
 
[http://download.nordugrid.org/repos-13.02.html Installing NorduGrid Client]
  
== proxy_upload script ==
+
== proxy_transfer scripts ==
 +
 
 +
The following script can be used in conjunction with the installed proxy_use script (installed on Platon and Alarik)
 +
 
 +
Usage:
 +
 
 +
<pre>
 +
proxy_upload [hostname] [username]
 +
</pre>
 +
 
 +
This generates a proxy certificates on your local machine and transfers it to the temp-directory on the remote resource using a unique filename.
 +
 
 +
On the remote machine:
 +
 
 +
<pre>
 +
proxy_use
 +
</pre>
 +
 
 +
This command will look in the /tmp dir for uploaded proxy_certs for your username and rename the file to the standard ARC proxy format.
 +
 
 +
== proxy_upload ==
  
 
<pre>#!/bin/bash
 
<pre>#!/bin/bash
Line 52: Line 72:
 
echo "-------------------------------------------------------------"
 
echo "-------------------------------------------------------------"
 
echo</pre>
 
echo</pre>
 +
 +
== proxy_use ==
 +
 +
<pre>
 +
#!/bin/env python
 +
 +
import sys, os
 +
 +
from datetime import datetime
 +
 +
tempDir = "/tmp"
 +
 +
def findProxyFiles():
 +
        userName = os.environ["LOGNAME"]
 +
        allFiles = os.listdir(tempDir)
 +
        proxyFiles = []
 +
 +
        for dirEntry in allFiles:
 +
                fullPath = os.path.join(tempDir, dirEntry)
 +
                if os.path.isfile(fullPath):
 +
                        if fullPath.find("x509_up_%s" % userName)!=-1:
 +
                                proxyFiles.append(fullPath)
 +
 +
        return proxyFiles
 +
 +
 +
 +
if __name__ == "__main__":
 +
 +
        stdProxyFilename = os.path.join(tempDir, "x509up_u%s" % os.getuid())
 +
        proxyCertExists = False
 +
 +
        if os.path.isfile(stdProxyFilename):
 +
                print("Proxy certificate %s exists." % stdProxyFilename)
 +
                proxyCertExists = True
 +
        else:
 +
                print("No existing proxy certificate %s found. " % stdProxyFilename)
 +
 +
        proxyFiles = findProxyFiles()
 +
        proxyDict = {}
 +
 +
        for proxyFilename in proxyFiles:
 +
                info = os.stat(proxyFilename)
 +
                proxyDict[info.st_ctime] = proxyFilename
 +
 +
        sortedProxyKeys = proxyDict.keys()
 +
        sortedProxyKeys.sort()
 +
        sortedProxyKeys.reverse()
 +
 +
        if proxyCertExists:
 +
                proxyCount = 1
 +
        else:
 +
                proxyCount = 0
 +
 +
        for timeStamp in sortedProxyKeys:
 +
                if (proxyCount == 0):
 +
                        datetime = datetime.fromtimestamp(timeStamp)
 +
                        os.rename(proxyDict[timeStamp], stdProxyFilename)
 +
                        print("Created %s from uploaded proxy %s." % (stdProxyFilename, proxyDict[timeStamp]))
 +
                else:
 +
                        print("Removing old uploaded proxy %s." % proxyDict[timeStamp])
 +
                        os.remove(proxyDict[timeStamp])
 +
                proxyCount += 1
 +
 +
        if len(proxyFiles) == 0:
 +
                print("No uploaded proxy files found. Please upload proxy files using proxy_upload.")
 +
</pre>

Revision as of 21:34, 18 April 2013

Slides

File:Swestore slides sem apr15.pdf

Links

General information on SweStore

Applying for storage

Applying for certificate

Installing NorduGrid Client

proxy_transfer scripts

The following script can be used in conjunction with the installed proxy_use script (installed on Platon and Alarik)

Usage:

proxy_upload [hostname] [username]

This generates a proxy certificates on your local machine and transfers it to the temp-directory on the remote resource using a unique filename.

On the remote machine:

proxy_use

This command will look in the /tmp dir for uploaded proxy_certs for your username and rename the file to the standard ARC proxy format.

proxy_upload

#!/bin/bash

if [ $# -ne 2 ]
then
  echo "Usage: `basename $0` hostname username"
  exit $E_BADARGS
fi

proxyPath=/tmp/x509up_u$UID

echo "Generating proxy certificate."
arcproxy --proxy=$proxyPath
echo

if [ -e $proxyPath ] ; then
        echo "Found generated proxy certificate : $proxyPath"
else
        echo "Could not find any proxy certificate."
        return -1
fi

uuid=`uuidgen`

remoteProxyPath=/tmp/x509_up_$2_$uuid

echo
echo "Uploading proxy certificate to $1."
scp -p -q $proxyPath $2@$1:$remoteProxyPath

echo
echo "-------------------------------------------------------------"
echo "To use the uploaded proxy on $1, issue the"
echo "following command:"
echo
echo "proxy_use"
echo "-------------------------------------------------------------"
echo

proxy_use

#!/bin/env python

import sys, os

from datetime import datetime

tempDir = "/tmp"

def findProxyFiles():
        userName = os.environ["LOGNAME"]
        allFiles = os.listdir(tempDir)
        proxyFiles = []

        for dirEntry in allFiles:
                fullPath = os.path.join(tempDir, dirEntry)
                if os.path.isfile(fullPath):
                        if fullPath.find("x509_up_%s" % userName)!=-1:
                                proxyFiles.append(fullPath)

        return proxyFiles



if __name__ == "__main__":

        stdProxyFilename = os.path.join(tempDir, "x509up_u%s" % os.getuid())
        proxyCertExists = False

        if os.path.isfile(stdProxyFilename):
                print("Proxy certificate %s exists." % stdProxyFilename)
                proxyCertExists = True
        else:
                print("No existing proxy certificate %s found. " % stdProxyFilename)

        proxyFiles = findProxyFiles()
        proxyDict = {}

        for proxyFilename in proxyFiles:
                info = os.stat(proxyFilename)
                proxyDict[info.st_ctime] = proxyFilename

        sortedProxyKeys = proxyDict.keys()
        sortedProxyKeys.sort()
        sortedProxyKeys.reverse()

        if proxyCertExists:
                proxyCount = 1
        else:
                proxyCount = 0

        for timeStamp in sortedProxyKeys:
                if (proxyCount == 0):
                        datetime = datetime.fromtimestamp(timeStamp)
                        os.rename(proxyDict[timeStamp], stdProxyFilename)
                        print("Created %s from uploaded proxy %s." % (stdProxyFilename, proxyDict[timeStamp]))
                else:
                        print("Removing old uploaded proxy %s." % proxyDict[timeStamp])
                        os.remove(proxyDict[timeStamp])
                proxyCount += 1

        if len(proxyFiles) == 0:
                print("No uploaded proxy files found. Please upload proxy files using proxy_upload.")