Skip to content

Commit

Permalink
Merge pull request #103 from vantage6/bugfix/also-remove-tasks
Browse files Browse the repository at this point in the history
Removing tasks from the workshop server
  • Loading branch information
bartvanb authored Oct 1, 2024
2 parents ecafc34 + 4586745 commit 5d15fe0
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions instructors/files/infrastructure/delete-resources.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"source": [
"from vantage6.client import Client\n",
"\n",
"client = Client(url, port, api_path, log_level='debug')\n",
"client = Client(url, port, api_path, log_level='info')\n",
"\n",
"client.authenticate(username, password)\n",
"client.setup_encryption(None)"
Expand All @@ -38,6 +38,20 @@
"from workshop_resources.collaborations import collaborations as collaboration_names"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# clear all tasks\n",
"tasks = client.task.list(per_page=999)[\"data\"]\n",
"print(f\"Clearing {len(tasks)} tasks\")\n",
"for task in tasks:\n",
" client.task.delete(task[\"id\"])\n",
"print(\"Done\")"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -47,12 +61,13 @@
"### read participants as list of dictionaries\n",
"import csv\n",
"\n",
"participants_file = 'workshop_resources/participants.csv'\n",
"participants_file = 'workshop_resources/participants_try_outs.csv'\n",
"participants = []\n",
"with open(participants_file, mode='r') as f:\n",
" reader = csv.DictReader(f)\n",
" for row in reader:\n",
" participants.append(row)\n"
" participants.append(row)\n",
"print(f\"Read {len(participants)} participants\")"
]
},
{
Expand All @@ -63,10 +78,14 @@
"source": [
"# clear users\n",
"for participant in participants:\n",
" print(f\"Deleting user {participant['first_name']} {participant['last_name']}\")\n",
" response = client.user.list(firstname=participant['first_name'], lastname=participant['last_name'])\n",
" if len(response['data']) > 0:\n",
" user = response['data'][0]\n",
" client.user.delete(user['id'])"
" response = client.user.delete(user['id'])\n",
" else:\n",
" print(\"User not found\")\n",
"\n"
]
},
{
Expand All @@ -78,9 +97,12 @@
"# clear organizations\n",
"for organization in organization_names:\n",
" response = client.organization.list(name=organization['name'])\n",
" print(f\"Deleting organization {organization['name']}\")\n",
" if len(response['data']) > 0:\n",
" org = response['data'][0]\n",
" client.organization.delete(org['id'], delete_dependents=True)"
" client.organization.delete(org['id'], delete_dependents=True)\n",
" else:\n",
" print(f\"Organization {organization['name']} not found\")"
]
},
{
Expand All @@ -92,11 +114,13 @@
"# note that this also deletes the studies and the nodes\n",
"# TODO there is a bug. Therefore studies are not deleted by this endpoint. See\n",
"# https://github.com/vantage6/vantage6/issues/1465\n",
"for collab in client.collaboration.list(scope=\"global\")['data']:\n",
"for collab in client.collaboration.list(scope=\"global\", per_page=999)['data']:\n",
" if collab['name'] in collaboration_names:\n",
" print(f\"Deleting collaboration {collab['name']}\")\n",
" client.collaboration.delete(collab['id'], delete_dependents=True)\n",
"\n",
"for study in client.study.list()[\"data\"]:\n",
"for study in client.study.list(per_page=999)[\"data\"]:\n",
" print(f\"Deleting study {study}\")\n",
" client.study.delete(study[\"id\"])"
]
},
Expand Down

0 comments on commit 5d15fe0

Please sign in to comment.