@@ -525,12 +525,18 @@ def get_all_collections_by_repo(api_client=None):
525
525
""" Return a dict of each repo and their collections """
526
526
assert api_client is not None , "api_client is a required param"
527
527
api_prefix = api_client .config .get ("api_prefix" ).rstrip ("/" )
528
- collections = {
529
- 'staging' : {},
530
- 'published' : {},
531
- 'community' : {},
532
- 'rh-certified' : {},
533
- }
528
+
529
+ # get all distributions ...
530
+ # /api/galaxy/pulp/api/v3/distributions/
531
+ distro_names = []
532
+ next_page = f'{ api_prefix } /pulp/api/v3/distributions/'
533
+ while next_page :
534
+ resp = api_client (next_page )
535
+ next_page = resp .get ('links' , {}).get ('next' )
536
+ for distro in resp ['results' ]:
537
+ distro_names .append (distro ['name' ])
538
+
539
+ collections = dict ((x , {}) for x in distro_names )
534
540
for repo in collections .keys ():
535
541
next_page = f'{ api_prefix } /_ui/v1/collection-versions/?repository={ repo } '
536
542
while next_page :
@@ -638,25 +644,43 @@ def delete_all_collections(api_client):
638
644
def delete_all_collections_in_namespace (api_client , namespace_name ):
639
645
640
646
assert api_client is not None , "api_client is a required param"
647
+ api_prefix = api_client .config .get ("api_prefix" ).rstrip ("/" )
641
648
642
649
# accumlate a list of matching collections in each repo
643
650
ctuples = set ()
651
+
652
+ '''
644
653
cmap = get_all_collections_by_repo(api_client)
645
654
for repo, cvs in cmap.items():
646
655
for cv_spec in cvs.keys():
647
656
if cv_spec[0] == namespace_name:
648
657
ctuples.add((repo, cv_spec[0], cv_spec[1]))
658
+ '''
659
+
660
+ #import epdb; epdb.st()
661
+ next_page = f'{ api_prefix } /_ui/v1/collection-versions/?namespace={ namespace_name } '
662
+ while next_page :
663
+ resp = api_client (next_page )
664
+ next_page = resp .get ('links' , {}).get ('next' )
665
+
666
+ for collection in resp ['data' ]:
667
+ for repository_name in collection ['repository_list' ]:
668
+ ctuples .add ((repository_name , collection ['namespace' ], collection ['name' ]))
649
669
650
670
# delete each collection ...
671
+ results = []
651
672
for ctuple in ctuples :
652
673
crepo = ctuple [0 ]
653
674
cname = ctuple [2 ]
654
675
655
- recursive_delete (api_client , namespace_name , cname , crepo )
676
+ res = recursive_delete (api_client , namespace_name , cname , crepo )
677
+ results .append (res )
678
+
679
+ return results
656
680
657
681
658
- def recursvive_delete (api_client , namespace_name , cname , crepo ):
659
- return recursive_delete (api_client , namespace_name , cname , crepo )
682
+ # def recursvive_delete(api_client, namespace_name, cname, crepo):
683
+ # return recursive_delete(api_client, namespace_name, cname, crepo)
660
684
661
685
662
686
def recursive_delete (api_client , namespace_name , cname , crepo ):
@@ -672,7 +696,7 @@ def recursive_delete(api_client, namespace_name, cname, crepo):
672
696
673
697
if dependants :
674
698
for ns , name in dependants :
675
- recursvive_delete (api_client , ns , name , crepo )
699
+ recursive_delete (api_client , ns , name , crepo )
676
700
677
701
# Try deleting the whole collection ...
678
702
try :
0 commit comments