#!/usr/bin/env python
import json
import requests
import time
import os
import sys
from requests.auth import HTTPBasicAuth

headers = {
    'Content-Type': 'application/json',
    'Accept': 'application/json'
}

api_url = 'https://girder.local.wholetale.org/api/v1'

try:
    r = requests.get(api_url + '/user/authentication', auth=HTTPBasicAuth('admin', 'arglebargle123'))
except:
    print('Girder is no longer running')
    exit()
r.raise_for_status()
headers['Girder-Token'] = r.json()['authToken']['token']

print('Deleting all running instances')
r = requests.get(api_url + '/instance', headers=headers,
                 params={'limit': 0})
r.raise_for_status()
for instance in r.json():
    requests.delete(api_url + '/instance/' + instance['_id'], headers=headers)

@@ -115,16 +115,52 @@
 asicAuth
+%0Afrom subprocess import check_output
 %0A%0Aheader
@@ -803,8 +803,122 @@
 eaders)%0A
+%0Acmd = %22docker service ls --filter=name=tmp -q %7C xargs -r docker service rm%22%0Aprint(check_output(cmd, shell=True))%0A

Remove stray instances