Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Projets publics
Ravada-Mirror
Commits
778dca26
Commit
778dca26
authored
Jul 17, 2018
by
JanFontanet
Browse files
[#218]Options view, FrontEnd methods and requests added
parent
1a904515
Changes
9
Hide whitespace changes
Inline
Side-by-side
lib/Ravada.pm
View file @
778dca26
...
...
@@ -2437,6 +2437,38 @@ sub _cmd_change_curr_memory($self, $request) {
$domain
->
set_memory
(
$memory
);
}
sub
_cmd_take_snapshot
($self, $request) {
my
$id_domain
=
$request
->
args
('
id_domain
');
my
$sname
=
$request
->
args
('
name
');
my
$dom
=
$self
->
search_domain_by_id
(
$id_domain
);
$dom
->
create_snapshot
(
$sname
);
}
sub
_cmd_revert_to_snapshot
($self, $request) {
my
$id_domain
=
$request
->
args
('
id_domain
');
my
$sname
=
$request
->
args
('
name
');
my
$dom
=
$self
->
search_domain_by_id
(
$id_domain
);
$dom
->
revert_to_snapshot
(
$sname
);
}
sub
_cmd_delete_snapshot
($self, $request) {
my
$id_domain
=
$request
->
args
('
id_domain
');
my
$sname
=
$request
->
args
('
name
');
my
$dom
=
$self
->
search_domain_by_id
(
$id_domain
);
$dom
->
delete_snapshot
(
$sname
);
}
sub
_cmd_list_snapshots
($self, $request) {
my
$id_domain
=
$request
->
args
('
id_domain
');
my
$dom
=
$self
->
search_domain_by_id
(
$id_domain
);
my
@snaps
=
$dom
->
list_snapshots
();
return
\
@snaps
;
}
sub
_clean_requests
($self, $command, $request=undef) {
my
$query
=
"
DELETE FROM requests
"
.
"
WHERE command=?
"
...
...
@@ -2578,6 +2610,10 @@ sub _req_method {
,
remove_hardware
=>
\
&_cmd_remove_hardware
,
change_max_memory
=>
\
&_cmd_change_max_memory
,
change_curr_memory
=>
\
&_cmd_change_curr_memory
,
take_snapshot
=>
\
&_cmd_take_snapshot
,
revert_to_snapshot
=>
\
&_cmd_revert_to_snapshot
,
delete_snapshot
=>
\
&_cmd_delete_snapshot
,
list_snapshot
=>
\
&_cmd_list_snapshots
);
return
$methods
{
$cmd
};
...
...
lib/Ravada/Domain.pm
View file @
778dca26
...
...
@@ -878,6 +878,7 @@ sub info($self, $user) {
$info
->
{
display_port
}
=
$local_port
;
}
$info
->
{
hardware
}
=
$self
->
get_controllers
();
#$info->{snapshots} = $self->list_snapshots();
return
$info
;
}
...
...
lib/Ravada/Domain/KVM.pm
View file @
778dca26
...
...
@@ -1636,7 +1636,7 @@ sub delete_snapshot($self, $name) {
sub
list_snapshots
($self) {
my
@snaps
=
$self
->
domain
->
list_all_snapshots
();
return
@snaps
;
return
\
@snaps
;
}
sub
revert_to_snapshot
($self, $name) {
...
...
lib/Ravada/Request.pm
View file @
778dca26
...
...
@@ -70,6 +70,8 @@ our %VALID_ARG = (
,
add_hardware
=>
{
uid
=>
1
,
id_domain
=>
1
,
name
=>
1
,
number
=>
1
}
,
remove_hardware
=>
{
uid
=>
1
,
id_domain
=>
1
,
name
=>
1
,
index
=>
1
}
,
change_max_memory
=>
{
uid
=>
1
,
id_domain
=>
1
,
ram
=>
1
}
,
snapshot
=>
{
uid
=>
1
,
id_domain
=>
1
,
name
=>
1
}
,
list_snapshot
=>
{
uid
=>
1
,
id_domain
=>
1
}
);
our
%CMD_SEND_MESSAGE
=
map
{
$_
=>
1
}
...
...
@@ -882,6 +884,68 @@ sub remove_hardware {
);
}
sub
take_snap
{
my
$proto
=
shift
;
my
$class
=
ref
(
$proto
)
||
$proto
;
my
$args
=
_check_args
('
snapshot
',
@
_
);
my
$self
=
{};
bless
(
$self
,
$class
);
return
$self
->
_new_request
(
command
=>
'
take_snapshot
'
,
id_domain
=>
$args
->
{
id_domain
}
,
args
=>
encode_json
(
$args
)
);
}
sub
revert_to_snap
{
my
$proto
=
shift
;
my
$class
=
ref
(
$proto
)
||
$proto
;
my
$args
=
_check_args
('
snapshot
',
@
_
);
my
$self
=
{};
bless
(
$self
,
$class
);
return
$self
->
_new_request
(
command
=>
'
revert_to_snapshot
'
,
id_domain
=>
$args
->
{
id_domain
}
,
args
=>
encode_json
(
$args
)
);
}
sub
delete_snap
{
my
$proto
=
shift
;
my
$class
=
ref
(
$proto
)
||
$proto
;
my
$args
=
_check_args
('
snapshot
',
@
_
);
my
$self
=
{};
bless
(
$self
,
$class
);
return
$self
->
_new_request
(
command
=>
'
delete_snapshot
'
,
id_domain
=>
$args
->
{
id_domain
}
,
args
=>
encode_json
(
$args
)
);
}
sub
list_snap
{
my
$proto
=
shift
;
my
$class
=
ref
(
$proto
)
||
$proto
;
my
$args
=
_check_args
('
list_snapshot
',
@
_
);
my
$self
=
{};
bless
(
$self
,
$class
);
return
$self
->
_new_request
(
command
=>
'
list_snapshot
'
,
id_domain
=>
$args
->
{
id_domain
}
,
args
=>
encode_json
(
$args
)
);
}
=head2 hybernate
Hybernates a domain.
...
...
public/js/ravada.js
View file @
778dca26
...
...
@@ -157,6 +157,10 @@
$scope
.
validate_new_name
(
$scope
.
showmachine
.
name
);
$scope
.
refresh_machine
();
});
/*$http.get('/machine/snapshot/list/'+$scope.showmachineId)
.then(function(response){
$scope.snapshots = response.data;
});*/
};
$scope
.
domain_remove
=
0
;
$scope
.
new_name_invalid
=
false
;
...
...
@@ -305,6 +309,25 @@
}
});
};
$scope
.
take_snapshot
=
function
(){
let
snap_name
=
document
.
getElementById
(
'
take-snap
'
).
value
;
$http
.
get
(
'
/machine/snapshot/take/
'
+
$scope
.
showmachine
.
id
+
'
/
'
+
snap_name
).
then
(
function
(
response
){
$scope
.
pending_before
++
;
if
(
!
$scope
.
requests
||
!
$scope
.
requests
.
length
)
$scope
.
refresh_machine
();
});
};
$scope
.
revert_to_snapshot
=
function
(
snap_name
){
$http
.
get
(
'
/machine/snapshot/revert/
'
+
$scope
.
showmachine
.
id
+
'
/
'
+
snap_name
).
then
(
function
(
response
){
$scope
.
pending_before
++
;
if
(
!
$scope
.
requests
||
!
$scope
.
requests
.
length
)
$scope
.
refresh_machine
();
});
};
$scope
.
delete_snapshot
=
function
(
snap_name
){
$http
.
get
(
'
/machine/snapshot/delete/
'
+
$scope
.
showmachine
.
id
+
'
/
'
+
snap_name
).
then
(
function
(
response
){
$scope
.
pending_before
++
;
if
(
!
$scope
.
requests
||
!
$scope
.
requests
.
length
)
$scope
.
refresh_machine
();
});
};
$scope
.
removed_hardware
=
[];
$scope
.
pending_before
=
10
;
...
...
rvd_front.pl
View file @
778dca26
...
...
@@ -733,6 +733,63 @@ get '/machine/hardware/add/(#id_domain)/(#hardware)/(#number)' => sub {
);
return
$c
->
render
(
json
=>
{
request
=>
$req
->
id
}
);
};
get
'
/machine/snapshot/take/(#id_domain)/(#snap_name)
'
=>
sub
{
my
$c
=
shift
;
my
$domain
=
Ravada::Front::
Domain
->
open
(
$c
->
stash
('
id_domain
'));
return
access_denied
(
$c
)
unless
$USER
->
id
==
$domain
->
id_owner
||
$USER
->
is_admin
;
my
$req
=
Ravada::
Request
->
take_snap
(
uid
=>
$USER
->
id
,
id_domain
=>
$c
->
stash
('
id_domain
')
,
name
=>
$c
->
stash
('
snap_name
')
);
return
$c
->
render
(
json
=>
{
request
=>
$req
->
id
});
};
get
'
/machine/snapshot/revert/(#id_domain)/(#snap_name)
'
=>
sub
{
my
$c
=
shift
;
my
$domain
=
Ravada::Front::
Domain
->
open
(
$c
->
stash
('
id_domain
'));
return
access_denied
(
$c
)
unless
$USER
->
id
==
$domain
->
id_owner
||
$USER
->
is_admin
;
my
$req
=
Ravada::
Request
->
revert_to_snap
(
uid
=>
$USER
->
id
,
id_domain
=>
$c
->
stash
('
id_domain
')
,
name
=>
$c
->
stash
('
name
')
);
return
$c
->
render
(
json
=>
{
request
=>
$req
->
id
});
};
get
'
/machine/snapshot/delete/(#id_domain)/(#snap_name)
'
=>
sub
{
my
$c
=
shift
;
my
$domain
=
Ravada::Front::
Domain
->
open
(
$c
->
stash
('
id_domain
'));
return
access_denied
(
$c
)
unless
$USER
->
id
==
$domain
->
id_owner
||
$USER
->
is_admin
;
my
$req
=
Ravada::
Request
->
delete_snap
(
uid
=>
$USER
->
id
,
id_domain
=>
$c
->
stash
('
id_domain
')
,
name
=>
$c
->
stash
('
name
')
);
return
$c
->
render
(
json
=>
{
request
=>
$req
->
id
});
};
get
'
/machine/snapshot/list/(#id_domain)
'
=>
sub
{
my
$c
=
shift
;
my
$domain
=
Ravada::Front::
Domain
->
open
(
$c
->
stash
('
id_domain
'));
return
access_denied
(
$c
)
unless
$USER
->
id
==
$domain
->
id_owner
||
$USER
->
is_admin
;
my
$req
=
Ravada::
Request
->
list_snap
(
uid
=>
$USER
->
id
,
id_domain
=>
$c
->
stash
('
id_domain
')
);
warn
$req
;
return
$c
->
render
(
json
=>
{
request
=>
$req
->
id
});
};
###################################################
## user_settings
...
...
templates/main/settings_machine_tabs_body.html.ep
View file @
778dca26
...
...
@@ -59,6 +59,9 @@
% }
</div>
% }
<div class="tab-pane fade" id="snapshots">
%= include 'main/vm_snapshots'
</div>
<div class="tab-pane fade" id="copy">
%= include 'main/vm_copy'
</div>
...
...
templates/main/settings_machine_tabs_head.html.ep
View file @
778dca26
...
...
@@ -14,6 +14,7 @@
% if ($USER->can_change_settings($domain->id)){
<li class="nav"><a ng-click="refresh_machine()" href="#hardware" data-toggle="tab"><%=l 'Hardware' %></a></li>
% }
<li class="nav"><a href="#snapshots" ng-click="refresh_machine()" data-toggle="tab"><%=l 'Snapshots' %></a></li>
% if ($USER->can_change_settings($domain->id) && !$domain->is_base) {
<li class="nav"><a ng-click="refresh_machine()" href="#screenshot" data-toggle="tab"><%=l 'Screenshot' %></a></li>
% }
...
...
templates/main/vm_snapshots.html.ep
0 → 100644
View file @
778dca26
<div class="panel-body">
%= include "main/needs_restart"
<div ng-repeat="(name) in showmachine.snapshots">
<ul ng-show="value">
<li>{{name}}
<button class="label label-danger" title="remove {{name}}"
ng-disabled="pending_requests > 0"
ng-click="delete_snapshot(name)"><i class="fa fa-times"></i> Delete
</button>
<button class="label label-info" title="revert to {{name}}"
ng-disabled="pending_requests > 0"
ng-click="revert_to_snapshot(name)"><i class="fa fa-times"></i> Delete
</button>
</li>
</ul>
</div>
<div class="input-group">
<input type="text" class="form-control" placeholder="Snapshot Name" id="take-snap">
<span class="input-group-btn">
<button class="btn btn-default" ng-disabled="pending_requests > 0"
ng-click="take_snapshot();">
<%=l 'Take Snapshot' %>
</button>
</span>
</div>
</div>
\ No newline at end of file
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