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
A prog2-höz tartozó friss repo anyagok itt elérhetőek:
https://git.iit.bme.hu/
Commit
07d4ec62
authored
Mar 05, 2013
by
Bach Dániel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SendMailTask added
parent
ff4144e6
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
77 additions
and
16 deletions
+77
-16
cloud/settings.py
+1
-0
firewall/tasks.py
+1
-1
firewall/views.py
+1
-4
one/jobs/hourly/scheduled_vm_cleanup.py
+48
-2
one/jobs/hourly/update.py
+3
-1
one/tasks.py
+15
-0
one/templates/mails/notification-delete.txt
+2
-2
one/templates/mails/notification-suspend-now.txt
+3
-3
one/templates/mails/notification-suspend.txt
+3
-3
No files found.
cloud/settings.py
View file @
07d4ec62
...
...
@@ -188,6 +188,7 @@ CELERY_ROUTES = {
'firewall.tasks.reload_dhcp_task'
:
{
'queue'
:
'dhcp'
},
'firewall.tasks.reload_blacklist_task'
:
{
'queue'
:
'firewall'
},
'firewall.tasks.Periodic'
:
{
'queue'
:
'local'
},
'one.tasks.SendMailTask'
:
{
'queue'
:
'local'
},
}
store_settings
=
{
...
...
firewall/tasks.py
View file @
07d4ec62
...
...
@@ -20,7 +20,7 @@ def reload_blacklist_task(data):
pass
class
Periodic
(
PeriodicTask
):
run_every
=
timedelta
(
seconds
=
6
0
)
run_every
=
timedelta
(
seconds
=
1
0
)
def
run
(
self
,
**
kwargs
):
...
...
firewall/views.py
View file @
07d4ec62
...
...
@@ -53,11 +53,8 @@ def firewall_api(request):
s
=
render_to_string
(
'mails/notification-ban-now.txt'
,
{
'user'
:
user
,
'bl'
:
obj
}
)
print
s
# send_mail(settings.EMAIL_SUBJECT_PREFIX + (_('New project: %s') % p.identifier), s, settings.SERVER_EMAIL, [])
except
Host
.
DoesNotExist
,
ValidationError
,
IntegrityError
,
AttributeError
as
e
:
except
(
Host
.
DoesNotExist
,
ValidationError
,
IntegrityError
,
AttributeError
)
:
pass
except
:
raise
print
"ok"
print
obj
.
modified_at
+
datetime
.
timedelta
(
minutes
=
5
)
print
datetime
.
datetime
.
utcnow
()
.
replace
(
tzinfo
=
utc
)
if
obj
.
type
==
'tempwhite'
and
obj
.
modified_at
+
datetime
.
timedelta
(
minutes
=
1
)
<
datetime
.
datetime
.
utcnow
()
.
replace
(
tzinfo
=
utc
):
...
...
one/jobs/hourly/scheduled_vm_cleanup.py
View file @
07d4ec62
# -*- coding: utf-8 -*-
from
django_extensions.management.jobs
import
HourlyJob
import
datetime
from
django.utils.timezone
import
utc
from
one.models
import
Instance
from
django.template.loader
import
render_to_string
from
one.tasks
import
SendMailTask
from
django.utils.translation
import
ugettext_lazy
as
_
class
Job
(
HourlyJob
):
help
=
"Suspend/delete expired Instances."
def
calc
(
self
,
orig
,
days
=
0
,
hours
=
0
):
return
(
orig
+
datetime
.
timedelta
(
days
=
days
,
hours
=
hours
))
.
replace
(
minute
=
0
,
second
=
0
,
microsecond
=
0
)
def
execute
(
self
):
# executing empty sample job TODO
pass
now
=
datetime
.
datetime
.
utcnow
()
.
replace
(
tzinfo
=
utc
)
d
=
{
'1m'
:
self
.
calc
(
orig
=
now
,
days
=
30
),
'2w'
:
self
.
calc
(
orig
=
now
,
days
=
14
),
'1w'
:
self
.
calc
(
orig
=
now
,
days
=
7
),
'1d'
:
self
.
calc
(
orig
=
now
,
days
=
1
),
'1h'
:
self
.
calc
(
orig
=
now
,
hours
=
2
),
}
# for i in d:
# print i+':'+unicode(d[i])
# delete
for
i
in
Instance
.
objects
.
filter
(
state__in
=
[
'ACTIVE'
,
'STOPPED'
],
time_of_delete__isnull
=
False
):
print
"
%
s delete:
%
s"
%
(
i
.
name
,
i
.
time_of_delete
)
delete
=
i
.
time_of_delete
.
replace
(
minute
=
0
,
second
=
0
,
microsecond
=
0
)
if
delete
<
now
:
msg
=
render_to_string
(
'mails/notification-delete-now.txt'
,
{
'user'
:
i
.
owner
,
'instance'
:
i
}
)
SendMailTask
.
delay
(
to
=
i
.
owner
.
email
,
subject
=
_
(
'Delete notification'
),
msg
=
msg
)
else
:
for
t
in
d
:
if
delete
==
d
[
t
]:
msg
=
render_to_string
(
'mails/notification-delete.txt'
,
{
'user'
:
i
.
owner
,
'instance'
:
i
}
)
SendMailTask
.
delay
(
to
=
i
.
owner
.
email
,
subject
=
_
(
'Delete notification'
),
msg
=
msg
)
# suspend
for
i
in
Instance
.
objects
.
filter
(
state
=
'ACTIVE'
,
time_of_suspend__isnull
=
False
):
print
"
%
s suspend:
%
s"
%
(
i
.
name
,
i
.
time_of_suspend
)
suspend
=
i
.
time_of_suspend
.
replace
(
minute
=
0
,
second
=
0
,
microsecond
=
0
)
if
suspend
<
now
:
msg
=
render_to_string
(
'mails/notification-suspend-now.txt'
,
{
'user'
:
i
.
owner
,
'instance'
:
i
}
)
SendMailTask
.
delay
(
to
=
i
.
owner
.
email
,
subject
=
_
(
'Stop notification'
),
msg
=
msg
)
i
.
stop
()
else
:
for
t
in
d
:
if
suspend
==
d
[
t
]:
msg
=
render_to_string
(
'mails/notification-suspend.txt'
,
{
'user'
:
i
.
owner
,
'instance'
:
i
}
)
SendMailTask
.
delay
(
to
=
i
.
owner
.
email
,
subject
=
_
(
'Stop notification'
),
msg
=
msg
)
one/jobs/hourly/update.py
View file @
07d4ec62
...
...
@@ -2,9 +2,11 @@ from one.models import *
from
django_extensions.management.jobs
import
HourlyJob
class
Job
(
HourlyJob
):
help
=
"Update Disks
and Network
s from OpenNebula."
help
=
"Update Disks
, Networks and Instance
s from OpenNebula."
def
execute
(
self
):
Disk
.
update
()
Network
.
update
()
for
i
in
Instance
.
objects
.
filter
(
state__in
=
[
'ACTIVE'
,
'STOPPED'
],
time_of_delete__isnull
=
False
):
i
.
update_state
()
pass
one/tasks.py
0 → 100644
View file @
07d4ec62
from
celery.task
import
Task
,
PeriodicTask
import
logging
import
celery
import
os
import
sys
import
time
logger
=
logging
.
getLogger
(
__name__
)
class
SendMailTask
(
Task
):
def
run
(
self
,
to
,
subject
,
msg
):
sender
=
u'cloud@ik.bme.hu'
print
u'
%
s->
%
s [
%
s]'
%
(
sender
,
to
,
subject
)
logger
.
info
(
"[django][one][tasks.py]
%
s"
,
msg
)
one/templates/mails/notification-delete.txt
View file @
07d4ec62
{%
base base.txt
%}
{%
extends "mails/base.txt"
%}
{% load i18n %}
{% block body %}
{% blocktrans with vm=instance.name state=instance.state date=
exp
time=exp|timeuntil %}
{% blocktrans with vm=instance.name state=instance.state date=
instance.time_of_delete
time=exp|timeuntil %}
Your {{state}} virtual machine "{{vm}}" is going to be DELETED
at {{date}} (in {{time}}).
{% endblocktrans %}
...
...
one/templates/mails/notification-suspend-now.txt
View file @
07d4ec62
{%
base base.txt
%}
{%
extends "mails/base.txt"
%}
{% load i18n %}
{% block body %}
{% blocktrans with vm=instance.name state=instance.state date=
exp deldate=exp2
%}
{% blocktrans with vm=instance.name state=instance.state date=
instance.time_of_suspend
%}
Your {{state}} virtual machine "{{vm}}" has been STOPPED
at {{date}}.
{% endblocktrans %}
{% blocktrans with deldate=
exp2
%}
{% blocktrans with deldate=
instance.time_of_delete
%}
The disk and memory image is stored, and you can resume it
until the final expiration time ({{deldate}}).
{% endblocktrans %}
...
...
one/templates/mails/notification-suspend.txt
View file @
07d4ec62
{%
base base.txt
%}
{%
extends "mails/base.txt"
%}
{% load i18n %}
{% block body %}
{% blocktrans with vm=instance.name state=instance.state date=
exp
time=exp|timeuntil url=url %}
{% blocktrans with vm=instance.name state=instance.state date=
instance.time_of_suspend
time=exp|timeuntil url=url %}
Your {{state}} virtual machine "{{vm}}" is going to be STOPPED
at {{date}} (in {{time}}).
{% endblocktrans %}
{% blocktrans with deldate=
exp2
%}
{% blocktrans with deldate=
instance.time_of_delete
%}
The disk and memory image will be stored, and you can resume it
until the final expiration time ({{deldate}}).
{% endblocktrans %}
...
...
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