Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
circlestack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
e155a219
authored
Mar 19, 2018
by
Szabolcs Gelencser
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add initial template details view
parent
29ed5533
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
132 additions
and
129 deletions
+132
-129
.idea/workspace.xml
+0
-0
circle/circle/os_policies/circle_policy.json
+2
-2
circle/dashboard/forms.py
+67
-67
circle/dashboard/templates/dashboard/template-edit.html
+13
-13
circle/dashboard/urls.py
+9
-8
circle/dashboard/views/template.py
+41
-39
circle/dashboard/views/util.py
+0
-0
No files found.
.idea/workspace.xml
View file @
e155a219
This diff is collapsed.
Click to expand it.
circle/circle/os_policies/circle_policy.json
View file @
e155a219
{
{
"admin_or_owner"
:
"is_admin:True or (role:admin and is_admin_project:True) or project_id:%(project_id)s"
,
"admin_or_owner"
:
"is_admin:True or (role:admin and is_admin_project:True) or project_id:%(project_id)s"
,
"default"
:
"rule:admin_or_owner"
,
"template:create"
:
""
"template:create"
:
"
rule:admin_or_owner
"
}
}
\ No newline at end of file
circle/dashboard/forms.py
View file @
e155a219
...
@@ -502,77 +502,77 @@ class NodeForm(forms.ModelForm):
...
@@ -502,77 +502,77 @@ class NodeForm(forms.ModelForm):
class
TemplateForm
(
forms
.
ModelForm
):
class
TemplateForm
(
forms
.
ModelForm
):
networks
=
forms
.
ModelMultipleChoiceField
(
# networks = forms.ModelMultipleChoiceField(queryset=None, required=False, label=_("Networks"))
queryset
=
None
,
required
=
False
,
label
=
_
(
"Networks"
))
#
# num_cores = forms.IntegerField(widget=forms.NumberInput(attrs={
num_cores
=
forms
.
IntegerField
(
widget
=
forms
.
NumberInput
(
attrs
=
{
# 'class': "form-control input-tags cpu-count-input",
'class'
:
"form-control input-tags cpu-count-input"
,
# 'min': 1,
'min'
:
1
,
# 'max': 10,
'max'
:
10
,
# 'required': "",
'required'
:
""
,
# }),
}),
# min_value=1, max_value=10,
min_value
=
1
,
max_value
=
10
,
# )
)
#
# ram_size = forms.IntegerField(widget=forms.NumberInput(attrs={
ram_size
=
forms
.
IntegerField
(
widget
=
forms
.
NumberInput
(
attrs
=
{
# 'class': "form-control input-tags ram-input",
'class'
:
"form-control input-tags ram-input"
,
# 'min': 128,
'min'
:
128
,
# 'max': MAX_NODE_RAM,
'max'
:
MAX_NODE_RAM
,
# 'step': 128,
'step'
:
128
,
# 'required': "",
'required'
:
""
,
# }),
}),
# min_value=128, max_value=MAX_NODE_RAM,
min_value
=
128
,
max_value
=
MAX_NODE_RAM
,
# )
)
#
# priority = forms.ChoiceField(priority_choices, widget=forms.Select(attrs={
priority
=
forms
.
ChoiceField
(
priority_choices
,
widget
=
forms
.
Select
(
attrs
=
{
# 'class': "form-control input-tags cpu-priority-input",
'class'
:
"form-control input-tags cpu-priority-input"
,
# }))
}))
name
=
forms
.
TextInput
()
flavor
=
forms
.
ChoiceField
([
'a'
,
'b'
,
'c'
])
def
__init__
(
self
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
user
=
kwargs
.
pop
(
"user"
,
None
)
self
.
user
=
kwargs
.
pop
(
"user"
,
None
)
super
(
TemplateForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
super
(
TemplateForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
#
self
.
fields
[
'networks'
]
.
queryset
=
Vlan
.
get_objects_with_level
(
# self.fields['networks'].queryset = ()#Vlan.get_objects_with_level('user', self.user)
'user'
,
self
.
user
)
#
# data = self.data.copy()
data
=
self
.
data
.
copy
()
# data['owner'] = self.user.pk
data
[
'owner'
]
=
self
.
user
.
pk
# self.data = data
self
.
data
=
data
#
# if self.instance.pk:
if
self
.
instance
.
pk
:
# n = self.instance.interface_set.values_list("vlan", flat=True)
n
=
self
.
instance
.
interface_set
.
values_list
(
"vlan"
,
flat
=
True
)
# self.initial['networks'] = n
self
.
initial
[
'networks'
]
=
n
#
# if self.instance.pk and not self.instance.has_level(self.user, 'owner'):
if
self
.
instance
.
pk
and
not
self
.
instance
.
has_level
(
self
.
user
,
# self.allowed_fields = ()
'owner'
):
# else:
self
.
allowed_fields
=
()
# self.allowed_fields = (
else
:
# 'name', 'access_method', 'description', 'system', 'tags',
self
.
allowed_fields
=
(
# 'arch', 'lease', 'has_agent')
'name'
,
'access_method'
,
'description'
,
'system'
,
'tags'
,
# if (self.user.has_perm('vm.change_template_resources') or
'arch'
,
'lease'
,
'has_agent'
)
# not self.instance.pk):
if
(
self
.
user
.
has_perm
(
'vm.change_template_resources'
)
or
# self.allowed_fields += tuple(set(self.fields.keys()) -
not
self
.
instance
.
pk
):
# set(['raw_data']))
self
.
allowed_fields
+=
tuple
(
set
(
self
.
fields
.
keys
())
-
# if self.user.is_superuser:
set
([
'raw_data'
]))
# self.allowed_fields += ('raw_data', )
if
self
.
user
.
is_superuser
:
# for name, field in self.fields.items():
self
.
allowed_fields
+=
(
'raw_data'
,
)
# if name not in self.allowed_fields:
for
name
,
field
in
self
.
fields
.
items
():
# field.widget.attrs['disabled'] = 'disabled'
if
name
not
in
self
.
allowed_fields
:
#
field
.
widget
.
attrs
[
'disabled'
]
=
'disabled'
# if not self.instance.pk and len(self.errors) < 1:
# self.initial['num_cores'] = 1
if
not
self
.
instance
.
pk
and
len
(
self
.
errors
)
<
1
:
# self.initial['priority'] = 10
self
.
initial
[
'num_cores'
]
=
1
# self.initial['ram_size'] = 512
self
.
initial
[
'priority'
]
=
10
# self.initial['max_ram_size'] = 512
self
.
initial
[
'ram_size'
]
=
512
#
self
.
initial
[
'max_ram_size'
]
=
512
# lease_queryset = (
# Lease.get_objects_with_level("operator", self.user).distinct() |
lease_queryset
=
(
# Lease.objects.filter(pk=self.instance.lease_id).distinct())
Lease
.
get_objects_with_level
(
"operator"
,
self
.
user
)
.
distinct
()
|
#
Lease
.
objects
.
filter
(
pk
=
self
.
instance
.
lease_id
)
.
distinct
())
# self.fields["lease"].queryset = lease_queryset
#
self
.
fields
[
"lease"
]
.
queryset
=
lease_queryset
# self.fields['raw_data'].validators.append(domain_validator)
self
.
fields
[
'raw_data'
]
.
validators
.
append
(
domain_validator
)
def
clean_owner
(
self
):
def
clean_owner
(
self
):
if
self
.
instance
.
pk
is
not
None
:
if
self
.
instance
.
pk
is
not
None
:
...
...
circle/dashboard/templates/dashboard/template-edit.html
View file @
e155a219
...
@@ -39,26 +39,26 @@
...
@@ -39,26 +39,26 @@
<fieldset
class=
"resources-sliders"
>
<fieldset
class=
"resources-sliders"
>
<legend>
{% trans "Resource configuration" %}
</legend>
<legend>
{% trans "Resource configuration" %}
</legend>
{% include "dashboard/_resources-sliders.html" with field_priority=form.priority field_num_cores=form.num_cores field_ram_size=form.ram_size %}
{% include "dashboard/_resources-sliders.html" with field_priority=form.priority field_num_cores=form.num_cores field_ram_size=form.ram_size %}
{{ form.max_ram_size|as_crispy_field }
}
{# {{ form.max_ram_size|as_crispy_field }}#
}
</fieldset>
</fieldset>
<fieldset>
<fieldset>
<legend>
{% trans "Virtual machine settings" %}
</legend>
<legend>
{% trans "Virtual machine settings" %}
</legend>
{{ form.arch|as_crispy_field }
}
{# {{ form.arch|as_crispy_field }}#
}
{{ form.access_method|as_crispy_field }
}
{# {{ form.access_method|as_crispy_field }}#
}
{{ form.boot_menu|as_crispy_field }
}
{# {{ form.boot_menu|as_crispy_field }}#
}
{{ form.raw_data|as_crispy_field }
}
{# {{ form.raw_data|as_crispy_field }}#
}
{{ form.req_traits|as_crispy_field }
}
{# {{ form.req_traits|as_crispy_field }}#
}
{{ form.description|as_crispy_field }
}
{# {{ form.description|as_crispy_field }}#
}
{{ form.system|as_crispy_field }
}
{# {{ form.system|as_crispy_field }}#
}
{{ form.has_agent|as_crispy_field }
}
{# {{ form.has_agent|as_crispy_field }}#
}
</fieldset>
</fieldset>
<fieldset>
<fieldset>
<legend>
{% trans "External resources" %}
</legend>
<legend>
{% trans "External resources" %}
</legend>
{{ form.networks|as_crispy_field }
}
{# {{ form.networks|as_crispy_field }}#
}
{{ form.lease|as_crispy_field }
}
{# {{ form.lease|as_crispy_field }}#
}
{##}
{{ form.tags|as_crispy_field }
}
{# {{ form.tags|as_crispy_field }}#
}
</fieldset>
</fieldset>
<input
type=
"submit"
value=
"{% trans "
Save
changes
"
%}"
class=
"btn btn-primary"
>
<input
type=
"submit"
value=
"{% trans "
Save
changes
"
%}"
class=
"btn btn-primary"
>
...
...
circle/dashboard/urls.py
View file @
e155a219
...
@@ -18,7 +18,8 @@
...
@@ -18,7 +18,8 @@
from
__future__
import
absolute_import
from
__future__
import
absolute_import
from
dashboard.views.autocomplete
import
AclUserGroupAutocomplete
,
AclUserAutocomplete
from
dashboard.views.autocomplete
import
AclUserGroupAutocomplete
,
AclUserAutocomplete
from
dashboard.views.template
import
TemplateList
,
TemplateChoose
,
TemplateDetail
from
dashboard.views.template
import
TemplateList
,
TemplateChoose
,
TemplateDetail
,
TemplateDelete
,
\
TransferTemplateOwnershipConfirmView
,
TransferTemplateOwnershipView
from
dashboard.views.vm
import
VmDetailView
,
VmList
,
VmCreate
,
vm_activity
,
vm_ops
,
FavouriteView
,
VmPlainImageCreate
from
dashboard.views.vm
import
VmDetailView
,
VmList
,
VmCreate
,
vm_activity
,
vm_ops
,
FavouriteView
,
VmPlainImageCreate
from
django.conf.urls
import
url
from
django.conf.urls
import
url
...
@@ -52,10 +53,10 @@ urlpatterns = [
...
@@ -52,10 +53,10 @@ urlpatterns = [
name
=
'dashboard.views.template-detail'
),
name
=
'dashboard.views.template-detail'
),
url
(
r"^template/list/$"
,
TemplateList
.
as_view
(),
url
(
r"^template/list/$"
,
TemplateList
.
as_view
(),
name
=
"dashboard.views.template-list"
),
name
=
"dashboard.views.template-list"
),
#
url(r"^template/delete/(?P<pk>\d+)/$", TemplateDelete.as_view(),
url
(
r"^template/delete/(?P<pk>\d+)/$"
,
TemplateDelete
.
as_view
(),
#
name="dashboard.views.template-delete"),
name
=
"dashboard.views.template-delete"
),
#
url(r'^template/(?P<pk>\d+)/tx/$', TransferTemplateOwnershipView.as_view(),
url
(
r'^template/(?P<pk>\d+)/tx/$'
,
TransferTemplateOwnershipView
.
as_view
(),
#
name='dashboard.views.template-transfer-ownership'),
name
=
'dashboard.views.template-transfer-ownership'
),
url
(
r'^vm/(?P<pk>[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/$'
,
VmDetailView
.
as_view
(),
url
(
r'^vm/(?P<pk>[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/$'
,
VmDetailView
.
as_view
(),
name
=
'dashboard.views.detail'
),
name
=
'dashboard.views.detail'
),
# url(r'^vm/(?P<pk>\d+)/vnctoken/$', VmDetailVncTokenView.as_view(),
# url(r'^vm/(?P<pk>\d+)/vnctoken/$', VmDetailVncTokenView.as_view(),
...
@@ -88,9 +89,9 @@ urlpatterns = [
...
@@ -88,9 +89,9 @@ urlpatterns = [
# url(r'^vm/tx/(?P<key>.*)/?$',
# url(r'^vm/tx/(?P<key>.*)/?$',
# TransferInstanceOwnershipConfirmView.as_view(),
# TransferInstanceOwnershipConfirmView.as_view(),
# name='dashboard.views.vm-transfer-ownership-confirm'),
# name='dashboard.views.vm-transfer-ownership-confirm'),
#
url(r'^template/tx/(?P<key>.*)/?$',
url
(
r'^template/tx/(?P<key>.*)/?$'
,
#
TransferTemplateOwnershipConfirmView.as_view(),
TransferTemplateOwnershipConfirmView
.
as_view
(),
#
name='dashboard.views.template-transfer-ownership-confirm'),
name
=
'dashboard.views.template-transfer-ownership-confirm'
),
# url(r'^node/delete/(?P<pk>\d+)/$', NodeDelete.as_view(),
# url(r'^node/delete/(?P<pk>\d+)/$', NodeDelete.as_view(),
# name="dashboard.views.delete-node"),
# name="dashboard.views.delete-node"),
# url(r'^node/(?P<pk>\d+)/activity/$', NodeActivityView.as_view(),
# url(r'^node/(?P<pk>\d+)/activity/$', NodeActivityView.as_view(),
...
...
circle/dashboard/views/template.py
View file @
e155a219
...
@@ -53,8 +53,8 @@ from .util import (
...
@@ -53,8 +53,8 @@ from .util import (
AclUpdateView
,
FilterMixin
,
AclUpdateView
,
FilterMixin
,
# TransferOwnershipConfirmView, TransferOwnershipView,
# TransferOwnershipConfirmView, TransferOwnershipView,
# DeleteViewBase,
# DeleteViewBase,
GraphMixin
GraphMixin
,
)
DeleteViewBase
,
TransferOwnershipConfirmView
,
TransferOwnershipView
)
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
...
@@ -285,22 +285,21 @@ class TemplateList(LoginRequiredMixin, FilterMixin, SingleTableView):
...
@@ -285,22 +285,21 @@ class TemplateList(LoginRequiredMixin, FilterMixin, SingleTableView):
return
qs
.
select_related
(
"lease"
,
"owner"
,
"owner__profile"
)
return
qs
.
select_related
(
"lease"
,
"owner"
,
"owner__profile"
)
#
# class TemplateDelete(DeleteViewBase):
# model = InstanceTemplate
# success_message = _("Template successfully deleted.")
#
# def get_success_url(self):
# return reverse("dashboard.views.template-list")
#
# def delete_obj(self, request, *args, **kwargs):
# object = self.get_object()
# object.destroy_disks()
# object.delete()
class
TemplateDelete
(
DeleteViewBase
):
model
=
InstanceTemplate
success_message
=
_
(
"Template successfully deleted."
)
def
get_success_url
(
self
):
return
reverse
(
"dashboard.views.template-list"
)
def
delete_obj
(
self
,
request
,
*
args
,
**
kwargs
):
object
=
self
.
get_object
()
object
.
destroy_disks
()
object
.
delete
()
class
TemplateDetail
(
LoginRequiredMixin
,
GraphMixin
,
SuccessMessageMixin
,
UpdateView
):
class
TemplateDetail
(
LoginRequiredMixin
,
GraphMixin
,
SuccessMessageMixin
,
UpdateView
):
model
=
InstanceTemplate
model
=
InstanceTemplate
template_name
=
"dashboard/template-edit.html"
template_name
=
"dashboard/template-edit.html"
form_class
=
TemplateForm
form_class
=
TemplateForm
...
@@ -308,8 +307,11 @@ class TemplateDetail(LoginRequiredMixin, GraphMixin,
...
@@ -308,8 +307,11 @@ class TemplateDetail(LoginRequiredMixin, GraphMixin,
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
template
=
self
.
get_object
()
template
=
self
.
get_object
()
if
not
template
.
has_level
(
request
.
user
,
'user'
):
#TODO: multiple users
if
template
.
owner_id
!=
request
.
user
.
id
:
raise
PermissionDenied
()
raise
PermissionDenied
()
if
request
.
is_ajax
():
if
request
.
is_ajax
():
template
=
{
template
=
{
'num_cores'
:
template
.
num_cores
,
'num_cores'
:
template
.
num_cores
,
...
@@ -334,15 +336,15 @@ class TemplateDetail(LoginRequiredMixin, GraphMixin,
...
@@ -334,15 +336,15 @@ class TemplateDetail(LoginRequiredMixin, GraphMixin,
return
super
(
TemplateDetail
,
self
)
.
get
(
request
,
*
args
,
**
kwargs
)
return
super
(
TemplateDetail
,
self
)
.
get
(
request
,
*
args
,
**
kwargs
)
def
get_context_data
(
self
,
**
kwargs
):
def
get_context_data
(
self
,
**
kwargs
):
obj
=
self
.
get_object
()
template
=
self
.
get_object
()
context
=
super
(
TemplateDetail
,
self
)
.
get_context_data
(
**
kwargs
)
context
=
super
(
TemplateDetail
,
self
)
.
get_context_data
(
**
kwargs
)
context
[
'acl'
]
=
AclUpdateView
.
get_acl_data
(
#
context['acl'] = AclUpdateView.get_acl_data(
obj
,
self
.
request
.
user
,
'dashboard.views.template-acl'
)
# template
, self.request.user, 'dashboard.views.template-acl')
context
[
'disks'
]
=
obj
.
disks
.
all
()
# context['disks'] = template
.disks.all()
context
[
'is_owner'
]
=
obj
.
has_level
(
self
.
request
.
user
,
'owner'
)
context
[
'is_owner'
]
=
template
.
owner_id
==
self
.
request
.
user
.
id
context
[
'aclform'
]
=
AclUserOrGroupAddForm
()
context
[
'aclform'
]
=
AclUserOrGroupAddForm
()
context
[
'parent'
]
=
obj
.
parent
# context['parent'] = template
.parent
context
[
'show_graph'
]
=
obj
.
has_level
(
self
.
request
.
user
,
'operator'
)
# context['show_graph'] = template
.has_level(self.request.user, 'operator')
return
context
return
context
def
get_success_url
(
self
):
def
get_success_url
(
self
):
...
@@ -476,18 +478,18 @@ class LeaseDetail(LoginRequiredMixin, SuccessMessageMixin, UpdateView):
...
@@ -476,18 +478,18 @@ class LeaseDetail(LoginRequiredMixin, SuccessMessageMixin, UpdateView):
# object.delete()
# object.delete()
#
#
#
#
#
class TransferTemplateOwnershipConfirmView(TransferOwnershipConfirmView):
class
TransferTemplateOwnershipConfirmView
(
TransferOwnershipConfirmView
):
#
template = "dashboard/confirm/transfer-template-ownership.html"
template
=
"dashboard/confirm/transfer-template-ownership.html"
#
model = InstanceTemplate
model
=
InstanceTemplate
#
#
#
class TransferTemplateOwnershipView(TransferOwnershipView):
class
TransferTemplateOwnershipView
(
TransferOwnershipView
):
#
confirm_view = TransferTemplateOwnershipConfirmView
confirm_view
=
TransferTemplateOwnershipConfirmView
#
model = InstanceTemplate
model
=
InstanceTemplate
#
notification_msg = ugettext_noop(
notification_msg
=
ugettext_noop
(
#
'%(owner)s offered you to take the ownership of '
'
%(owner)
s offered you to take the ownership of '
#
'his/her template called %(instance)s. '
'his/her template called
%(instance)
s. '
#
'<a href="%(token)s" '
'<a href="
%(token)
s" '
#
'class="btn btn-success btn-small">Accept</a>')
'class="btn btn-success btn-small">Accept</a>'
)
#
token_url = 'dashboard.views.template-transfer-ownership-confirm'
token_url
=
'dashboard.views.template-transfer-ownership-confirm'
#
template = "dashboard/template-tx-owner.html"
template
=
"dashboard/template-tx-owner.html"
circle/dashboard/views/util.py
View file @
e155a219
This diff is collapsed.
Click to expand it.
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