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
af659aad
Commit
af659aad
authored
Sep 27, 2016
by
Francesc Guasch
Browse files
improved create domain request
parent
3817e5a4
Changes
6
Hide whitespace changes
Inline
Side-by-side
lib/Ravada.pm
View file @
af659aad
...
...
@@ -443,6 +443,8 @@ sub process_requests {
my
$debug
=
shift
;
my
$dont_fork
=
shift
;
$self
->
_wait_pids_nohang
();
my
$sth
=
$CONNECTOR
->
dbh
->
prepare
("
SELECT id FROM requests WHERE status='requested'
");
$sth
->
execute
;
while
(
my
(
$id
)
=
$sth
->
fetchrow
)
{
...
...
@@ -453,7 +455,9 @@ sub process_requests {
$req
->
error
(
$@
);
$req
->
status
('
done
');
}
warn
"
status:
"
.
$req
->
status
()
.
"
error: '
"
.
(
$req
->
error
or
'')
.
"
'
"
if
$DEBUG
||
$debug
;
warn
"
req
"
.
$req
->
id
.
"
, command:
"
.
$req
->
command
.
"
, status:
"
.
$req
->
status
()
.
"
, error: '
"
.
(
$req
->
error
or
'
NONE
')
.
"
'
"
if
$DEBUG
||
$debug
;
}
$sth
->
finish
;
}
...
...
@@ -517,9 +521,9 @@ sub _do_cmd_create{
my
$request
=
shift
;
$request
->
status
('
creating domain
');
warn
"
$$ creating domain
";
warn
"
$$ creating domain
"
if
$DEBUG
;
my
$domain
;
eval
{
$domain
=
$self
->
create_domain
(
%
{
$request
->
args
},
request
=>
$request
)
}
;
$domain
=
$self
->
create_domain
(
%
{
$request
->
args
},
request
=>
$request
);
warn
$@
if
$@
;
$request
->
status
('
done
');
...
...
@@ -527,6 +531,17 @@ sub _do_cmd_create{
}
sub
_wait_pids_nohang
{
my
$self
=
shift
;
return
if
!
keys
%
{
$self
->
{
pids
}};
my
$kid
=
waitpid
(
-
1
,
WNOHANG
);
return
if
!
$kid
;
warn
"
Kid
$kid
finished
";
delete
$self
->
{
pids
}
->
{
$kid
};
}
sub
_wait_pids
{
my
$self
=
shift
;
my
$request
=
shift
;
...
...
lib/Ravada/Request.pm
View file @
af659aad
...
...
@@ -6,6 +6,7 @@ use warnings;
use
Carp
qw(confess)
;
use
Data::
Dumper
;
use
JSON::
XS
;
use
Hash::
Util
;
use
Ravada
;
use
Ravada::
Front
;
...
...
@@ -18,7 +19,7 @@ Request a command to the ravada backend
=cut
our
%FIELD
=
map
{
$_
=>
1
}
qw(error)
;
our
%FIELD_RO
=
map
{
$_
=>
1
}
qw(name)
;
our
%FIELD_RO
=
map
{
$_
=>
1
}
qw(
id
name)
;
our
%VALID_ARG
=
(
create_domain
=>
{
...
...
@@ -81,7 +82,7 @@ sub open {
$row
->
{
args
}
=
$args
;
bless
(
$row
,
$class
);
bless
(
$row
,
$class
);
return
$row
;
}
...
...
@@ -452,7 +453,7 @@ sub AUTOLOAD {
$name
=~
tr/[a-z]/_/c
;
confess
"
ERROR: Unknown field
$name
"
if
!
exists
$self
->
{
$name
}
||
!
exists
$FIELD
{
$name
};
if
!
exists
$self
->
{
$name
}
&&
!
exists
$FIELD
{
$name
}
&&
!
exists
$FIELD_RO
{
$name
}
;
if
(
!
defined
$value
)
{
my
$sth
=
$$CONNECTOR
->
dbh
->
prepare
("
SELECT * FROM requests
"
.
"
WHERE id=?
");
...
...
public/templates/new_machine.html
View file @
af659aad
...
...
@@ -29,7 +29,7 @@
<h2>
New Base
</h2>
</div>
<div
class=
"panel-body"
>
<form
name=
"new_machineForm"
role=
"form"
method=
"post"
action=
"
#
"
ng-controller=
"new_machine"
novalidate
>
<form
name=
"new_machineForm"
role=
"form"
method=
"post"
action=
"
/machines/new
"
ng-controller=
"new_machine"
novalidate
>
<div
class=
"from-group"
>
<label
for=
"name"
>
Name
</label>
<input
class=
"form-control"
ng-model=
"name"
type=
"text"
ng-maxlength=
"20"
name=
"name"
required=
""
><br/>
...
...
rvd_front.pl
View file @
af659aad
...
...
@@ -151,6 +151,16 @@ get '/machine/prepare/*.html' => sub {
return
prepare_machine
(
$c
);
};
##############################################
#
get
'
/request/*.html
'
=>
sub
{
my
$c
=
shift
;
my
(
$id
)
=
$c
->
req
->
url
->
to_abs
->
path
=~
m{/(\d+)\.html}
;
return
_show_request
(
$c
,
$id
);
};
get
'
/requests.json
'
=>
sub
{
my
$c
=
shift
;
return
list_requests
(
$c
);
...
...
@@ -293,21 +303,7 @@ sub new_machine {
if
(
$c
->
param
('
submit
'))
{
push
@error
,("
Name is mandatory
")
if
!
$c
->
param
('
name
');
if
(
!
@error
)
{
my
$request
=
req_new_domain
(
$c
);
if
(
$request
)
{
if
(
$request
->
status
eq
'
done
')
{
my
$domain
=
$RAVADA
->
search_domain
(
$c
->
param
('
name
'));
return
show_link
(
$c
,
$domain
)
if
$domain
;
return
show_failure
(
$c
,
$c
->
param
('
name
'))
if
!
$domain
;
return
_show_request
(
$c
,
$request
);
}
}
else
{
return
show_failure
(
$c
,
$c
->
param
('
name
'));
}
}
return
_show_request
(
$c
,
req_new_domain
(
$c
))
if
!
@error
;
}
warn
join
("
\n
",
@error
)
if
@error
;
...
...
@@ -335,12 +331,37 @@ sub req_new_domain {
sub
_show_request
{
my
$c
=
shift
;
my
$request
=
shift
;
my
$id_request
=
shift
;
my
$request
;
if
(
!
ref
$id_request
)
{
warn
"
opening request
$id_request
";
eval
{
$request
=
Ravada::
Request
->
open
(
$id_request
)
};
warn
$@
if
$@
;
return
$c
->
render
(
data
=>
"
Request
$id_request
unknown
")
if
!
$request
;
}
else
{
$request
=
$id_request
;
}
return
$c
->
render
(
data
=>
"
Request
$id_request
unknown
"
.
Dumper
(
$request
))
if
!
$request
->
{
id
};
$c
->
render
(
template
=>
'
bootstrap/request
'
,
request
=>
$request
);
return
if
$request
->
status
ne
'
done
';
return
$c
->
render
(
data
=>
"
Request
$id_request
error
"
.
$request
->
error
)
if
$request
->
error
;
my
$name
=
$request
->
args
('
name
');
my
$domain
=
$RAVADA
->
search_domain
(
$name
);
if
(
!
$domain
)
{
return
$c
->
render
(
data
=>
"
Request
"
.
$request
->
status
.
"
, but I can't find domain
$name
");
}
return
view_machine
(
$c
,
$domain
);
}
sub
_search_req_base_error
{
...
...
@@ -453,9 +474,12 @@ sub manage_machine {
}
sub
view_machine
{
my
$c
=
shift
;
my
$domain
=
shift
;
return
login
(
$c
)
if
!
_logged_in
(
$c
);
return
show_link
(
$c
,
_search_requested_machine
(
$c
));
$domain
=
_search_requested_machine
(
$c
)
if
!
$domain
;
return
show_link
(
$c
,
$domain
);
}
sub
clone_machine
{
...
...
t/30_request.t
View file @
af659aad
...
...
@@ -90,6 +90,9 @@ sub test_req_create_domain_iso {
,"
Status of request is
"
.
$req
->
status
.
"
it should be done
");
ok
(
!
$req
->
error
,"
Error
"
.
$req
->
error
.
"
creating domain
"
.
$name
);
my
$req2
=
Ravada::
Request
->
open
(
$req
->
id
);
ok
(
$req2
->
{
id
}
==
$req
->
id
,"
req2->{id} =
"
.
$req2
->
{
id
}
.
"
, expecting
"
.
$req
->
id
);
my
$domain
=
$ravada
->
search_domain
(
$name
);
ok
(
$domain
,"
I can't find domain
$name
");
...
...
templates/bootstrap/request.html.ep
View file @
af659aad
<h1>Request</h1>
<a href="/request/<%= $request->{id} %>.html">refresh</a><br>
<%= Data::Dumper::Dumper($request) %>
Write
Preview
Supports
Markdown
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