Discard ipAddresses cache if wings is offline + Switch to Select (#862)

* Change TextInputColumn to SelectColumn

* Discard cache if wings is offline

* Return 0.0.0.0 instead of an empty array

* Adjustment & remove dns resolve
This commit is contained in:
MartinOscar 2025-01-06 03:37:39 +01:00 committed by GitHub
parent 77fd54fdc2
commit ae445840f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 9 deletions

View File

@ -16,6 +16,7 @@ use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Actions\BulkActionGroup;
use Filament\Tables\Actions\DeleteBulkAction;
use Filament\Tables\Columns\SelectColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Columns\TextInputColumn;
use Filament\Tables\Table;
@ -69,7 +70,9 @@ class AllocationsRelationManager extends RelationManager
TextInputColumn::make('ip_alias')
->searchable()
->label('Alias'),
TextInputColumn::make('ip')
SelectColumn::make('ip')
->options(fn (Allocation $allocation) => collect($this->getOwnerRecord()->ipAddresses())->merge([$allocation->ip])->mapWithKeys(fn (string $ip) => [$ip => $ip]))
->selectablePlaceholder(false)
->searchable()
->label('IP'),
])

View File

@ -374,24 +374,21 @@ class Node extends Model
{
return cache()->remember("nodes.$this->id.ips", now()->addHour(), function () {
$ips = collect();
if (is_ip($this->fqdn)) {
$ips = $ips->push($this->fqdn);
} elseif ($dnsRecords = gethostbynamel($this->fqdn)) {
$ips = $ips->concat($dnsRecords);
}
try {
$addresses = Http::daemon($this)->connectTimeout(1)->timeout(1)->get('/api/system/ips')->json();
$ips = $ips->concat(fluent($addresses)->get('ip_addresses'));
} catch (Exception) {
// pass
if (is_ip($this->fqdn)) {
$ips->push($this->fqdn);
}
}
$ips->push('0.0.0.0');
// Only IPV4
$ips = $ips->filter(fn (string $ip) => filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== false);
$ips->push('0.0.0.0');
return $ips->unique()->all();
});
}