24 def getAmiClient(cls, amiconf = None, verbose = False):
25 """get ami client
26 param amiconf: name of file with AMI user and pw
27
28 If a valid filename is specified, it tries to read the
29 username and password from there. If that does not succeed or
30 no filename is specified, voms based authentication is tried.
31 """
32 from pyAMI.pyAMI import AMI,pyAMIEndPoint
33 from os import stat,path
34
35 useConfigFile = False
36 if amiconf:
37 if not path.exists(amiconf):
38 if verbose:
39 print ("WARNING: AMI config file", amiconf, "does not exist. Need to rely on valid voms proxy.")
40 elif stat(amiconf).st_mode & path.stat.S_IRUSR == 0:
41 if verbose:
42 print ("WARNING: AMI config file", amiconf, "exists but is not readable. Need to rely on valid voms proxy.")
43 else:
44 useConfigFile = True
45
46 if useConfigFile:
47 pyAMIEndPoint.setType("replica")
48 ami=AMI()
49 ami.readConfig(amiconf)
50 if ami.checkAuth():
51 print ("... connecting to CERN AMI replica with user+pw")
52 return ami
53 pyAMIEndPoint.setType("main")
54 ami.certAuth()
55 if ami.checkAuth():
56 print ("... connecting to AMI main server with user+pw")
57 return ami
58
59 print ("WARNING: Authentication in config file",amiconf,"not valid, check format, user, pw. Need to rely on valid voms proxy.")
60
61
62 pyAMIEndPoint.setType("replica")
63 ami=AMI()
64 if ami.checkAuth():
65 print ("... connecting to CERN replica using voms-proxy")
66 return ami
67
68
69 pyAMIEndPoint.setType("main")
70 ami.certAuth()
71 if ami.checkAuth():
72 print ("... connecting to main server using voms-proxy")
73 return ami
74
75
76 if verbose:
77 print ("WARNING voms-proxy authentication not valid. No access to AMI.")
78 return None
79
80