Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
988dc1d2
authored
Mar 06, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vm: add Instance.is_expiring()
parent
106e3707
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
0 deletions
+26
-0
circle/vm/models/instance.py
+26
-0
No files found.
circle/vm/models/instance.py
View file @
988dc1d2
...
@@ -562,6 +562,32 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
...
@@ -562,6 +562,32 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
else
:
else
:
raise
Node
.
DoesNotExist
()
raise
Node
.
DoesNotExist
()
def
is_expiring
(
self
,
threshold
=
0.1
):
"""Returns if an instance will expire soon.
Soon means that the time of suspend or delete comes in 10
%
of the
interval what the Lease allows. This rate is configurable with the
only parameter, threshold (0.1 = 10
%
by default).
"""
return
(
self
.
_is_suspend_expiring
(
self
,
threshold
)
or
self
.
_is_delete_expiring
(
self
,
threshold
))
def
_is_suspend_expiring
(
self
,
threshold
=
0.1
):
interval
=
self
.
lease
.
suspend_interval
if
interval
is
not
None
:
limit
=
timezone
.
now
()
+
threshold
*
self
.
lease
.
suspend_interval
return
limit
>
self
.
time_of_suspend
else
:
return
False
def
_is_delete_expiring
(
self
,
threshold
=
0.1
):
interval
=
self
.
lease
.
delete_interval
if
interval
is
not
None
:
limit
=
timezone
.
now
()
+
threshold
*
self
.
lease
.
delete_interval
return
limit
>
self
.
time_of_delete
else
:
return
False
def
get_renew_times
(
self
):
def
get_renew_times
(
self
):
"""Returns new suspend and delete times if renew would be called.
"""Returns new suspend and delete times if renew would be called.
"""
"""
...
...
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