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
44d1a2a7
authored
Jul 25, 2014
by
Bach Dániel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vm: add PasswordResetOperation
fixes #193 fixes #203 fixes #204
parent
8b3c49e3
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
36 deletions
+33
-36
circle/dashboard/static/dashboard/vm-common.js
+1
-1
circle/dashboard/templates/dashboard/vm-detail.html
+5
-10
circle/dashboard/views.py
+3
-14
circle/vm/models/instance.py
+4
-11
circle/vm/operations.py
+20
-0
No files found.
circle/dashboard/static/dashboard/vm-common.js
View file @
44d1a2a7
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
$
(
function
()
{
$
(
function
()
{
/* vm operations */
/* vm operations */
$
(
'#ops, #vm-details-resources-disk, #vm-details-renew-op'
).
on
(
'click'
,
'.operation.btn'
,
function
(
e
)
{
$
(
'#ops, #vm-details-resources-disk, #vm-details-renew-op
, #vm-details-pw-reset
'
).
on
(
'click'
,
'.operation.btn'
,
function
(
e
)
{
var
icon
=
$
(
this
).
children
(
"i"
).
addClass
(
'fa-spinner fa-spin'
);
var
icon
=
$
(
this
).
children
(
"i"
).
addClass
(
'fa-spinner fa-spin'
);
$
.
ajax
({
$
.
ajax
({
...
...
circle/dashboard/templates/dashboard/vm-detail.html
View file @
44d1a2a7
...
@@ -98,17 +98,12 @@
...
@@ -98,17 +98,12 @@
</div>
</div>
</dd>
</dd>
<dd
style=
"font-size: 10px; text-align: right; padding-top: 8px;"
>
<dd
style=
"font-size: 10px; text-align: right; padding-top: 8px;"
>
<a
id=
"vm-details-pw-change"
href=
"#"
>
{% trans "Generate new password!" %}
</a>
<div
id=
"vm-details-pw-reset"
>
{% with op=op.password_reset %}{% if op %}
<a
href=
"{{op.get_url}}"
class=
"operation btn btn-default btn-xs"
{%
if
op
.
disabled
%}
disabled
{%
endif
%}
>
{% trans "Generate new password!" %}
</a>
{% endif %}{% endwith %}
</div>
</dd>
</dd>
<div
id=
"vm-details-pw-confirm"
>
{% comment %} TODO Couldn't this use a modal? {% endcomment%}
<dt>
{% trans "Are you sure?" %}
</dt>
<dd>
<a
href=
"#"
class=
"vm-details-pw-confirm-choice label label-success"
data-choice=
"1"
data-vm=
"{{ instance.pk }}"
>
{% trans "Yes" %}
</a>
/
<a
href=
"#"
class=
"vm-details-pw-confirm-choice label label-danger"
data-choice=
"0"
>
{% trans "No" %}
</a>
</dd>
</div>
</dl>
</dl>
<div
class=
"input-group"
id=
"dashboard-vm-details-connect-command"
>
<div
class=
"input-group"
id=
"dashboard-vm-details-connect-command"
>
...
...
circle/dashboard/views.py
View file @
44d1a2a7
...
@@ -303,7 +303,6 @@ class VmDetailView(CheckedDetailView):
...
@@ -303,7 +303,6 @@ class VmDetailView(CheckedDetailView):
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
options
=
{
options
=
{
'change_password'
:
self
.
__change_password
,
'new_name'
:
self
.
__set_name
,
'new_name'
:
self
.
__set_name
,
'new_description'
:
self
.
__set_description
,
'new_description'
:
self
.
__set_description
,
'new_tag'
:
self
.
__add_tag
,
'new_tag'
:
self
.
__add_tag
,
...
@@ -319,19 +318,6 @@ class VmDetailView(CheckedDetailView):
...
@@ -319,19 +318,6 @@ class VmDetailView(CheckedDetailView):
raise
Http404
()
raise
Http404
()
def
__change_password
(
self
,
request
):
self
.
object
=
self
.
get_object
()
if
not
self
.
object
.
has_level
(
request
.
user
,
'owner'
):
raise
PermissionDenied
()
self
.
object
.
change_password
(
user
=
request
.
user
)
messages
.
success
(
request
,
_
(
"Password changed."
))
if
request
.
is_ajax
():
return
HttpResponse
(
"Success."
)
else
:
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'
):
...
@@ -856,6 +842,9 @@ vm_ops = OrderedDict([
...
@@ -856,6 +842,9 @@ vm_ops = OrderedDict([
(
'download_disk'
,
VmDownloadDiskView
),
(
'download_disk'
,
VmDownloadDiskView
),
(
'renew'
,
VmRenewView
),
(
'renew'
,
VmRenewView
),
(
'resources_change'
,
VmResourcesChangeView
),
(
'resources_change'
,
VmResourcesChangeView
),
(
'password_reset'
,
VmOperationView
.
factory
(
op
=
'password_reset'
,
icon
=
'unlock'
,
effect
=
'warning'
,
show_in_toolbar
=
False
)),
])
])
...
...
circle/vm/models/instance.py
View file @
44d1a2a7
...
@@ -719,22 +719,15 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
...
@@ -719,22 +719,15 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
timezone
.
now
()
+
lease
.
suspend_interval
,
timezone
.
now
()
+
lease
.
suspend_interval
,
timezone
.
now
()
+
lease
.
delete_interval
)
timezone
.
now
()
+
lease
.
delete_interval
)
def
change_password
(
self
,
user
=
None
):
def
change_password
(
self
):
"""Generate new password for the vm
"""Generate new password for the vm
:param self: The virtual machine.
:param self: The virtual machine.
:param user: The user who's issuing the command.
"""
"""
self
.
pw
=
pwgen
()
self
.
pw
=
pwgen
()
with
instance_activity
(
code_suffix
=
'change_password'
,
instance
=
self
,
queue
=
self
.
get_remote_queue_name
(
"agent"
)
readable_name
=
ugettext_noop
(
"change password"
),
agent_tasks
.
change_password
.
apply_async
(
user
=
user
):
queue
=
queue
,
args
=
(
self
.
vm_name
,
self
.
pw
))
queue
=
self
.
get_remote_queue_name
(
"agent"
)
agent_tasks
.
change_password
.
apply_async
(
queue
=
queue
,
args
=
(
self
.
vm_name
,
self
.
pw
))
self
.
save
()
self
.
save
()
def
select_node
(
self
):
def
select_node
(
self
):
...
...
circle/vm/operations.py
View file @
44d1a2a7
...
@@ -867,3 +867,23 @@ class ResourcesOperation(InstanceOperation):
...
@@ -867,3 +867,23 @@ class ResourcesOperation(InstanceOperation):
register_operation
(
ResourcesOperation
)
register_operation
(
ResourcesOperation
)
class
PasswordResetOperation
(
InstanceOperation
):
activity_code_suffix
=
'Password reset'
id
=
'password_reset'
name
=
_
(
"password reset"
)
description
=
_
(
"Password reset"
)
acl_level
=
"owner"
required_perms
=
()
def
check_precond
(
self
):
super
(
PasswordResetOperation
,
self
)
.
check_precond
()
if
self
.
instance
.
status
not
in
[
"RUNNING"
]:
raise
self
.
instance
.
WrongStateError
(
self
.
instance
)
def
_operation
(
self
):
self
.
instance
.
change_password
()
register_operation
(
PasswordResetOperation
)
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