@@ -159,89 +159,7 @@ def get(data):
159
159
return rorable (get )
160
160
161
161
162
- # api call results massagers
163
-
164
-
165
- def get_unixcluser_autogroups ():
166
- groups = get_osg_co_groups ()
167
- return [ g for g in groups ["CoGroups" ]
168
- if "automatically by UnixCluster" in g ["Description" ] ]
169
-
170
-
171
- def get_misnamed_unixcluster_groups ():
172
- groups = get_osg_co_groups ()
173
- return [ g for g in groups ["CoGroups" ]
174
- if "UnixCluster Group" in g ["Name" ] ]
175
-
176
-
177
- def _osgid_sortkey (i ):
178
- return int (i ["Identifier" ])
179
-
180
- def get_identifiers_to_delete (identifiers ):
181
- by_type = collections .defaultdict (list )
182
- ids_to_delete = []
183
-
184
- for i in identifiers :
185
- by_type [i ["Type" ]].append (i )
186
-
187
- if len (by_type ["osggid" ]) == 2 :
188
- min_identifier = min (by_type ["osggid" ], key = _osgid_sortkey )
189
- ids_to_delete .append (min_identifier ["Id" ])
190
-
191
- for i in by_type ["osggroup" ]:
192
- if i ["Identifier" ].endswith ("unixclustergroup" ):
193
- ids_to_delete .append (i ["Id" ])
194
-
195
- return ids_to_delete
196
-
197
-
198
- def get_fixed_unixcluster_group_name (name ):
199
- m = re .search (r'^(.*) UnixCluster Group' , name )
200
- return m .group (1 ) if m else name
201
-
202
-
203
- # display functions
204
-
205
-
206
- def show_misnamed_unixcluster_group (group ):
207
- print ('CO {CoId} Group {Id}: "{Name}"' .format (** group ))
208
- oldname = group ["Name" ]
209
- newname = get_fixed_unixcluster_group_name (oldname )
210
- if oldname != newname :
211
- print (' ** Rename group to: "%s"' % newname )
212
- show_group_identifiers (group ["Id" ])
213
- print ("" )
214
-
215
-
216
- def show_all_unixcluster_groups ():
217
- groups = get_unixcluser_autogroups ()
218
- for group in groups :
219
- show_misnamed_unixcluster_group (group )
220
-
221
-
222
- def show_one_unixcluster_group (gid ):
223
- group = get_co_group (gid )
224
- show_misnamed_unixcluster_group (group )
225
-
226
-
227
- def show_misnamed_unixcluster_groups ():
228
- groups = get_misnamed_unixcluster_groups ()
229
- for group in groups :
230
- show_misnamed_unixcluster_group (group )
231
-
232
-
233
- def show_group_identifiers (gid ):
234
- identifiers = get_co_group_identifiers (gid ) | get_datalist ("Identifiers" )
235
- for i in identifiers :
236
- print (' - Identifier {Id}: ({Type}) "{Identifier}"' .format (** i ))
237
-
238
- ids_to_delete = get_identifiers_to_delete (identifiers )
239
- if ids_to_delete :
240
- print (' ** Identifier Ids to delete: %s' % ', ' .join (ids_to_delete ))
241
-
242
-
243
-
244
- # fixup functions
162
+ # script-specific functions
245
163
246
164
def add_project_identifier_to_group (gid , project_name ):
247
165
identifier_name = "Yes-%s" % project_name
@@ -279,44 +197,6 @@ def gname_to_gid(gname):
279
197
return group ["Id" ]
280
198
281
199
282
- def delete_identifier (id_ ):
283
- return call_api2 (DELETE , "identifiers/%d.json" % id_ )
284
-
285
-
286
- def rename_co_group (gid , group , newname ):
287
- # minimal edit CoGroup Request includes Name+CoId+Status+Version
288
- new_group_info = {
289
- "Name" : newname ,
290
- "CoId" : group ["CoId" ],
291
- "Status" : group ["Status" ],
292
- "Version" : group ["Version" ]
293
- }
294
- data = {
295
- "CoGroups" : [new_group_info ],
296
- "RequestType" : "CoGroups" ,
297
- "Version" : "1.0"
298
- }
299
- return call_api3 (PUT , "co_groups/%d.json" % gid , data )
300
-
301
-
302
- def fixup_unixcluster_group (gid ):
303
- group = get_co_group (gid )
304
- oldname = group ["Name" ]
305
- newname = get_fixed_unixcluster_group_name (oldname )
306
- identifiers = get_co_group_identifiers (gid ) | get_datalist ("Identifiers" )
307
- ids_to_delete = get_identifiers_to_delete (identifiers )
308
-
309
- show_misnamed_unixcluster_group (group )
310
- if oldname != newname :
311
- rename_co_group (gid , group , newname )
312
- for id_ in ids_to_delete :
313
- delete_identifier (id_ )
314
-
315
- # http errors raise exceptions, so at this point we apparently succeeded
316
- print (":thumbsup:" )
317
- return 0
318
-
319
-
320
200
# CLI
321
201
322
202
0 commit comments