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
cc728f9b
authored
Sep 29, 2016
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: list unused/rarely used templates
parent
cfae5fec
Pipeline
#229
failed with stage
in 0 seconds
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
5 deletions
+69
-5
circle/dashboard/templates/dashboard/_list-templates.html
+6
-0
circle/dashboard/templates/dashboard/template-list.html
+22
-4
circle/dashboard/views/template.py
+41
-1
No files found.
circle/dashboard/templates/dashboard/_list-templates.html
0 → 100644
View file @
cc728f9b
{% for t in templates %}
<a
href=
"{{ t.get_absolute_url }}"
>
{{ t.name }}
</a>
{% if not forloop.last %},{% endif %}
{% empty %}
-
{% endfor %}
circle/dashboard/templates/dashboard/template-list.html
View file @
cc728f9b
...
...
@@ -63,18 +63,36 @@
</div>
</div>
{% comment %}
<div
class=
"col-md-6"
>
<div
class=
"panel panel-default"
>
<div
class=
"panel-heading"
>
<h3
class=
"no-margin"
><i
class=
"fa fa-desktop"
></i>
Placeholder
</h3>
<h3
class=
"no-margin"
>
<i
class=
"fa fa-puzzle-piece"
></i>
{% trans "Rarely used templates" %}
</h3>
</div>
<div
class=
"panel-body"
>
???
<dl>
<dt>
{% trans "Never instantiated" %}
</dd>
<dd>
{% include "dashboard/_list-templates.html" with templates=unused_templates.never_instantiated %}
</dd>
<dt>
{% trans "Templates without running instances" %}
</dd>
<dd>
{% include "dashboard/_list-templates.html" with templates=unused_templates.templates_wo_instances %}
</dd>
<dt>
{% trans "Templates without instances, last instance created more than 90 days ago" %}
</dd>
<dd>
{% include "dashboard/_list-templates.html" with templates=unused_templates.templates_wo_instances_90 %}
</dd>
<dt>
{% trans "Templates without instances, last instance created more than 180 days ago" %}
</dd>
<dd>
{% include "dashboard/_list-templates.html" with templates=unused_templates.templates_wo_instances_180 %}
</dd>
</dl>
</div>
</div>
</div>
{% endcomment %}
</div>
{% endif %}
{% endblock %}
circle/dashboard/views/template.py
View file @
cc728f9b
...
...
@@ -16,6 +16,7 @@
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
from
__future__
import
unicode_literals
,
absolute_import
from
datetime
import
timedelta
import
json
import
logging
...
...
@@ -24,8 +25,10 @@ from django.contrib.auth.models import User
from
django.contrib.messages.views
import
SuccessMessageMixin
from
django.core.urlresolvers
import
reverse
,
reverse_lazy
from
django.core.exceptions
import
PermissionDenied
,
SuspiciousOperation
from
django.db.models
import
Count
from
django.http
import
HttpResponse
,
HttpResponseRedirect
from
django.shortcuts
import
redirect
,
get_object_or_404
from
django.utils
import
timezone
from
django.utils.translation
import
ugettext
as
_
,
ugettext_noop
from
django.views.generic
import
(
TemplateView
,
CreateView
,
UpdateView
,
...
...
@@ -36,7 +39,9 @@ from braces.views import (
)
from
django_tables2
import
SingleTableView
from
vm.models
import
InstanceTemplate
,
InterfaceTemplate
,
Instance
,
Lease
from
vm.models
import
(
InstanceTemplate
,
InterfaceTemplate
,
Instance
,
Lease
,
InstanceActivity
)
from
storage.models
import
Disk
from
..forms
import
(
...
...
@@ -203,6 +208,41 @@ class TemplateList(LoginRequiredMixin, FilterMixin, SingleTableView):
context
[
'search_form'
]
=
self
.
search_form
# templates without any instances
# [t for t in InstanceTemplate.objects.all()
# if t.instance_set.count() < 1]
never_instantiated
=
context
[
'object_list'
]
.
annotate
(
instance_count
=
Count
(
"instance_set"
))
.
filter
(
instance_count__lt
=
1
)
# templates without active virtual machines
active_statuses
=
Instance
.
STATUS
.
_db_values
-
set
([
"DESTROYED"
])
templates_wo_instances
=
context
[
'object_list'
]
.
exclude
(
pk__in
=
InstanceTemplate
.
objects
.
filter
(
instance_set__status__in
=
active_statuses
)
)
.
exclude
(
pk__in
=
never_instantiated
)
def
get_create_acts_younger_than
(
days
):
return
InstanceActivity
.
objects
.
filter
(
activity_code
=
"vm.Instance.create"
,
finished__gt
=
timezone
.
now
()
-
timedelta
(
days
=
days
))
# templates without active virtual machines
# last machine started later than 90 days
templates_wo_i_90
=
templates_wo_instances
.
exclude
(
instance_set__activity_log__in
=
get_create_acts_younger_than
(
90
))
# templates without active virtual machines
# last machine started later than 180 days
templates_wo_i_180
=
templates_wo_instances
.
exclude
(
instance_set__activity_log__in
=
get_create_acts_younger_than
(
180
))
context
[
'unused_templates'
]
=
{
'never_instantiated'
:
never_instantiated
,
'templates_wo_instances'
:
templates_wo_instances
,
'templates_wo_instances_90'
:
templates_wo_i_90
,
'templates_wo_instances_180'
:
templates_wo_i_180
,
}
return
context
def
get
(
self
,
*
args
,
**
kwargs
):
...
...
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