Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Greenhost
Cloud API
Commits
e972eaaf
Commit
e972eaaf
authored
Dec 05, 2019
by
Varac
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'speedup-terminate-droplets' into 'master'
speedup terminate-droplets command See merge request
!3
parents
70b665bf
a8f195af
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
4 deletions
+19
-4
greenhost_cloud/cosmos.py
greenhost_cloud/cosmos.py
+19
-4
No files found.
greenhost_cloud/cosmos.py
View file @
e972eaaf
...
...
@@ -298,14 +298,29 @@ def terminate_droplets_by_name(name_regex: str, ndays: int = 0,
if
'NO_TERMINATE_DROPLETS'
in
os
.
environ
:
noterminate_droplets
=
os
.
environ
[
'NO_TERMINATE_DROPLETS'
].
split
(
','
)
# List of droplets that will be terminated
terminate_droplets
=
[]
for
droplet
in
all_droplets
:
if
droplet
[
'name'
]
not
in
noterminate_droplets
:
if
re
.
match
(
name_regex
,
droplet
[
'name'
]):
if
droplet
[
'created_at'
]
<
threshold_time
:
delete_domain_records_by_name
(
domain
,
r
'^\*.'
+
droplet
[
'name'
])
delete_domain_records_by_name
(
domain
,
'^'
+
droplet
[
'name'
])
terminate_droplet
(
droplet
[
'id'
])
terminate_droplets
.
append
(
droplet
)
# First stop all droplets
for
droplet
in
terminate_droplets
:
shutdown_droplet
(
droplet
[
'id'
])
# Then delete all domain names associated with the droplets
for
droplet
in
terminate_droplets
:
delete_domain_records_by_name
(
domain
,
r
'^\*.'
+
droplet
[
'name'
])
delete_domain_records_by_name
(
domain
,
'^'
+
droplet
[
'name'
])
# Lastly delete all droplets:
for
droplet
in
terminate_droplets
:
wait_for_state
(
droplet
[
'id'
],
'stopped'
)
delete_droplet
(
droplet
[
'id'
])
def
wait_for_ssh
(
droplet_ip
:
str
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment