add default_server_name, change spawn start

This commit is contained in:
Christian Barra
2017-01-21 14:56:36 +01:00
parent 5b85d1e248
commit f4a7e28aa5
2 changed files with 23 additions and 6 deletions

View File

@@ -214,3 +214,18 @@ def url_path_join(*pieces):
result = '/'
return result
def default_server_name(user):
"""Return the default name for a new server for a given user.
Will be the first available integer string, e.g. '1' or '2'.
"""
existing_names = { server.name for server in user.servers }
# if there are 5 servers, count from 1 to 6
for n in range(1, len(existing_names) + 2):
name = str(n)
if name not in existing_names:
return name
raise RuntimeError("It should be impossible to get here")