3
3
import os
4
4
import sys
5
5
import getopt
6
- import comanage_scripts_utils as utils
6
+ import comanage_utils as utils
7
7
8
8
SCRIPT = os .path .basename (__file__ )
9
- ENDPOINT = "https://registry-test .cilogon.org/registry/"
10
- LDAP_SERVER = "ldaps://ldap-test .cilogon.org"
11
- LDAP_USER = "uid=registry_user ,ou=system,o=OSG,o=CO,dc=cilogon,dc=org"
12
- OSG_CO_ID = 8
13
- UNIX_CLUSTER_ID = 10
14
- LDAP_TARGET_ID = 9
9
+ ENDPOINT = "https://registry.cilogon.org/registry/"
10
+ LDAP_SERVER = "ldaps://ldap.cilogon.org"
11
+ LDAP_USER = "uid=readonly_user ,ou=system,o=OSG,o=CO,dc=cilogon,dc=org"
12
+ OSG_CO_ID = 7
13
+ UNIX_CLUSTER_ID = 1
14
+ LDAP_TARGET_ID = 6
15
15
16
16
OSPOOL_PROJECT_PREFIX_STR = "Yes-"
17
17
PROJECT_GIDS_START = 200000
25
25
-c OSG_CO_ID specify OSG CO ID (default = { OSG_CO_ID } )
26
26
-g CLUSTER_ID specify UNIX Cluster ID (default = { UNIX_CLUSTER_ID } )
27
27
-l LDAP_TARGET specify LDAP Provsion ID (defult = { LDAP_TARGET_ID } )
28
+ -s LDAP_SERVER specify LDAP server
29
+ -y LDAP_USER specify LDAP server user
28
30
-p LDAP authtok specify LDAP server authtok
29
31
-d passfd specify open fd to read PASS
30
32
-f passfile specify path to file to open and read PASS
43
45
44
46
def usage (msg = None ):
45
47
if msg :
46
- print (msg + " \n " , file = sys .stderr )
48
+ print (f" { msg } \n " , file = sys .stderr )
47
49
48
50
print (_usage , file = sys .stderr )
49
51
sys .exit ()
50
52
51
53
52
54
class Options :
53
55
endpoint = ENDPOINT
54
- user = "co_8.william_test "
56
+ user = "co_7.project_script "
55
57
osg_co_id = OSG_CO_ID
56
58
ucid = UNIX_CLUSTER_ID
57
59
provision_target = LDAP_TARGET_ID
60
+ ldap_user = LDAP_USER
61
+ ldap_server = LDAP_SERVER
58
62
outfile = None
59
63
authstr = None
60
64
ldap_authtok = None
@@ -66,7 +70,7 @@ class Options:
66
70
67
71
def parse_options (args ):
68
72
try :
69
- ops , args = getopt .getopt (args , "u:c:g:l:p:d:f:e:o:h" )
73
+ ops , args = getopt .getopt (args , "u:c:g:l:p:d:f:e:o:s:y: h" )
70
74
except getopt .GetoptError :
71
75
usage ()
72
76
@@ -97,6 +101,10 @@ def parse_options(args):
97
101
options .endpoint = arg
98
102
if op == "-o" :
99
103
options .outfile = arg
104
+ if op == "-s" :
105
+ options .ldap_server = arg
106
+ if op == "-y" :
107
+ options .ldap_user = arg
100
108
101
109
try :
102
110
user , passwd = utils .getpw (options .user , passfd , passfile )
@@ -106,7 +114,7 @@ def parse_options(args):
106
114
107
115
108
116
def append_if_project (project_groups , group ):
109
- # If this group has a ospoolproject id, and it starts with "Yes-", it's a project
117
+ """ If this group has a ospoolproject id, and it starts with "Yes-", it's a project"""
110
118
if utils .identifier_matches (group ["ID_List" ], "ospoolproject" , (OSPOOL_PROJECT_PREFIX_STR + "*" )):
111
119
# Add a dict of the relavent data for this project to the project_groups list
112
120
project_groups .append (group )
@@ -116,9 +124,9 @@ def update_highest_osggid(highest_osggid, group):
116
124
# Get the value of the osggid identifier, if this group has one
117
125
osggid = utils .identifier_from_list (group ["ID_List" ], "osggid" )
118
126
# If this group has a osggid, keep a hold of the highest one we've seen so far
119
- if osggid is not None :
127
+ try :
120
128
return max (highest_osggid , int (osggid ))
121
- else :
129
+ except TypeError :
122
130
return highest_osggid
123
131
124
132
@@ -128,8 +136,8 @@ def get_comanage_data():
128
136
129
137
co_groups = utils .get_osg_co_groups (options .osg_co_id , options .endpoint , options .authstr )["CoGroups" ]
130
138
for group_data in co_groups :
131
- try :
132
- identifier_list = utils . get_co_group_identifiers ( group_data [ "Id" ], options . endpoint , options . authstr )
139
+ identifier_list = utils . get_co_group_identifiers ( group_data [ "Id" ], options . endpoint , options . authstr )
140
+ if identifier_list is not None :
133
141
# Store this groups data in a dictionary to avoid repeated API calls
134
142
group = {"Gid" : group_data ["Id" ], "Name" : group_data ["Name" ], "ID_List" : identifier_list ["Identifiers" ]}
135
143
@@ -138,8 +146,6 @@ def get_comanage_data():
138
146
139
147
# Update highest_osggid, if this group has an osggid and it's higher than the current highest osggid.
140
148
highest_osggid = update_highest_osggid (highest_osggid , group )
141
- except TypeError :
142
- pass
143
149
return (projects_list , highest_osggid )
144
150
145
151
@@ -169,12 +175,14 @@ def get_projects_needing_cluster_groups(project_groups):
169
175
)
170
176
return projects_needing_unix_groups
171
177
except TypeError :
178
+ print ("ERROR: TypeError raised while trying to determine which projects need UNIX cluster groups\n "
179
+ + f"clustered group ids: { clustered_group_ids } and project_gids: { project_gids } " )
172
180
return set ()
173
181
174
182
175
183
def get_projects_needing_provisioning (project_groups ):
176
184
# project groups provisioned in LDAP
177
- ldap_group_osggids = utils .get_ldap_groups (LDAP_SERVER , LDAP_USER , options .ldap_authtok )
185
+ ldap_group_osggids = utils .get_ldap_groups (options . ldap_server , options . ldap_user , options .ldap_authtok )
178
186
try :
179
187
# All project osggids
180
188
project_osggids = set (
@@ -190,6 +198,8 @@ def get_projects_needing_provisioning(project_groups):
190
198
)
191
199
return projects_to_provision
192
200
except TypeError :
201
+ print ("TypeError raised while trying to determine which projects need provisioning\n "
202
+ + f"ldap group osggids: { ldap_group_osggids } and project osggids: { project_osggids } " )
193
203
return set ()
194
204
195
205
@@ -241,7 +251,7 @@ def provision_groups(project_list):
241
251
def main (args ):
242
252
parse_options (args )
243
253
244
- # Make all of the nessisary calls to COManage's API for the data we'll need to set up projects.
254
+ # Make all of the necessary calls to COManage's API for the data we'll need to set up projects.
245
255
# Projects is a List of dicts with keys Gid, Name, and Identifiers, the project's list of identifiers.
246
256
# Highest_current_osggid is the highest OSGGID that's currently assigned to any CO Group.
247
257
projects , highest_current_osggid = get_comanage_data ()
@@ -265,6 +275,5 @@ def main(args):
265
275
if __name__ == "__main__" :
266
276
try :
267
277
main (sys .argv [1 :])
268
- except OSError as e :
269
- print (e , file = sys .stderr )
270
- sys .exit (1 )
278
+ except Exception as e :
279
+ sys .exit (e )
0 commit comments