-
Notifications
You must be signed in to change notification settings - Fork 0
/
shelve-action-runners.py
44 lines (33 loc) · 1.36 KB
/
shelve-action-runners.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Copyright (c) 2022-2023 The Regents of the University of Michigan.
# Part of the Glotzerlab jetstream2 administration scripts, released under the
# BSD 3-Clause License.
"""Shelve powered down actions runner instances in jetstream2."""
import sys
import openstack
def shelve_runners(connection):
"""Shelve runners that are powered down."""
try:
servers = list(connection.compute.servers())
except Exception as e:
print("::warning:: Failed to enumerate servers:", str(e))
return False
for server in servers:
if server.name.startswith("actions-runner"):
print(f"Server {server.name} is {server.status}({server.task_state}).")
if server.status == "SHUTOFF" and server.task_state is None:
print(f"... shelving {server.name}.")
try:
connection.compute.shelve_server(server)
except Exception as e:
print(f"::warning:: Failed to shelve server {server.name}:", str(e))
sys.stdout.flush()
return None
if __name__ == "__main__":
# catch errors and return success so that this script doesn't stop the whole
# actions job
try:
connection = openstack.connect()
except Exception as e:
print("::warning:: Failed to connect to cloud:", str(e))
sys.exit(0)
shelve_runners(connection)