Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
EasyCloud
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
DSDF
EasyCloud
Commits
b0324b2c
Commit
b0324b2c
authored
4 years ago
by
sguazt
Browse files
Options
Downloads
Patches
Plain Diff
Ditto
parent
ece1de8d
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
easycloud/common/aws.py
+37
-0
37 additions, 0 deletions
easycloud/common/aws.py
with
37 additions
and
0 deletions
easycloud/common/aws.py
+
37
−
0
View file @
b0324b2c
from
botocore.exceptions
import
WaiterError
from
easycloud.core.metaconfmanager
import
MetaConfManager
import
math
class
AWSBaseConfManager
(
MetaConfManager
):
...
...
@@ -34,3 +36,38 @@ class AWSBaseConfManager(MetaConfManager):
# Filters (for images, Amazon has 30.000+ images available)
self
.
images_filters
=
self
.
parser
.
get
(
"
filters
"
,
"
images_filters
"
).
replace
(
"
"
,
""
).
replace
(
"
\n
"
,
""
).
split
(
"
,
"
)
class
AWSEC2Utils
:
@staticmethod
def
wait_for_instance_operation
(
client
,
operation
,
instances
,
timeout
=
None
):
"""
Wait for the given operation to complete.
Args:
client (boto.EC2.Client) the AWS EC2 client.
operation (str): the operation to wait for (e.g.,
'
instance_running
'
).
instances (list): the list of instance IDs.
timeout (float): an optional value representing the max number of
seconds to wait for; if None, no timeout is enforced.
See:
- https://boto3.amazonaws.com/v1/documentation/api/latest/guide/clients.html
- https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2.html#waiters
"""
waiter
=
client
.
get_waiter
(
operation
)
if
timeout
is
not
None
:
delay
=
5
waiter_config
=
{
'
Delay
'
:
delay
,
'
MaxAttempts
'
:
math
.
ceil
(
timeout
/
delay
)}
ret
=
True
check
=
True
while
check
:
try
:
if
timeout
is
None
:
waiter
.
wait
(
InstanceIds
=
instances
)
else
:
waiter
.
wait
(
InstanceIds
=
instances
,
WaiterConfig
=
waiter_config
)
check
=
False
except
WaiterError
:
if
timeout
is
not
None
:
check
=
False
ret
=
False
return
ret
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment