Unverified Commit 37e9183d authored by Francesc Guasch's avatar Francesc Guasch Committed by GitHub
Browse files

Feat: Extra iso (#1694)

feat: download extra ISO file for installation

* test: check extra iso and then removed in clone
parent 76512fb0
......@@ -707,6 +707,8 @@ sub _update_isos {
,xml_volume => 'windows10-volume.xml'
,min_disk_size => '21'
,arch => 'x86_64'
,extra_iso => 'https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.215-\d+/virtio-win-0.1.\d+.iso'
}
,windows_xp => {
name => 'Windows XP'
......@@ -2295,6 +2297,7 @@ sub _upgrade_tables {
$self->_upgrade_table('iso_images','options','varchar(255)');
$self->_upgrade_table('iso_images','has_cd','int (1) DEFAULT "1"');
$self->_upgrade_table('iso_images','downloading','int (1) DEFAULT "0"');
$self->_upgrade_table('iso_images','extra_iso','varchar(255)');
$self->_upgrade_table('users','language','char(40) DEFAULT NULL');
if ( $self->_upgrade_table('users','is_external','int(11) DEFAULT 0')) {
......@@ -2772,13 +2775,58 @@ sub create_domain {
die $error if $error && !$request;
$request->error($error) if $error;
}
return if !$domain;
my $req_add_data;
if ($data) {
$req_add_data = Ravada::Request->add_hardware(
uid => $args{id_owner}
,id_domain => $domain->id
,name => 'disk'
,data => { size => $data, type => 'data' }
);
}
_add_extra_iso($domain, $request,$req_add_data) if $domain;
return $domain;
}
sub _search_iso($id) {
my $sth = $CONNECTOR->dbh->prepare(
"SELECT * FROM iso_images"
." WHERE id = ? "
);
$sth->execute($id);
my $row = $sth->fetchrow_hashref;
return $row;
}
sub _add_extra_iso($domain, $request, $previous_request) {
return if !$request;
my $id_iso = $request->defined_arg('id_iso');
return if !$id_iso;
my $iso = _search_iso($id_iso);
my $extra_iso = $iso->{extra_iso};
return if !$extra_iso;
my ($url, $file_re) = $extra_iso =~ m{(.*)/(.*)};
my $volume = $domain->_vm->search_volume_path_re(qr($file_re));
if (!$volume) {
my ($url) = $domain->_vm->_search_url_file($extra_iso);
my ($device) = $url =~ m{.*/(.*)};
$volume = $domain->_vm->dir_img()."/$device";
$domain->_vm->_download_file_external($url, $volume) ;
}
Ravada::Request->add_hardware(
uid => $args{id_owner}
name => 'disk'
,uid => Ravada::Utils::user_daemon->id
,id_domain => $domain->id
,name => 'disk'
,data => { size => $data, type => 'data' }
) if $domain && $data;
return $domain;
,data => {
file => $volume
,device => 'cdrom'
}
,after_request => $previous_request->id
);
}
sub _check_args($args,@) {
......
......@@ -528,6 +528,7 @@ sub add_volume {
}
sub _create_volume($self, $file, $format, $data=undef) {
confess "Undefined format" if !defined $format;
if ($format =~ /iso|raw|void/) {
$data->{format} = $format;
$self->_vm->write_file($file, Dump($data)),
......
......@@ -458,6 +458,23 @@ sub _iso_name($self, $iso, $request=undef, $verbose=0) {
return $name;
}
sub _search_url_file($self, $url) {
my ($url0,$file) = $url =~ m{(.*)/(.*)};
confess "Undefined file in url=$url" if !$file;
my $file0 = $file;
$file =~ s/(.*)\.\*(.*)/$1$2/;
$file =~ s/(.*)\.\+(.*)/$1.$2/;
$file =~ s/(.*)\[\\d.*?\]\+(.*)/${1}1$2/;
$file =~ s/(.*)\\d\+(.*)/${1}1$2/;
confess Dumper($url, $file0,$file) if $file =~ m{[*+\\]}
|| $file !~ /\.iso$/;
return "$url0/$file";
}
sub _download_file_external($self, $url, $device) {
}
#########################################################################3
1;
......@@ -74,6 +74,9 @@ sub test_windows($vm) {
,name => $name
,id_iso => $iso->{id}
,vm => $vm->type
,swap => 10*1024
,data => 10*1024
,options => { 'uefi' => 1 , machine => 'pc-q35-4.2' }
);
my $req = Ravada::Request->create_domain(@args);
ok($req->status,'done');
......@@ -91,8 +94,39 @@ sub test_windows($vm) {
my $domain = rvd_back->search_domain($name);
ok($domain, "Expected domain $name created") or exit;
test_cd_removed($domain);
test_extra_iso($domain) if $iso->{extra_iso};
}
}
sub test_extra_iso($domain) {
my $disks = $domain->info(user_admin)->{hardware}->{disk};
my @cds = grep { defined $_->{file} && $_->{file} =~ /\.iso$/i } @$disks;
is(scalar(@cds),2);
}
sub test_cd_removed($domain) {
my $req = Ravada::Request->prepare_base(
uid => user_admin->id
,id_domain => $domain->id
);
wait_request();
my $name = new_domain_name();
Ravada::Request->clone(
id_domain => $domain->id
,uid => user_admin->id
,name => $name
);
wait_request();
my $clone = rvd_back->search_domain($name);
my $disks = $clone->info(user_admin)->{hardware}->{disk};
my @cds = grep { defined $_->{file} && $_->{file} =~ /\.iso$/i } @$disks;
is(scalar(@cds),0);
}
#########################################################
clean();
......
......@@ -222,12 +222,22 @@
role="alert">
<strong><%=l 'Error' %></strong> <%=l 'Invalid Template' %>
</div>
<div ng-show="id_iso && id_iso.has_cd && !id_iso.url
&& (!iso_file || iso_file == '' || iso_file == '<NONE')
" class="alert alert-warning"
role="alert">
<strong><%=l 'Error' %></strong> <%=l 'Please select an ISO file' %>
</div>
</div>
<div class="form-group row">
<button type="reset" class="btn btn-outline-secondary mr-2" onclick = "location='/admin/machines'"><%=l 'Cancel' %></button>
<input type="submit" class="btn btn-primary" name="submit" value="<%=l 'Create' %>"
ng-disabled="new_machineForm.$invalid || name_duplicated || (id_iso && !id_iso.id)">
ng-disabled="new_machineForm.$invalid || name_duplicated || (id_iso && !id_iso.id)
|| (id_iso && id_iso.has_cd && !id_iso.url
&& (!iso_file || iso_file == '' || iso_file == '<NONE')
)
">
</div>
</form>
</div>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment