Commit 6c0ce42b by Szabolcs Gelencser

Show initial template lists

parent 0a3d40e0
......@@ -2,9 +2,7 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="1fbec8af-5a7c-40f9-b994-83ac07d1ae1d" name="Default" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
<change beforePath="$PROJECT_DIR$/circle/network/templates/network/vxlan-edit.html" afterPath="$PROJECT_DIR$/circle/network/templates/network/vxlan-edit.html" />
<change beforePath="$PROJECT_DIR$/circle/network/views.py" afterPath="$PROJECT_DIR$/circle/network/views.py" />
<change beforePath="$PROJECT_DIR$/circle/dashboard/views/template.py" afterPath="$PROJECT_DIR$/circle/dashboard/views/template.py" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="TRACKING_ENABLED" value="true" />
......@@ -34,7 +32,7 @@
</component>
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file leaf-file-name="vxlan-edit.html" pinned="false" current-in-tab="true">
<file leaf-file-name="vxlan-edit.html" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/circle/network/templates/network/vxlan-edit.html">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="431">
......@@ -46,6 +44,26 @@
</provider>
</entry>
</file>
<file leaf-file-name="template.py" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/circle/dashboard/views/template.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="153">
<caret line="203" column="11" lean-forward="true" selection-start-line="203" selection-start-column="11" selection-end-line="203" selection-end-column="11" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="template-list.html" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/circle/dashboard/templates/dashboard/template-list.html">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="125">
<caret line="16" column="18" lean-forward="true" selection-start-line="16" selection-start-column="18" selection-end-line="16" selection-end-column="18" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="views.py" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/circle/network/views.py">
<provider selected="true" editor-type-id="text-editor">
......@@ -80,7 +98,6 @@
</component>
<component name="FindInProjectRecents">
<findStrings>
<find>removeinterface</find>
<find>vm_op</find>
<find>hidden</find>
<find>removeint</find>
......@@ -110,6 +127,7 @@
<find>connect</find>
<find>vxlandele</find>
<find>vxlandeta</find>
<find>exclude</find>
</findStrings>
<replaceStrings>
<replace>'ACTIVE'</replace>
......@@ -136,7 +154,6 @@
<option value="$PROJECT_DIR$/circle/dashboard/templatetags/instance_tags.py" />
<option value="$PROJECT_DIR$/circle/dashboard/templates/dashboard/template-edit.html" />
<option value="$PROJECT_DIR$/circle/dashboard/views/util.py" />
<option value="$PROJECT_DIR$/circle/dashboard/views/template.py" />
<option value="$PROJECT_DIR$/circle/dashboard/urls.py" />
<option value="$PROJECT_DIR$/circle/circle/os_policies/glance_policy.json" />
<option value="$PROJECT_DIR$/circle/circle/os_policies/keystone_policy.json" />
......@@ -182,6 +199,7 @@
<option value="$PROJECT_DIR$/circle/network/operations.py" />
<option value="$PROJECT_DIR$/circle/network/views.py" />
<option value="$PROJECT_DIR$/circle/network/templates/network/vxlan-edit.html" />
<option value="$PROJECT_DIR$/circle/dashboard/views/template.py" />
</list>
</option>
</component>
......@@ -632,27 +650,6 @@ certifi.where()</expression-string>
</expressions>
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/circle/dashboard/compilers.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="0">
<caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
</state>
</provider>
</entry>
<entry file="file://$USER_HOME$/.virtualenvs/cloud/local/lib/python2.7/site-packages/urllib3/connectionpool.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="102">
<caret line="857" column="0" lean-forward="false" selection-start-line="857" selection-start-column="0" selection-end-line="857" selection-end-column="0" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/circle/common/management/commands/watch.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="204">
<caret line="32" column="0" lean-forward="true" selection-start-line="32" selection-start-column="0" selection-end-line="32" selection-end-column="0" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/circle/common/management/commands/compileless.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="0">
......@@ -771,14 +768,6 @@ certifi.where()</expression-string>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/circle/dashboard/views/util.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="148">
<caret line="296" column="19" lean-forward="false" selection-start-line="296" selection-start-column="19" selection-end-line="296" selection-end-column="32" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/circle/circle/settings/base.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="482">
......@@ -1029,6 +1018,14 @@ certifi.where()</expression-string>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/circle/dashboard/views/util.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="44">
<caret line="107" column="41" lean-forward="false" selection-start-line="107" selection-start-column="27" selection-end-line="107" selection-end-column="41" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/circle/network/templates/network/vxlan-edit.html">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="431">
......@@ -1039,5 +1036,29 @@ certifi.where()</expression-string>
</state>
</provider>
</entry>
<entry file="file://$USER_HOME$/.virtualenvs/cloud/local/lib/python2.7/site-packages/django/views/generic/list.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="358">
<caret line="159" column="0" lean-forward="false" selection-start-line="159" selection-start-column="0" selection-end-line="159" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/circle/dashboard/templates/dashboard/template-list.html">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="125">
<caret line="16" column="18" lean-forward="true" selection-start-line="16" selection-start-column="18" selection-end-line="16" selection-end-column="18" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/circle/dashboard/views/template.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="153">
<caret line="203" column="11" lean-forward="true" selection-start-line="203" selection-start-column="11" selection-end-line="203" selection-end-column="11" />
<folding />
</state>
</provider>
</entry>
</component>
</project>
\ No newline at end of file
......@@ -20,6 +20,7 @@ from datetime import timedelta
import json
import logging
import openstack_api
from django.contrib import messages
from django.contrib.auth.models import User
from django.contrib.messages.views import SuccessMessageMixin
......@@ -196,52 +197,52 @@ class TemplateList(LoginRequiredMixin, FilterMixin, SingleTableView):
def get_context_data(self, *args, **kwargs):
context = super(TemplateList, self).get_context_data(*args, **kwargs)
user = self.request.user
leases_w_operator = Lease.get_objects_with_level("operator", user)
context['lease_table'] = LeaseListTable(
leases_w_operator, request=self.request,
template="django_tables2/table_no_page.html",
)
# leases_w_operator = Lease.get_objects_with_level("operator", user)
# context['lease_table'] = LeaseListTable(
# leases_w_operator, request=self.request,
# template="django_tables2/table_no_page.html",
# )
context['show_lease_table'] = (
leases_w_operator.count() > 0 or
user.has_perm("vm.create_leases")
# leases_w_operator.count() > 0 or
# user.has_perm("vm.create_leases")
False
)
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,
}
# tem0for 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
......@@ -249,12 +250,14 @@ class TemplateList(LoginRequiredMixin, FilterMixin, SingleTableView):
self.search_form = TemplateListSearchForm(self.request.GET)
self.search_form.full_clean()
if self.request.is_ajax():
templates = [{
'icon': i.os_type,
'system': i.system,
'url': reverse("dashboard.views.template-detail",
kwargs={'pk': i.pk}),
'name': i.name} for i in self.get_queryset()]
templates = [
{
'icon': i.os_type,
'system': i.system,
'url': reverse("dashboard.views.template-detail",
kwargs={'pk': i.pk}),
'name': i.name
} for i in self.get_queryset()]
return HttpResponse(
json.dumps(templates),
content_type="application/json",
......@@ -262,29 +265,8 @@ class TemplateList(LoginRequiredMixin, FilterMixin, SingleTableView):
else:
return super(TemplateList, self).get(*args, **kwargs)
def create_acl_queryset(self, model):
queryset = super(TemplateList, self).create_acl_queryset(model)
sql = ("SELECT count(*) FROM vm_instance WHERE "
"vm_instance.template_id = vm_instancetemplate.id and "
"vm_instance.destroyed_at is null and "
"vm_instance.status = 'RUNNING'")
queryset = queryset.extra(select={'running': sql})
return queryset
def get_queryset(self):
logger.debug('TemplateList.get_queryset() called. User: %s',
unicode(self.request.user))
qs = self.create_acl_queryset(InstanceTemplate)
self.create_fake_get()
try:
filters, excludes = self.get_queryset_filters()
qs = qs.filter(**filters).exclude(**excludes).distinct()
except ValueError:
messages.error(self.request, _("Error during filtering."))
return qs.select_related("lease", "owner", "owner__profile")
return InstanceTemplate.objects.all()
class TemplateDelete(DeleteViewBase):
model = InstanceTemplate
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment