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

Feature #265 ports 2 (#1094)

feature(ports): get port exposed

issue #265
parent b6969695
......@@ -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}
......@@ -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;
......
......@@ -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);
......
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