Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Fukász Rómeó Ervin
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
42cc6856
authored
Mar 06, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vm: add Instance.notify_owners_about_expiration()
parent
988dc1d2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
0 deletions
+37
-0
circle/vm/models/instance.py
+37
-0
No files found.
circle/vm/models/instance.py
View file @
42cc6856
...
@@ -562,6 +562,43 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
...
@@ -562,6 +562,43 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
else
:
else
:
raise
Node
.
DoesNotExist
()
raise
Node
.
DoesNotExist
()
def
_is_notified_about_expiration
(
self
):
renews
=
self
.
activity_log
.
filter
(
activity_code__endswith
=
'renew'
)
cond
=
{
'activity_code__endswith'
:
'notification_about_expiration'
}
if
len
(
renews
)
>
0
:
cond
[
'finished__gt'
]
=
renews
[
0
]
.
started
return
self
.
activity_log
.
filter
(
**
cond
)
.
exists
()
def
notify_owners_about_expiration
(
self
,
again
=
False
):
"""Notify owners about vm expiring soon if they aren't already.
:param again: Notify already notified owners.
"""
if
not
again
and
self
.
_is_notified_about_expiration
():
return
False
success
,
failed
=
[],
[]
def
on_commit
(
act
):
act
.
result
=
{
'failed'
:
failed
,
'success'
:
success
}
with
instance_activity
(
'notification_about_expiration'
,
instance
=
self
,
on_commit
=
on_commit
):
from
dashboard.views
import
VmRenewView
level
=
self
.
get_level_object
(
"owner"
)
for
u
,
ulevel
in
self
.
get_users_with_level
(
level__pk
=
level
.
pk
):
try
:
token
=
VmRenewView
.
get_token_url
(
self
,
u
)
u
.
profile
.
notify
(
_
(
'
%
s expiring soon'
)
%
unicode
(
self
),
'dashboard/notifications/vm-expiring.html'
,
{
'instance'
:
self
,
'token'
:
token
},
valid_until
=
min
(
self
.
time_of_delete
,
self
.
time_of_suspend
))
except
Exception
as
e
:
failed
.
append
((
u
,
e
))
else
:
success
.
append
(
u
)
return
True
def
is_expiring
(
self
,
threshold
=
0.1
):
def
is_expiring
(
self
,
threshold
=
0.1
):
"""Returns if an instance will expire soon.
"""Returns if an instance will expire soon.
...
...
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