Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
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
1a4ca401
authored
Mar 02, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vm: implement vm expiration
parent
f6687581
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
2 deletions
+58
-2
circle/dashboard/templates/dashboard/notifications/vm-destroyed.html
+4
-0
circle/dashboard/templates/dashboard/notifications/vm-suspended.html
+4
-0
circle/manager/mancelery.py
+6
-1
circle/vm/tasks/local_periodic_tasks.py
+44
-1
No files found.
circle/dashboard/templates/dashboard/notifications/vm-destroyed.html
0 → 100644
View file @
1a4ca401
{%load i18n%}
{%blocktrans with instance=instance.name url=instance.get_absolute_url %}
Your instance
<a
href=
"{{url}}"
>
{{instance}}
</a>
has been destroyed due to expiration.
{%endblocktrans%}
circle/dashboard/templates/dashboard/notifications/vm-suspended.html
0 → 100644
View file @
1a4ca401
{%load i18n%}
{%blocktrans with instance=instance.name url=instance.get_absolute_url %}
Your instance
<a
href=
"{{url}}"
>
{{instance}}
</a>
has been suspended due to expiration.
{%endblocktrans%}
circle/manager/mancelery.py
View file @
1a4ca401
...
@@ -28,11 +28,16 @@ celery.conf.update(
...
@@ -28,11 +28,16 @@ celery.conf.update(
'schedule'
:
timedelta
(
seconds
=
5
),
'schedule'
:
timedelta
(
seconds
=
5
),
'options'
:
{
'queue'
:
'localhost.man'
}
'options'
:
{
'queue'
:
'localhost.man'
}
},
},
'vm.
periodic_task
s'
:
{
'vm.
update_domain_state
s'
:
{
'task'
:
'vm.tasks.local_periodic_tasks.update_domain_states'
,
'task'
:
'vm.tasks.local_periodic_tasks.update_domain_states'
,
'schedule'
:
timedelta
(
seconds
=
10
),
'schedule'
:
timedelta
(
seconds
=
10
),
'options'
:
{
'queue'
:
'localhost.man'
}
'options'
:
{
'queue'
:
'localhost.man'
}
},
},
'vm.garbage_collector'
:
{
'task'
:
'vm.tasks.local_periodic_tasks.garbage_collector'
,
'schedule'
:
timedelta
(
minutes
=
10
),
'options'
:
{
'queue'
:
'localhost.man'
}
},
'storage.periodic_tasks'
:
{
'storage.periodic_tasks'
:
{
'task'
:
'storage.tasks.periodic_tasks.garbage_collector'
,
'task'
:
'storage.tasks.periodic_tasks.garbage_collector'
,
'schedule'
:
timedelta
(
hours
=
1
),
'schedule'
:
timedelta
(
hours
=
1
),
...
...
circle/vm/tasks/local_periodic_tasks.py
View file @
1a4ca401
from
datetime
import
datetime
import
logging
from
django.utils
import
timezone
from
django.utils.translation
import
ugettext_lazy
as
_
from
manager.mancelery
import
celery
from
manager.mancelery
import
celery
from
vm.models
import
Node
from
vm.models
import
Node
,
Instance
logger
=
logging
.
getLogger
(
__name__
)
@celery.task
(
ignore_result
=
True
)
@celery.task
(
ignore_result
=
True
)
...
@@ -7,3 +14,39 @@ def update_domain_states():
...
@@ -7,3 +14,39 @@ def update_domain_states():
nodes
=
Node
.
objects
.
filter
(
enabled
=
True
)
.
all
()
nodes
=
Node
.
objects
.
filter
(
enabled
=
True
)
.
all
()
for
node
in
nodes
:
for
node
in
nodes
:
node
.
update_vm_states
()
node
.
update_vm_states
()
@celery.task
(
ignore_result
=
True
)
def
garbage_collector
(
timeout
=
15
):
"""Garbage collector for instances.
Suspends and destroys expired instances.
:param timeout: Seconds before TimeOut exception
:type timeout: int
"""
now
=
timezone
.
now
()
for
i
in
Instance
.
objects
.
filter
(
destroyed
=
None
)
.
all
():
if
i
.
time_of_delete
and
now
<
i
.
time_of_delete
:
i
.
destroy_async
()
logger
.
info
(
"Expired instance
%
d destroyed."
,
i
.
pk
)
try
:
i
.
owner
.
profile
.
notify
(
_
(
'Machine destroyed'
),
'dashboard/notifications/vm-destroyed.html'
,
{
'instance'
:
i
})
except
:
logger
.
debug
(
'Could not notify owner of instance
%
d.'
,
i
.
pk
)
elif
(
i
.
time_of_suspend
and
now
<
i
.
time_of_suspend
and
i
.
state
==
'RUNNING'
):
i
.
sleep_async
()
logger
.
info
(
"Expired instance
%
d suspended."
%
i
.
pk
)
try
:
i
.
owner
.
profile
.
notify
(
_
(
'Machine suspended'
),
'dashboard/notifications/vm-suspended.html'
,
{
'instance'
:
i
})
except
:
logger
.
debug
(
'Could not notify owner of instance
%
d.'
,
i
.
pk
)
else
:
logger
.
debug
(
"Instance
%
d didn't expire."
%
i
.
pk
)
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