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
1077621c
authored
Jun 30, 2014
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: make resources change an operation
parent
3316ed40
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
69 additions
and
36 deletions
+69
-36
circle/dashboard/static/dashboard/vm-details.js
+9
-2
circle/dashboard/templates/dashboard/vm-detail/resources.html
+5
-1
circle/dashboard/views.py
+27
-33
circle/vm/operations.py
+28
-0
No files found.
circle/dashboard/static/dashboard/vm-details.js
View file @
1077621c
...
@@ -11,13 +11,14 @@ $(function() {
...
@@ -11,13 +11,14 @@ $(function() {
/* save resources */
/* save resources */
$
(
'#vm-details-resources-save'
).
click
(
function
()
{
$
(
'#vm-details-resources-save'
).
click
(
function
()
{
$
(
'i.icon-save'
,
this
).
removeClass
(
"icon-save"
).
addClass
(
"icon-refresh icon-spin"
);
$
(
'i.icon-save'
,
this
).
removeClass
(
"icon-save"
).
addClass
(
"icon-refresh icon-spin"
);
var
vm
=
$
(
this
).
data
(
"vm"
);
$
.
ajax
({
$
.
ajax
({
type
:
'POST'
,
type
:
'POST'
,
url
:
location
.
href
,
url
:
"/dashboard/vm/"
+
vm
+
"/op/resources_change/"
,
data
:
$
(
'#vm-details-resources-form'
).
serialize
(),
data
:
$
(
'#vm-details-resources-form'
).
serialize
(),
success
:
function
(
data
,
textStatus
,
xhr
)
{
success
:
function
(
data
,
textStatus
,
xhr
)
{
addMessage
(
data
[
'message'
],
'success'
);
$
(
"#vm-details-resources-save i"
).
removeClass
(
'icon-refresh icon-spin'
).
addClass
(
"icon-save"
);
$
(
"#vm-details-resources-save i"
).
removeClass
(
'icon-refresh icon-spin'
).
addClass
(
"icon-save"
);
$
(
'a[href="#activity"]'
).
trigger
(
"click"
);
},
},
error
:
function
(
xhr
,
textStatus
,
error
)
{
error
:
function
(
xhr
,
textStatus
,
error
)
{
$
(
"#vm-details-resources-save i"
).
removeClass
(
'icon-refresh icon-spin'
).
addClass
(
"icon-save"
);
$
(
"#vm-details-resources-save i"
).
removeClass
(
'icon-refresh icon-spin'
).
addClass
(
"icon-save"
);
...
@@ -367,6 +368,12 @@ function checkNewActivity(only_status, runs) {
...
@@ -367,6 +368,12 @@ function checkNewActivity(only_status, runs) {
$
(
"[data-target=#_console]"
).
attr
(
"data-toggle"
,
"_pill"
).
attr
(
"href"
,
"#"
).
parent
(
"li"
).
addClass
(
"disabled"
);
$
(
"[data-target=#_console]"
).
attr
(
"data-toggle"
,
"_pill"
).
attr
(
"href"
,
"#"
).
parent
(
"li"
).
addClass
(
"disabled"
);
}
}
if
(
data
[
'status'
]
==
"STOPPED"
)
{
$
(
".enabled-when-stopped"
).
prop
(
"disabled"
,
false
);
}
else
{
$
(
".enabled-when-stopped"
).
prop
(
"disabled"
,
true
);
}
if
(
runs
>
0
&&
decideActivityRefresh
())
{
if
(
runs
>
0
&&
decideActivityRefresh
())
{
setTimeout
(
setTimeout
(
function
()
{
checkNewActivity
(
only_status
,
runs
+
1
)},
function
()
{
checkNewActivity
(
only_status
,
runs
+
1
)},
...
...
circle/dashboard/templates/dashboard/vm-detail/resources.html
View file @
1077621c
...
@@ -35,7 +35,11 @@
...
@@ -35,7 +35,11 @@
<p
class=
"row"
>
<p
class=
"row"
>
<div
class=
"col-sm-12"
>
<div
class=
"col-sm-12"
>
<button
type=
"submit"
class=
"btn btn-success btn-sm"
id=
"vm-details-resources-save"
><i
class=
"icon-save"
></i>
{% trans "Save resources" %}
</button>
<button
type=
"submit"
class=
"btn btn-success btn-sm enabled-when-stopped"
id=
"vm-details-resources-save"
data-vm=
"{{ instance.pk }}"
{%
if
not
op
.
resources_change
%}
disabled
{%
endif
%}
>
<i
class=
"icon-save"
></i>
{% trans "Save resources" %}
</button>
</div>
</div>
</p>
</p>
</form>
</form>
...
...
circle/dashboard/views.py
View file @
1077621c
...
@@ -290,10 +290,6 @@ class VmDetailView(CheckedDetailView):
...
@@ -290,10 +290,6 @@ class VmDetailView(CheckedDetailView):
return
context
return
context
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
if
(
request
.
POST
.
get
(
'ram-size'
)
and
request
.
POST
.
get
(
'cpu-count'
)
and
request
.
POST
.
get
(
'cpu-priority'
)):
return
self
.
__set_resources
(
request
)
options
=
{
options
=
{
'change_password'
:
self
.
__change_password
,
'change_password'
:
self
.
__change_password
,
'new_name'
:
self
.
__set_name
,
'new_name'
:
self
.
__set_name
,
...
@@ -321,33 +317,6 @@ class VmDetailView(CheckedDetailView):
...
@@ -321,33 +317,6 @@ class VmDetailView(CheckedDetailView):
return
redirect
(
reverse_lazy
(
"dashboard.views.detail"
,
return
redirect
(
reverse_lazy
(
"dashboard.views.detail"
,
kwargs
=
{
'pk'
:
self
.
object
.
pk
}))
kwargs
=
{
'pk'
:
self
.
object
.
pk
}))
def
__set_resources
(
self
,
request
):
self
.
object
=
self
.
get_object
()
if
not
self
.
object
.
has_level
(
request
.
user
,
'owner'
):
raise
PermissionDenied
()
if
not
request
.
user
.
has_perm
(
'vm.change_resources'
):
raise
PermissionDenied
()
resources
=
{
'num_cores'
:
request
.
POST
.
get
(
'cpu-count'
),
'ram_size'
:
request
.
POST
.
get
(
'ram-size'
),
'max_ram_size'
:
request
.
POST
.
get
(
'ram-size'
),
# TODO: max_ram
'priority'
:
request
.
POST
.
get
(
'cpu-priority'
)
}
Instance
.
objects
.
filter
(
pk
=
self
.
object
.
pk
)
.
update
(
**
resources
)
success_message
=
_
(
"Resources successfully updated."
)
if
request
.
is_ajax
():
response
=
{
'message'
:
success_message
}
return
HttpResponse
(
json
.
dumps
(
response
),
content_type
=
"application/json"
)
else
:
messages
.
success
(
request
,
success_message
)
return
redirect
(
reverse_lazy
(
"dashboard.views.detail"
,
kwargs
=
{
'pk'
:
self
.
object
.
pk
}))
def
__set_name
(
self
,
request
):
def
__set_name
(
self
,
request
):
self
.
object
=
self
.
get_object
()
self
.
object
=
self
.
get_object
()
if
not
self
.
object
.
has_level
(
request
.
user
,
'owner'
):
if
not
self
.
object
.
has_level
(
request
.
user
,
'owner'
):
...
@@ -577,8 +546,9 @@ class VmOperationView(OperationView):
...
@@ -577,8 +546,9 @@ class VmOperationView(OperationView):
model
=
Instance
model
=
Instance
context_object_name
=
'instance'
# much simpler to mock object
context_object_name
=
'instance'
# much simpler to mock object
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
def
post
(
self
,
request
,
extra
=
None
,
*
args
,
**
kwargs
):
resp
=
super
(
VmOperationView
,
self
)
.
post
(
request
,
*
args
,
**
kwargs
)
resp
=
super
(
VmOperationView
,
self
)
.
post
(
request
,
extra
,
*
args
,
**
kwargs
)
if
request
.
is_ajax
():
if
request
.
is_ajax
():
store
=
messages
.
get_messages
(
request
)
store
=
messages
.
get_messages
(
request
)
store
.
used
=
True
store
.
used
=
True
...
@@ -668,6 +638,29 @@ class VmSaveView(FormOperationMixin, VmOperationView):
...
@@ -668,6 +638,29 @@ class VmSaveView(FormOperationMixin, VmOperationView):
icon
=
'save'
icon
=
'save'
form_class
=
VmSaveForm
form_class
=
VmSaveForm
class
VmResourcesChangeView
(
VmOperationView
):
op
=
'resources_change'
icon
=
"save"
show_in_toolbar
=
False
def
post
(
self
,
request
,
extra
=
None
,
*
args
,
**
kwargs
):
if
extra
is
None
:
extra
=
{}
resources
=
{
'num_cores'
:
"cpu-count"
,
'priority'
:
"cpu-priority"
,
'ram_size'
:
"ram-size"
,
"max_ram_size"
:
"ram-size"
,
# TODO
}
for
k
,
v
in
resources
.
iteritems
():
extra
[
k
]
=
request
.
POST
.
get
(
v
)
return
super
(
VmResourcesChangeView
,
self
)
.
post
(
request
,
extra
,
*
args
,
**
kwargs
)
vm_ops
=
{
vm_ops
=
{
'reset'
:
VmOperationView
.
factory
(
op
=
'reset'
,
icon
=
'bolt'
),
'reset'
:
VmOperationView
.
factory
(
op
=
'reset'
,
icon
=
'bolt'
),
'deploy'
:
VmOperationView
.
factory
(
op
=
'deploy'
,
icon
=
'play'
),
'deploy'
:
VmOperationView
.
factory
(
op
=
'deploy'
,
icon
=
'play'
),
...
@@ -681,6 +674,7 @@ vm_ops = {
...
@@ -681,6 +674,7 @@ vm_ops = {
'wake_up'
:
VmOperationView
.
factory
(
op
=
'wake_up'
,
icon
=
'sun'
),
'wake_up'
:
VmOperationView
.
factory
(
op
=
'wake_up'
,
icon
=
'sun'
),
'create_disk'
:
VmCreateDiskView
,
'create_disk'
:
VmCreateDiskView
,
'download_disk'
:
VmDownloadDiskView
,
'download_disk'
:
VmDownloadDiskView
,
'resources_change'
:
VmResourcesChangeView
,
}
}
...
...
circle/vm/operations.py
View file @
1077621c
...
@@ -600,3 +600,31 @@ class ScreenshotOperation(InstanceOperation):
...
@@ -600,3 +600,31 @@ class ScreenshotOperation(InstanceOperation):
register_operation
(
ScreenshotOperation
)
register_operation
(
ScreenshotOperation
)
class
ResourcesOperation
(
InstanceOperation
):
activity_code_suffix
=
'Resources change'
id
=
'resources_change'
name
=
_
(
"resources change"
)
description
=
_
(
"Change resources"
)
acl_level
=
"owner"
concurrency_check
=
False
def
check_precond
(
self
):
super
(
ResourcesOperation
,
self
)
.
check_precond
()
if
self
.
instance
.
status
in
[
'RUNNING'
]:
raise
self
.
instance
.
WrongStateError
(
self
.
instance
)
def
_operation
(
self
,
user
,
num_cores
,
ram_size
,
max_ram_size
,
priority
):
if
not
user
.
has_perm
(
'vm.change_resources'
):
raise
PermissionDenied
()
self
.
instance
.
num_cores
=
num_cores
self
.
instance
.
ram_size
=
ram_size
self
.
instance
.
max_ram_size
=
max_ram_size
self
.
instance
.
priority
=
priority
self
.
instance
.
save
()
register_operation
(
ResourcesOperation
)
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