Skip to content

Commit 82fcc65

Browse files
Name change and add UNIX cluster group creation
1 parent c92d1f1 commit 82fcc65

1 file changed

Lines changed: 39 additions & 7 deletions

File tree

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
SCRIPT = os.path.basename(__file__)
1212
ENDPOINT = "https://registry-test.cilogon.org/registry/"
1313
OSG_CO_ID = 8
14+
CLUSTER_ID = 10
1415
MINTIMEOUT = 5
1516
MAXTIMEOUT = 625
1617
TIMEOUTMULTIPLE = 5
@@ -23,12 +24,14 @@
2324
OSPOOL_PROJECT_PREFIX_STR = "Yes-"
2425
PROJECT_GIDS_START = 200000
2526

27+
2628
_usage = f"""\
2729
usage: [PASS=...] {SCRIPT} [OPTIONS]
2830
2931
OPTIONS:
3032
-u USER[:PASS] specify USER and optionally PASS on command line
3133
-c OSG_CO_ID specify OSG CO ID (default = {OSG_CO_ID})
34+
-p CLUSTER_ID specify UNIX Cluster ID (default = {CLUSTER_ID})
3235
-d passfd specify open fd to read PASS
3336
-f passfile specify path to file to open and read PASS
3437
-e ENDPOINT specify REST endpoint
@@ -58,6 +61,7 @@ class Options:
5861
endpoint = ENDPOINT
5962
user = "co_8.william_test"
6063
osg_co_id = OSG_CO_ID
64+
unix_id = CLUSTER_ID
6165
outfile = None
6266
authstr = None
6367
min_timeout = MINTIMEOUT
@@ -202,6 +206,8 @@ def parse_options(args):
202206
options.user = arg
203207
if op == "-c":
204208
options.osg_co_id = int(arg)
209+
if op == "-p":
210+
options.unix_id = int(arg)
205211
if op == "-d":
206212
passfd = int(arg)
207213
if op == "-f":
@@ -226,8 +232,14 @@ def main(args):
226232

227233
co_groups = get_osg_co_groups()["CoGroups"]
228234
highest_osggid = 0
235+
project_groups = set()
229236
projects_to_assign_identifiers = []
230237

238+
unix_cluster_groups = call_api("unix_cluster/unix_cluster_groups.json", unix_cluster_id=options.unix_id)
239+
clustered_group_ids = set(group["CoGroupId"] for group in unix_cluster_groups["UnixClusterGroups"])
240+
projects_needing_cluster_groups = set()
241+
projects_needing_provisioning = set()
242+
231243
for group in co_groups:
232244
gid = group["Id"]
233245
identifier_data = get_co_group_identifiers(gid)
@@ -238,16 +250,24 @@ def main(args):
238250
project_id_index = identifier_index(identifier_list, "ospoolproject")
239251
if project_id_index != -1:
240252
project_id = str(identifier_list[project_id_index]["Identifier"])
241-
is_project = re.compile(OSPOOL_PROJECT_PREFIX_STR + "*").match(project_id) is not None
242-
else:
243-
is_project = False
253+
if re.compile(OSPOOL_PROJECT_PREFIX_STR + "*").match(project_id) is not None:
254+
project_groups.add(gid)
244255

245256
osggid_index = identifier_index(identifier_list, "osggid")
246257
if osggid_index != -1:
247258
highest_osggid = max(highest_osggid, int(identifier_list[osggid_index]["Identifier"]))
248-
elif is_project is True:
249-
project_name = project_id.replace(OSPOOL_PROJECT_PREFIX_STR, "", 1).lower()
250-
projects_to_assign_identifiers.append((gid, project_name,))
259+
260+
if gid in project_groups:
261+
if osggid_index == -1:
262+
project_name = project_id.replace(OSPOOL_PROJECT_PREFIX_STR, "", 1).lower()
263+
project_data = (
264+
gid,
265+
project_name,
266+
)
267+
projects_to_assign_identifiers.append(project_data)
268+
269+
if not gid in clustered_group_ids:
270+
projects_needing_cluster_groups.add(gid)
251271

252272
for gid, project_name in projects_to_assign_identifiers:
253273
# for each, set a 'OSG GID' starting from 200000 and a 'OSG Group Name' that is the group name
@@ -257,11 +277,23 @@ def main(args):
257277
add_identifier_to_group(gid, type="osggroup", identifier_name=project_name)
258278
print(f"project {project_name}: added osggid {osggid_to_assign} and osg project name {project_name}")
259279

280+
for gid in projects_needing_cluster_groups:
281+
request = {
282+
"RequestType": "UnixClusterGroups",
283+
"Version": "1.0",
284+
"UnixClusterGroups": [{"Version": "1.0", "UnixClusterId": options.unix_id, "CoGroupId": gid}],
285+
}
286+
call_api3(
287+
POST,
288+
"unix_cluster/unix_cluster_groups.json",
289+
request,
290+
)
291+
print(f"project group {gid}: added UNIX Cluster Group")
292+
260293

261294
if __name__ == "__main__":
262295
try:
263296
main(sys.argv[1:])
264297
except urllib.error.HTTPError as e:
265298
print(e, file=sys.stderr)
266299
sys.exit(1)
267-

0 commit comments

Comments
 (0)