Fix
This commit is contained in:
parent
8b1c611e37
commit
c7883caf2b
@ -2,4 +2,4 @@
|
|||||||
|
|
||||||
chmod +x delete_resources_script.py
|
chmod +x delete_resources_script.py
|
||||||
pip install -r requirements.txt
|
pip install -r requirements.txt
|
||||||
python delete_resources_script.py
|
python delete_resources_script.py $1
|
@ -13,17 +13,19 @@ client = Client(
|
|||||||
)
|
)
|
||||||
|
|
||||||
delete_volumes = False
|
delete_volumes = False
|
||||||
sys.argv = sys.argv[1:]
|
if len(sys.argv) > 1:
|
||||||
if len(sys.argv) > 0:
|
if sys.argv[1] == "--delete-volumes":
|
||||||
if sys.argv[0] == "--delete-volumes":
|
|
||||||
delete_volumes = True
|
delete_volumes = True
|
||||||
|
|
||||||
def delete_all_servers():
|
def delete_all_servers():
|
||||||
servers = client.servers.get_all()
|
servers = client.servers.get_all()
|
||||||
for server in servers:
|
for server in servers:
|
||||||
if server.name.startswith(PREFIX):
|
if server.name.startswith(PREFIX):
|
||||||
action = server.volumes[0].detach()
|
action = server.power_off()
|
||||||
action.wait_until_finished()
|
action.wait_until_finished()
|
||||||
|
if server.volumes and server.volumes[0]:
|
||||||
|
action = server.volumes[0].detach()
|
||||||
|
action.wait_until_finished()
|
||||||
action = client.servers.delete(server)
|
action = client.servers.delete(server)
|
||||||
print(
|
print(
|
||||||
f"Usuwanie serwera {server.data_model.name} ({server.data_model.public_net.ipv4.ip}): {action.data_model.status}")
|
f"Usuwanie serwera {server.data_model.name} ({server.data_model.public_net.ipv4.ip}): {action.data_model.status}")
|
||||||
@ -32,8 +34,9 @@ def delete_all_volumes():
|
|||||||
volumes = client.volumes.get_all()
|
volumes = client.volumes.get_all()
|
||||||
for volume in volumes:
|
for volume in volumes:
|
||||||
if volume.name.startswith(PREFIX):
|
if volume.name.startswith(PREFIX):
|
||||||
action = client.volumes.detach(volume)
|
if volume.server is not None:
|
||||||
action.wait_until_finished()
|
action = client.volumes.detach(volume)
|
||||||
|
action.wait_until_finished()
|
||||||
client.volumes.delete(volume)
|
client.volumes.delete(volume)
|
||||||
print(f"Usuwanie woluminu {volume.name}")
|
print(f"Usuwanie woluminu {volume.name}")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user