Commit 6c0ce42b by Szabolcs Gelencser

Show initial template lists

parent 0a3d40e0
...@@ -2,9 +2,7 @@ ...@@ -2,9 +2,7 @@
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="1fbec8af-5a7c-40f9-b994-83ac07d1ae1d" name="Default" comment=""> <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/dashboard/views/template.py" afterPath="$PROJECT_DIR$/circle/dashboard/views/template.py" />
<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" />
</list> </list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="TRACKING_ENABLED" value="true" /> <option name="TRACKING_ENABLED" value="true" />
...@@ -34,7 +32,7 @@ ...@@ -34,7 +32,7 @@
</component> </component>
<component name="FileEditorManager"> <component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300"> <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"> <entry file="file://$PROJECT_DIR$/circle/network/templates/network/vxlan-edit.html">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="431"> <state relative-caret-position="431">
...@@ -46,6 +44,26 @@ ...@@ -46,6 +44,26 @@
</provider> </provider>
</entry> </entry>
</file> </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"> <file leaf-file-name="views.py" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/circle/network/views.py"> <entry file="file://$PROJECT_DIR$/circle/network/views.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
...@@ -80,7 +98,6 @@ ...@@ -80,7 +98,6 @@
</component> </component>
<component name="FindInProjectRecents"> <component name="FindInProjectRecents">
<findStrings> <findStrings>
<find>removeinterface</find>
<find>vm_op</find> <find>vm_op</find>
<find>hidden</find> <find>hidden</find>
<find>removeint</find> <find>removeint</find>
...@@ -110,6 +127,7 @@ ...@@ -110,6 +127,7 @@
<find>connect</find> <find>connect</find>
<find>vxlandele</find> <find>vxlandele</find>
<find>vxlandeta</find> <find>vxlandeta</find>
<find>exclude</find>
</findStrings> </findStrings>
<replaceStrings> <replaceStrings>
<replace>'ACTIVE'</replace> <replace>'ACTIVE'</replace>
...@@ -136,7 +154,6 @@ ...@@ -136,7 +154,6 @@
<option value="$PROJECT_DIR$/circle/dashboard/templatetags/instance_tags.py" /> <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/templates/dashboard/template-edit.html" />
<option value="$PROJECT_DIR$/circle/dashboard/views/util.py" /> <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/dashboard/urls.py" />
<option value="$PROJECT_DIR$/circle/circle/os_policies/glance_policy.json" /> <option value="$PROJECT_DIR$/circle/circle/os_policies/glance_policy.json" />
<option value="$PROJECT_DIR$/circle/circle/os_policies/keystone_policy.json" /> <option value="$PROJECT_DIR$/circle/circle/os_policies/keystone_policy.json" />
...@@ -182,6 +199,7 @@ ...@@ -182,6 +199,7 @@
<option value="$PROJECT_DIR$/circle/network/operations.py" /> <option value="$PROJECT_DIR$/circle/network/operations.py" />
<option value="$PROJECT_DIR$/circle/network/views.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/network/templates/network/vxlan-edit.html" />
<option value="$PROJECT_DIR$/circle/dashboard/views/template.py" />
</list> </list>
</option> </option>
</component> </component>
...@@ -632,27 +650,6 @@ certifi.where()</expression-string> ...@@ -632,27 +650,6 @@ certifi.where()</expression-string>
</expressions> </expressions>
</component> </component>
<component name="editorHistoryManager"> <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"> <entry file="file://$PROJECT_DIR$/circle/common/management/commands/compileless.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="0"> <state relative-caret-position="0">
...@@ -771,14 +768,6 @@ certifi.where()</expression-string> ...@@ -771,14 +768,6 @@ certifi.where()</expression-string>
</state> </state>
</provider> </provider>
</entry> </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"> <entry file="file://$PROJECT_DIR$/circle/circle/settings/base.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="482"> <state relative-caret-position="482">
...@@ -1029,6 +1018,14 @@ certifi.where()</expression-string> ...@@ -1029,6 +1018,14 @@ certifi.where()</expression-string>
</state> </state>
</provider> </provider>
</entry> </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"> <entry file="file://$PROJECT_DIR$/circle/network/templates/network/vxlan-edit.html">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="431"> <state relative-caret-position="431">
...@@ -1039,5 +1036,29 @@ certifi.where()</expression-string> ...@@ -1039,5 +1036,29 @@ certifi.where()</expression-string>
</state> </state>
</provider> </provider>
</entry> </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> </component>
</project> </project>
\ No newline at end of file
...@@ -20,6 +20,7 @@ from datetime import timedelta ...@@ -20,6 +20,7 @@ from datetime import timedelta
import json import json
import logging import logging
import openstack_api
from django.contrib import messages from django.contrib import messages
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.contrib.messages.views import SuccessMessageMixin from django.contrib.messages.views import SuccessMessageMixin
...@@ -196,52 +197,52 @@ class TemplateList(LoginRequiredMixin, FilterMixin, SingleTableView): ...@@ -196,52 +197,52 @@ class TemplateList(LoginRequiredMixin, FilterMixin, SingleTableView):
def get_context_data(self, *args, **kwargs): def get_context_data(self, *args, **kwargs):
context = super(TemplateList, self).get_context_data(*args, **kwargs) context = super(TemplateList, self).get_context_data(*args, **kwargs)
user = self.request.user user = self.request.user
leases_w_operator = Lease.get_objects_with_level("operator", user) # leases_w_operator = Lease.get_objects_with_level("operator", user)
context['lease_table'] = LeaseListTable( # context['lease_table'] = LeaseListTable(
leases_w_operator, request=self.request, # leases_w_operator, request=self.request,
template="django_tables2/table_no_page.html", # template="django_tables2/table_no_page.html",
) # )
context['show_lease_table'] = ( context['show_lease_table'] = (
leases_w_operator.count() > 0 or # leases_w_operator.count() > 0 or
user.has_perm("vm.create_leases") # user.has_perm("vm.create_leases")
False
) )
context['search_form'] = self.search_form context['search_form'] = self.search_form
# templates without any instances # tem0for t in InstanceTemplate.objects.all()
# [t for t in InstanceTemplate.objects.all() # # if t.instance_set.count() < 1]
# if t.instance_set.count() < 1] # never_instantiated = context['object_list'].annotate(
never_instantiated = context['object_list'].annotate( # instance_count=Count("instance_set")).filter(instance_count__lt=1)
instance_count=Count("instance_set")).filter(instance_count__lt=1) #
# # templates without active virtual machines
# templates without active virtual machines # active_statuses = Instance.STATUS._db_values - set(["DESTROYED"])
active_statuses = Instance.STATUS._db_values - set(["DESTROYED"]) # templates_wo_instances = context['object_list'].exclude(
templates_wo_instances = context['object_list'].exclude( # pk__in=InstanceTemplate.objects.filter(
pk__in=InstanceTemplate.objects.filter( # instance_set__status__in=active_statuses)
instance_set__status__in=active_statuses) # ).exclude(pk__in=never_instantiated)
).exclude(pk__in=never_instantiated) #
# def get_create_acts_younger_than(days):
def get_create_acts_younger_than(days): # return InstanceActivity.objects.filter(
return InstanceActivity.objects.filter( # activity_code="vm.Instance.create",
activity_code="vm.Instance.create", # finished__gt=timezone.now() - timedelta(days=days))
finished__gt=timezone.now() - timedelta(days=days)) #
# # templates without active virtual machines
# templates without active virtual machines # # last machine started later than 90 days
# last machine started later than 90 days # templates_wo_i_90 = templates_wo_instances.exclude(
templates_wo_i_90 = templates_wo_instances.exclude( # instance_set__activity_log__in=get_create_acts_younger_than(90))
instance_set__activity_log__in=get_create_acts_younger_than(90)) #
# # templates without active virtual machines
# templates without active virtual machines # # last machine started later than 180 days
# last machine started later than 180 days # templates_wo_i_180 = templates_wo_instances.exclude(
templates_wo_i_180 = templates_wo_instances.exclude( # instance_set__activity_log__in=get_create_acts_younger_than(180))
instance_set__activity_log__in=get_create_acts_younger_than(180)) #
# context['unused_templates'] = {
context['unused_templates'] = { # 'never_instantiated': never_instantiated,
'never_instantiated': never_instantiated, # 'templates_wo_instances': templates_wo_instances,
'templates_wo_instances': templates_wo_instances, # 'templates_wo_instances_90': templates_wo_i_90,
'templates_wo_instances_90': templates_wo_i_90, # 'templates_wo_instances_180': templates_wo_i_180,
'templates_wo_instances_180': templates_wo_i_180, # }
}
return context return context
...@@ -249,12 +250,14 @@ class TemplateList(LoginRequiredMixin, FilterMixin, SingleTableView): ...@@ -249,12 +250,14 @@ class TemplateList(LoginRequiredMixin, FilterMixin, SingleTableView):
self.search_form = TemplateListSearchForm(self.request.GET) self.search_form = TemplateListSearchForm(self.request.GET)
self.search_form.full_clean() self.search_form.full_clean()
if self.request.is_ajax(): if self.request.is_ajax():
templates = [{ templates = [
{
'icon': i.os_type, 'icon': i.os_type,
'system': i.system, 'system': i.system,
'url': reverse("dashboard.views.template-detail", 'url': reverse("dashboard.views.template-detail",
kwargs={'pk': i.pk}), kwargs={'pk': i.pk}),
'name': i.name} for i in self.get_queryset()] 'name': i.name
} for i in self.get_queryset()]
return HttpResponse( return HttpResponse(
json.dumps(templates), json.dumps(templates),
content_type="application/json", content_type="application/json",
...@@ -262,29 +265,8 @@ class TemplateList(LoginRequiredMixin, FilterMixin, SingleTableView): ...@@ -262,29 +265,8 @@ class TemplateList(LoginRequiredMixin, FilterMixin, SingleTableView):
else: else:
return super(TemplateList, self).get(*args, **kwargs) 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): def get_queryset(self):
logger.debug('TemplateList.get_queryset() called. User: %s', return InstanceTemplate.objects.all()
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")
class TemplateDelete(DeleteViewBase): class TemplateDelete(DeleteViewBase):
model = InstanceTemplate 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