Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Fukász Rómeó Ervin
/
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
9423ec6c
authored
Dec 10, 2013
by
Bach Dániel
Committed by
Guba Sándor
Dec 10, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: fix flake8 errors
parent
61b7b8b0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
68 deletions
+18
-68
circle/dashboard/tables.py
+7
-14
circle/dashboard/views.py
+7
-51
circle/vm/models/node.py
+4
-3
No files found.
circle/dashboard/tables.py
View file @
9423ec6c
from
django_tables2
import
Table
,
A
from
django_tables2.columns
import
LinkColumn
,
TemplateColumn
,
Column
,
BooleanColumn
from
django_tables2
import
Table
from
django_tables2.columns
import
TemplateColumn
,
Column
,
BooleanColumn
from
vm.models
import
Instance
,
Node
from
django.utils.translation
import
ugettext_lazy
as
_
...
...
@@ -88,24 +88,17 @@ class NodeListTable(Table):
)
actions
=
TemplateColumn
(
attrs
=
{
'th'
:
{
'class'
:
'node-list-table-thin'
}},
template_code
=
'{
%
include "dashboard/node-list/column-actions.html" with btn_size="btn-xs"
%
}'
,
# actions = TemplateColumn('{% load my_filters %}{{ record.name|int_to_time }}'
# attrs={'th': {'class': 'node-list-table-thin'},'extra_tag':},
template_code
=
(
'{
%
include "dashboard/node-list/column-'
'actions.html" with btn_size="btn-xs"
%
}'
),
)
# time_of_suspend = TemplateColumn(
# '{{ record.time_of_suspend|timeuntil }}',
# verbose_name=_("Suspend in"))
# time_of_delete = TemplateColumn(
# '{{ record.time_of_delete|timeuntil }}',
# verbose_name=_("Delete in"))
class
Meta
:
model
=
Node
attrs
=
{
'class'
:
(
'table table-bordered table-striped table-hover '
'node-list-table'
)}
fields
=
(
'pk'
,
'name'
,
'host'
,
'enabled'
,
'priority'
,
'overcommit'
,
'number_of_VMs'
,
)
fields
=
(
'pk'
,
'name'
,
'host'
,
'enabled'
,
'priority'
,
'overcommit'
,
'number_of_VMs'
,
)
class
NodeVmListTable
(
Table
):
pk
=
TemplateColumn
(
...
...
circle/dashboard/views.py
View file @
9423ec6c
...
...
@@ -224,9 +224,8 @@ class VmDetailView(CheckedDetailView):
def
__add_port
(
self
,
request
):
object
=
self
.
get_object
()
if
not
object
.
has_level
(
request
.
user
,
'owner'
):
raise
PermissionDenied
()
if
not
request
.
user
.
has_perm
(
'vm.config_ports'
):
if
(
not
object
.
has_level
(
request
.
user
,
'owner'
)
or
not
request
.
user
.
has_perm
(
'vm.config_ports'
)):
raise
PermissionDenied
()
port
=
request
.
POST
.
get
(
"port"
)
...
...
@@ -254,10 +253,10 @@ class NodeDetailView(DetailView):
template_name
=
"dashboard/node-detail.html"
model
=
Node
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
(
NodeDetailView
,
self
)
.
get_context_data
(
**
kwargs
)
context
[
'table'
]
=
NodeVmListTable
(
Instance
.
active
.
filter
(
node
=
self
.
object
))
instances
=
Instance
.
active
.
filter
(
node
=
self
.
object
)
context
[
'table'
]
=
NodeVmListTable
(
instances
)
return
context
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
...
...
@@ -287,7 +286,6 @@ class NodeDetailView(DetailView):
kwargs
=
{
'pk'
:
self
.
object
.
pk
}))
class
AclUpdateView
(
View
,
SingleObjectMixin
):
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
...
...
@@ -369,6 +367,7 @@ class VmList(SingleTableView):
table_class
=
VmListTable
table_pagination
=
False
class
NodeList
(
SingleTableView
):
template_name
=
"dashboard/node-list.html"
model
=
Node
...
...
@@ -449,6 +448,7 @@ class VmCreate(TemplateView):
else
:
return
redirect
(
path
)
class
NodeCreate
(
TemplateView
):
def
get_template_names
(
self
):
...
...
@@ -525,7 +525,6 @@ class NodeCreate(TemplateView):
return
redirect
(
reverse_lazy
(
'dashboard.views.detail'
,
resp
))
class
VmDelete
(
DeleteView
):
model
=
Instance
template_name
=
"dashboard/confirm/base-delete.html"
...
...
@@ -536,34 +535,6 @@ class VmDelete(DeleteView):
else
:
return
[
'dashboard/confirm/base-delete.html'
]
def
get_context_data
(
self
,
**
kwargs
):
# this is redundant now, but if we wanna add more to print
# we'll need this
print
kwargs
context
=
super
(
VmDelete
,
self
)
.
get_context_data
(
**
kwargs
)
return
context
# github.com/django/django/blob/master/django/views/generic/edit.py#L245
def
delete
(
self
,
request
,
*
args
,
**
kwargs
):
object
=
self
.
get_object
()
if
not
object
.
has_level
(
request
.
user
,
'owner'
):
raise
PermissionDenied
()
object
.
destroy_async
(
user
=
request
.
user
)
success_url
=
self
.
get_success_url
()
success_message
=
_
(
"VM successfully deleted!"
)
if
request
.
is_ajax
():
if
request
.
POST
.
get
(
'redirect'
)
.
lower
()
==
"true"
:
messages
.
success
(
request
,
success_message
)
return
HttpResponse
(
json
.
dumps
({
'message'
:
success_message
}),
content_type
=
"application/json"
,
)
else
:
messages
.
success
(
request
,
success_message
)
return
HttpResponseRedirect
(
success_url
)
def
get_success_url
(
self
):
next
=
self
.
request
.
POST
.
get
(
'next'
)
if
next
:
...
...
@@ -571,15 +542,6 @@ class VmDelete(DeleteView):
else
:
return
reverse_lazy
(
'dashboard.index'
)
model
=
Instance
template_name
=
"dashboard/confirm/base-delete.html"
def
get_template_names
(
self
):
if
self
.
request
.
is_ajax
():
return
[
'dashboard/confirm/ajax-delete.html'
]
else
:
return
[
'dashboard/confirm/base-delete.html'
]
def
get_context_data
(
self
,
**
kwargs
):
# this is redundant now, but if we wanna add more to print
# we'll need this
...
...
@@ -607,13 +569,6 @@ class VmDelete(DeleteView):
messages
.
success
(
request
,
success_message
)
return
HttpResponseRedirect
(
success_url
)
def
get_success_url
(
self
):
next
=
self
.
request
.
POST
.
get
(
'next'
)
if
next
:
return
next
else
:
return
reverse_lazy
(
'dashboard.index'
)
class
NodeDelete
(
DeleteView
):
...
...
@@ -660,6 +615,7 @@ class NodeDelete(DeleteView):
else
:
return
reverse_lazy
(
'dashboard.index'
)
class
PortDelete
(
DeleteView
):
model
=
Rule
pk_url_kwarg
=
'rule'
...
...
circle/vm/models/node.py
View file @
9423ec6c
...
...
@@ -41,7 +41,6 @@ class Node(TimeStampedModel):
help_text
=
_
(
"The ratio of total memory with "
"to without overcommit."
))
class
Meta
:
app_label
=
'vm'
db_table
=
'vm_node'
...
...
@@ -63,12 +62,13 @@ class Node(TimeStampedModel):
"""
return
self
.
remote_query
(
vm_tasks
.
get_core_num
)
@property
def
state
(
self
):
"""Node state.
"""
if
self
.
enabled
and
self
.
online
:
if
self
.
enabled
and
self
.
online
:
return
'online'
elif
self
.
enabled
and
not
self
.
online
:
return
'missing'
...
...
@@ -141,4 +141,5 @@ class Node(TimeStampedModel):
@classmethod
def
get_state_count
(
cls
,
online
,
enabled
):
return
len
([
1
for
i
in
cls
.
objects
.
filter
(
enabled
=
enabled
)
.
all
()
if
i
.
online
==
online
])
return
len
([
1
for
i
in
cls
.
objects
.
filter
(
enabled
=
enabled
)
.
all
()
if
i
.
online
==
online
])
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