Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/UPC/ravada into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
frankiejol committed Jun 7, 2019
2 parents 40332ec + bc31ed2 commit 7e6c8e2
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 43 deletions.
14 changes: 0 additions & 14 deletions etc/xml/alpine-amd64.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@
<apic/>
<vmport state='off'/>
</features>
<cpu mode='custom' match='exact' check='full'>
<model fallback='forbid'>Penryn</model>
<feature policy='require' name='vme'/>
<feature policy='require' name='x2apic'/>
<feature policy='require' name='hypervisor'/>
</cpu>
<clock offset='utc'>
<timer name='rtc' tickpolicy='catchup'/>
<timer name='pit' tickpolicy='delay'/>
Expand Down Expand Up @@ -138,12 +132,4 @@
<address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
</memballoon>
</devices>
<seclabel type='dynamic' model='apparmor' relabel='yes'>
<label>libvirt-a289e5a7-77c8-4447-b21e-177105598ec6</label>
<imagelabel>libvirt-a289e5a7-77c8-4447-b21e-177105598ec6</imagelabel>
</seclabel>
<seclabel type='dynamic' model='dac' relabel='yes'>
<label>+64055:+130</label>
<imagelabel>+64055:+130</imagelabel>
</seclabel>
</domain>
3 changes: 0 additions & 3 deletions etc/xml/alpine-i386.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
<apic/>
<vmport state='off'/>
</features>
<cpu mode='custom' match='exact' check='partial'>
<model fallback='allow'>Penryn</model>
</cpu>
<clock offset='utc'>
<timer name='rtc' tickpolicy='catchup'/>
<timer name='pit' tickpolicy='delay'/>
Expand Down
3 changes: 0 additions & 3 deletions etc/xml/bionic-amd64.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
<apic/>
<vmport state='off'/>
</features>
<cpu mode='custom' match='exact' check='partial'>
<model fallback='allow'>Penryn</model>
</cpu>
<clock offset='utc'>
<timer name='rtc' tickpolicy='catchup'/>
<timer name='pit' tickpolicy='delay'/>
Expand Down
3 changes: 0 additions & 3 deletions etc/xml/bionic-i386.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
<apic/>
<vmport state='off'/>
</features>
<cpu mode='custom' match='exact' check='partial'>
<model fallback='allow'>Penryn</model>
</cpu>
<clock offset='utc'>
<timer name='rtc' tickpolicy='catchup'/>
<timer name='pit' tickpolicy='delay'/>
Expand Down
3 changes: 0 additions & 3 deletions etc/xml/mint19-i386.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
<apic/>
<vmport state='off'/>
</features>
<cpu mode='custom' match='exact' check='partial'>
<model fallback='allow'>Penryn</model>
</cpu>
<clock offset='utc'>
<timer name='rtc' tickpolicy='catchup'/>
<timer name='pit' tickpolicy='delay'/>
Expand Down
8 changes: 0 additions & 8 deletions etc/xml/windows_8.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,4 @@
<address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
</memballoon>
</devices>
<seclabel type='dynamic' model='apparmor' relabel='yes'>
<label>libvirt-7358e9e4-7472-416e-a2d2-c831491814e9</label>
<imagelabel>libvirt-7358e9e4-7472-416e-a2d2-c831491814e9</imagelabel>
</seclabel>
<seclabel type='dynamic' model='dac' relabel='yes'>
<label>+123:+131</label>
<imagelabel>+123:+131</imagelabel>
</seclabel>
</domain>
12 changes: 12 additions & 0 deletions lib/Ravada.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3055,6 +3055,15 @@ sub _cmd_list_network_interfaces($self, $request) {
$request->output(encode_json(\@ifs));
}

sub _cmd_list_isos($self, $request){
my $vm_type = $request->args('vm_type');

my $vm = Ravada::VM->open( type => $vm_type );
my @isos = sort { "\L$a" cmp "\L$b" } $vm->search_volume_path_re(qr(.*\.iso$));

$request->output(encode_json(\@isos));
}

sub _clean_requests($self, $command, $request=undef) {
my $query = "DELETE FROM requests "
." WHERE command=? "
Expand Down Expand Up @@ -3317,6 +3326,9 @@ sub _req_method {

#networks
,list_network_interfaces => \&_cmd_list_network_interfaces

#isos
,list_isos => \&_cmd_list_isos
);
return $methods{$cmd};
}
Expand Down
15 changes: 15 additions & 0 deletions lib/Ravada/Domain.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2090,6 +2090,20 @@ sub expose($self, @args) {
}
}

sub exposed_port($self, $search) {
confess "Error: you must supply a port number or name of exposed port"
if !defined $search || !length($search);

for my $port ($self->list_ports) {
if ( $search =~ /^\d+$/ ) {
return $port if $port->{internal_port} eq $search;
} else {
return $port if $port->{name} eq $search;
}
}
return;
}

sub _update_expose($self, %args) {
my $id = delete $args{id_port};
$args{internal_port} = delete $args{port}
Expand Down Expand Up @@ -2325,6 +2339,7 @@ sub list_ports($self) {
$sth->execute($self->id);
my @list;
while (my $data = $sth->fetchrow_hashref) {
lock_hash(%$data);
push @list,($data);
}
return @list;
Expand Down
17 changes: 11 additions & 6 deletions lib/Ravada/Front.pm
Original file line number Diff line number Diff line change
Expand Up @@ -580,12 +580,16 @@ Returns a reference to a list of the ISOs known by the system
=cut

sub iso_file {
my $self = shift;
my $vm = $self->search_vm('KVM');
my @isos = sort { "\L$a" cmp "\L$b" } $vm->search_volume_path_re(qr(.*\.iso$));
#TODO remove path from device
return \@isos;
sub iso_file ($self, $vm_type) {
my $req = Ravada::Request->list_isos(
vm_type => $vm_type
);
$self->wait_request($req);
return [] if $req->status ne 'done';

my $isos = decode_json($req->output());

return $isos;
}

=head2 list_lxc_templates
Expand Down Expand Up @@ -884,6 +888,7 @@ sub list_requests($self, $id_domain_req=undef, $seconds=60) {
|| $command eq 'connect_node'
|| $command eq 'post_login'
|| $command eq 'list_network_interfaces'
|| $command eq 'list_isos'
;
next if ( $command eq 'force_shutdown'
|| $command eq 'start'
Expand Down
5 changes: 4 additions & 1 deletion lib/Ravada/Request.pm
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ our %VALID_ARG = (
#networks
,list_network_interfaces => { uid => 1, vm_type => 1, type => 2 }

#isos
,list_isos => { vm_type => 1 }

,ping_backend => {}
);

Expand Down Expand Up @@ -137,7 +140,7 @@ our %COMMAND = (
,important=> {
limit => 20
,priority => 1
,commands => ['clone','start','start_clones','create','open_iptables','list_network_interfaces']
,commands => ['clone','start','start_clones','create','open_iptables','list_network_interfaces','list_isos']
}
,secondary => {
limit => 50
Expand Down
4 changes: 2 additions & 2 deletions rvd_front.pl
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@
return access_denied($c) unless _logged_in($c)
&& $USER->can_create_machine();
my @isos =('<NONE>');
push @isos,(@{$RAVADA->iso_file});
push @isos,(@{$RAVADA->iso_file('KVM')});
$c->render(json => \@isos);
};

Expand Down Expand Up @@ -1857,7 +1857,7 @@ sub manage_machine {
$c->stash(errors => \@errors);
return $c->render(template => 'main/settings_machine'
, nodes => [$RAVADA->list_vms($domain->type)]
, isos => $RAVADA->iso_file()
, isos => $RAVADA->iso_file($domain->type)
, list_clones => [map { $_->{name} } $domain->clones]
, action => $c->req->url->to_abs->path
);
Expand Down
16 changes: 16 additions & 0 deletions t/vm/92_ports.t
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ sub test_one_port($vm) {
};
is($@,'',"[".$vm->type."] export port $internal_port");

my $port_info_no = $domain->exposed_port(456);
is(!$port_info_no);

$port_info_no = $domain->exposed_port('no');
is(!$port_info_no);

my $port_info = $domain->exposed_port($name_port);
ok($port_info) && do {
is($port_info->{name}, $name_port);
is($port_info->{internal_port}, $internal_port);
};

my $port_info2 = $domain->exposed_port($internal_port);
ok($port_info2);
is_deeply($port_info2, $port_info);

my @list_ports = $domain->list_ports();
is(scalar @list_ports,1);

Expand Down

0 comments on commit 7e6c8e2

Please sign in to comment.