cull_idle_servers.py: Don't try to delete non-running servers

- Only run the server handler if a server is actually running.  A bug
  could occur with non-named servers.
This commit is contained in:
Richard Darst
2018-04-17 13:52:13 +03:00
parent 9858a3db9d
commit 5f98801c99

View File

@@ -115,7 +115,7 @@ def cull_idle(url, api_token, inactive_limit, cull_users=False, max_age=0, concu
def handle_server(user, server_name, server): def handle_server(user, server_name, server):
"""Handle (maybe) culling a single server """Handle (maybe) culling a single server
Returns True if server was culled, Returns True if server is now stopped (user removable),
False otherwise. False otherwise.
""" """
log_name = user['name'] log_name = user['name']
@@ -184,19 +184,28 @@ def cull_idle(url, api_token, inactive_limit, cull_users=False, max_age=0, concu
@coroutine @coroutine
def handle_user(user): def handle_user(user):
"""Handle one user""" """Handle one user.
Create a list of their servers, and async exec them. Wait for
that to be done, and if all servers are stopped, possibly cull
the user.
"""
# shutdown servers first. # shutdown servers first.
# Hub doesn't allow deleting users with running servers. # Hub doesn't allow deleting users with running servers.
servers = user.get( # named servers contain the 'servers' dict
'servers', if 'servers' in user:
{ servers = user['servers']
'': { # Otherwise, server data is intermingled in with the user
# model
else:
servers = {}
if user['server']:
servers[''] = {
'started': user.get('started'), 'started': user.get('started'),
'last_activity': user['last_activity'], 'last_activity': user['last_activity'],
'pending': user['pending'], 'pending': user['pending'],
'url': user['server'],
} }
}
)
server_futures = [ server_futures = [
handle_server(user, server_name, server) handle_server(user, server_name, server)
for server_name, server in servers.items() for server_name, server in servers.items()