forked from cybergodai/cybergodai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstop_delete_container.py
44 lines (39 loc) · 1.23 KB
/
stop_delete_container.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
import subprocess
import sys
def run_command(command):
"""
Helper function to execute a shell command.
"""
try:
print(f"Running command: {command}")
result = subprocess.run(command, shell=True, text=True, capture_output=True)
if result.returncode != 0:
print(f"Error: {result.stderr.strip()}")
sys.exit(1)
print(result.stdout.strip())
except Exception as e:
print(f"Error running command {command}: {e}")
sys.exit(1)
def stop_container():
"""
Stops the LXC container 'my-container'.
"""
container_name = "my-container"
print(f"Stopping container '{container_name}'...")
run_command(f"lxc stop {container_name}")
def delete_container():
"""
Deletes the LXC container 'my-container'.
"""
container_name = "my-container"
print(f"Deleting container '{container_name}'...")
run_command(f"lxc delete {container_name}")
def main():
"""
Main function to stop and delete the LXC container 'my-container'.
"""
stop_container()
delete_container()
print("Container 'my-container' has been successfully stopped and deleted.")
if __name__ == "__main__":
main()