Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gutyán Gábor
/
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
1c990ba8
authored
Sep 23, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: add new node operation views
parent
cbf6979a
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
42 deletions
+60
-42
circle/dashboard/templates/dashboard/node-detail.html
+3
-0
circle/dashboard/urls.py
+21
-5
circle/dashboard/views/node.py
+36
-37
No files found.
circle/dashboard/templates/dashboard/node-detail.html
View file @
1c990ba8
...
...
@@ -6,6 +6,9 @@
{% block content %}
<div
class=
"body-content"
>
<div
class=
"page-header"
>
<div
class=
"pull-right"
id=
"ops"
>
{% include "dashboard/vm-detail/_operations.html" %}
</div>
<div
class=
"pull-right"
style=
"padding-top: 15px;"
>
<a
title=
"{% trans "
Rename
"
%}"
href=
"#"
class=
"btn btn-default btn-xs node-details-rename-button"
><i
class=
"fa fa-pencil"
></i></a>
<a
title=
"{% trans "
Delete
"
%}"
data-node-pk=
"{{ node.pk }}"
class=
"btn btn-default btn-xs real-link node-delete"
href=
"{% url "
dashboard
.
views
.
delete-node
"
pk=
node.pk
%}"
><i
class=
"fa fa-trash-o"
></i></a>
...
...
circle/dashboard/urls.py
View file @
1c990ba8
...
...
@@ -25,7 +25,7 @@ from .views import (
GroupDetailView
,
GroupList
,
IndexView
,
InstanceActivityDetail
,
LeaseCreate
,
LeaseDelete
,
LeaseDetail
,
MyPreferencesView
,
NodeAddTraitView
,
NodeCreate
,
NodeDelete
,
NodeDetailView
,
Node
FlushView
,
Node
GraphView
,
NodeList
,
NodeStatus
,
NodeDetailView
,
NodeGraphView
,
NodeList
,
NodeStatus
,
NotificationView
,
PortDelete
,
TemplateAclUpdateView
,
TemplateCreate
,
TemplateDelete
,
TemplateDetail
,
TemplateList
,
TransferOwnershipConfirmView
,
TransferOwnershipView
,
vm_activity
,
VmCreate
,
VmDetailView
,
...
...
@@ -47,6 +47,8 @@ from .views import (
LeaseAclUpdateView
,
ClientCheck
,
TokenLogin
,
)
from
.views.vm
import
vm_ops
,
vm_mass_ops
from
.views.node
import
node_ops
autocomplete_light
.
autodiscover
()
...
...
@@ -74,8 +76,6 @@ urlpatterns = patterns(
name
=
"dashboard.views.template-list"
),
url
(
r"^template/delete/(?P<pk>\d+)/$"
,
TemplateDelete
.
as_view
(),
name
=
"dashboard.views.template-delete"
),
url
(
r'^vm/'
,
include
(
'dashboard.vm.urls'
)),
url
(
r'^vm/(?P<pk>\d+)/remove_port/(?P<rule>\d+)/$'
,
PortDelete
.
as_view
(),
name
=
'dashboard.views.remove-port'
),
url
(
r'^vm/(?P<pk>\d+)/$'
,
VmDetailView
.
as_view
(),
...
...
@@ -110,8 +110,6 @@ urlpatterns = patterns(
name
=
"dashboard.views.delete-node"
),
url
(
r'^node/status/(?P<pk>\d+)/$'
,
NodeStatus
.
as_view
(),
name
=
"dashboard.views.status-node"
),
url
(
r'^node/flush/(?P<pk>\d+)/$'
,
NodeFlushView
.
as_view
(),
name
=
"dashboard.views.flush-node"
),
url
(
r'^node/create/$'
,
NodeCreate
.
as_view
(),
name
=
'dashboard.views.node-create'
),
...
...
@@ -210,3 +208,21 @@ urlpatterns = patterns(
url
(
r'^token-login/(?P<token>.*)/$'
,
TokenLogin
.
as_view
(),
name
=
"dashboard.views.token-login"
),
)
urlpatterns
+=
patterns
(
''
,
*
(
url
(
r'^vm/(?P<pk>\d+)/op/
%
s/$'
%
op
,
v
.
as_view
(),
name
=
v
.
get_urlname
())
for
op
,
v
in
vm_ops
.
iteritems
())
)
urlpatterns
+=
patterns
(
''
,
*
(
url
(
r'^vm/mass_op/
%
s/$'
%
op
,
v
.
as_view
(),
name
=
v
.
get_urlname
())
for
op
,
v
in
vm_mass_ops
.
iteritems
())
)
urlpatterns
+=
patterns
(
''
,
*
(
url
(
r'^node/(?P<pk>\d+)/op/
%
s/$'
%
op
,
v
.
as_view
(),
name
=
v
.
get_urlname
())
for
op
,
v
in
node_ops
.
iteritems
())
)
circle/dashboard/views/node.py
View file @
1c990ba8
...
...
@@ -17,6 +17,7 @@
from
__future__
import
unicode_literals
,
absolute_import
import
json
from
collections
import
OrderedDict
from
django.conf
import
settings
from
django.contrib
import
messages
...
...
@@ -37,7 +38,39 @@ from vm.models import Node, NodeActivity, Trait
from
..forms
import
TraitForm
,
HostForm
,
NodeForm
from
..tables
import
NodeListTable
from
.util
import
GraphViewBase
from
.util
import
GraphViewBase
,
AjaxOperationMixin
,
OperationView
def
get_operations
(
instance
,
user
):
ops
=
[]
for
k
,
v
in
node_ops
.
iteritems
():
try
:
op
=
v
.
get_op_by_object
(
instance
)
op
.
check_auth
(
user
)
op
.
check_precond
()
except
Exception
:
ops
.
append
(
v
.
bind_to_object
(
instance
,
disabled
=
True
))
else
:
ops
.
append
(
v
.
bind_to_object
(
instance
))
return
ops
class
NodeOperationView
(
AjaxOperationMixin
,
OperationView
):
model
=
Node
context_object_name
=
'node'
# much simpler to mock object
node_ops
=
OrderedDict
([
(
'activate'
,
NodeOperationView
.
factory
(
op
=
'activate'
,
icon
=
'play-circle'
,
effect
=
'success'
)),
(
'passivate'
,
NodeOperationView
.
factory
(
op
=
'passivate'
,
icon
=
'play-circle-o'
,
effect
=
'info'
)),
(
'disable'
,
NodeOperationView
.
factory
(
op
=
'disable'
,
icon
=
'times-circle-o'
,
effect
=
'danger'
)),
(
'flush'
,
NodeOperationView
.
factory
(
op
=
'flush'
,
icon
=
'paint-brush'
,
effect
=
'danger'
)),
])
class
NodeDetailView
(
LoginRequiredMixin
,
SuperuserRequiredMixin
,
DetailView
):
...
...
@@ -53,6 +86,8 @@ class NodeDetailView(LoginRequiredMixin, SuperuserRequiredMixin, DetailView):
na
=
NodeActivity
.
objects
.
filter
(
node
=
self
.
object
,
parent
=
None
)
.
order_by
(
'-started'
)
.
select_related
()
context
[
'ops'
]
=
get_operations
(
self
.
object
,
self
.
request
.
user
)
context
[
'op'
]
=
{
i
.
op
:
i
for
i
in
context
[
'ops'
]}
context
[
'activities'
]
=
na
context
[
'trait_form'
]
=
form
context
[
'graphite_enabled'
]
=
(
...
...
@@ -316,42 +351,6 @@ class NodeStatus(LoginRequiredMixin, SuperuserRequiredMixin, DetailView):
return
redirect
(
self
.
get_success_url
())
class
NodeFlushView
(
LoginRequiredMixin
,
SuperuserRequiredMixin
,
DetailView
):
template_name
=
"dashboard/confirm/node-flush.html"
model
=
Node
def
get_template_names
(
self
):
if
self
.
request
.
is_ajax
():
return
[
'dashboard/confirm/ajax-node-flush.html'
]
else
:
return
[
'dashboard/confirm/node-flush.html'
]
def
get_success_url
(
self
):
next
=
self
.
request
.
GET
.
get
(
'next'
)
if
next
:
return
next
else
:
return
reverse_lazy
(
"dashboard.views.node-detail"
,
kwargs
=
{
'pk'
:
self
.
object
.
pk
})
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
(
NodeFlushView
,
self
)
.
get_context_data
(
**
kwargs
)
return
context
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
if
request
.
POST
.
get
(
'flush'
)
is
not
None
:
return
self
.
__flush
(
request
)
return
redirect
(
reverse_lazy
(
"dashboard.views.node-detail"
,
kwargs
=
{
'pk'
:
self
.
get_object
()
.
pk
}))
def
__flush
(
self
,
request
):
self
.
object
=
self
.
get_object
()
self
.
object
.
flush
.
async
(
user
=
request
.
user
)
success_message
=
_
(
"Node successfully flushed."
)
messages
.
success
(
request
,
success_message
)
return
redirect
(
self
.
get_success_url
())
class
NodeGraphView
(
SuperuserRequiredMixin
,
GraphViewBase
):
metrics
=
{
'cpu'
:
(
'cactiStyle(alias(nonNegativeDerivative(
%(prefix)
s.cpu.times),'
...
...
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