Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If no vlan is found return random one #8569

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 28 additions & 29 deletions lib/pf/role/pool.pm
Original file line number Diff line number Diff line change
Expand Up @@ -214,39 +214,38 @@ sub getPerUserVlan {
$logger->info("Found VLAN $vlan for $pid with registered devices in it.");
$res->finish();
return $vlan;
}

$logger->debug("Unable to find a VLAN in the pool that $pid has devices in. Finding an available VLAN for this user.");
($status, $res) = pf::dal->db_execute("
SELECT vlan
FROM locationlog
JOIN node USING (mac)
WHERE vlan IN ( $sql_vlans )
AND node.status != 'unreg'
");
if(is_error($status)) {
$logger->error("Error while finding available VLAN for $pid");
return;
}
else {
$logger->debug("Unable to find a VLAN in the pool that $pid has devices in. Finding an available VLAN for this user.");
($status, $res) = pf::dal->db_execute("
SELECT vlan
FROM locationlog
JOIN node USING (mac)
WHERE vlan IN ( $sql_vlans )
AND node.status != 'unreg'
");
if(is_error($status)) {
$logger->error("Error while finding available VLAN for $pid");
return;
}

my %used_vlans = map{$_->[0] => 1} @{$res->fetchall_arrayref};
$res->finish();
my $available_vlan;
for my $vlan (@vlans) {
if(!exists($used_vlans{$vlan})) {
$available_vlan = $vlan;
last;
}
}
if($available_vlan) {
$logger->info("Found available VLAN $available_vlan in the pool for $pid");
return $available_vlan;
}
else {
$logger->error("No available VLAN in the pool");
return;
my %used_vlans = map{$_->[0] => 1} @{$res->fetchall_arrayref};
$res->finish();
my $available_vlan;
for my $vlan (@vlans) {
if(!exists($used_vlans{$vlan})) {
$available_vlan = $vlan;
last;
}
}

if ($available_vlan) {
$logger->info("Found available VLAN $available_vlan in the pool for $pid");
return $available_vlan;
}

$logger->error("No available VLAN in the pool");
return $vlans[int(rand(scalar @vlans))];
}

=head1 AUTHOR
Expand Down