add alias for node sftp address

This commit is contained in:
Boy132 2024-06-04 09:17:36 +02:00
parent 33f10cbcb9
commit 8f2261f6cd
9 changed files with 60 additions and 10 deletions

View File

@ -25,6 +25,7 @@ class MakeNodeCommand extends Command
{--uploadSize= : Enter the maximum upload filesize.} {--uploadSize= : Enter the maximum upload filesize.}
{--daemonListeningPort= : Enter the daemon listening port.} {--daemonListeningPort= : Enter the daemon listening port.}
{--daemonSFTPPort= : Enter the daemon SFTP listening port.} {--daemonSFTPPort= : Enter the daemon SFTP listening port.}
{--daemonSFTPAlias= : Enter the daemon SFTP alias.}
{--daemonBase= : Enter the base folder.}'; {--daemonBase= : Enter the base folder.}';
protected $description = 'Creates a new node on the system via the CLI.'; protected $description = 'Creates a new node on the system via the CLI.';
@ -65,6 +66,7 @@ class MakeNodeCommand extends Command
$data['upload_size'] = $this->option('uploadSize') ?? $this->ask(__('commands.make_node.upload_size'), '100'); $data['upload_size'] = $this->option('uploadSize') ?? $this->ask(__('commands.make_node.upload_size'), '100');
$data['daemon_listen'] = $this->option('daemonListeningPort') ?? $this->ask(__('commands.make_node.daemonListen'), '8080'); $data['daemon_listen'] = $this->option('daemonListeningPort') ?? $this->ask(__('commands.make_node.daemonListen'), '8080');
$data['daemon_sftp'] = $this->option('daemonSFTPPort') ?? $this->ask(__('commands.make_node.daemonSFTP'), '2022'); $data['daemon_sftp'] = $this->option('daemonSFTPPort') ?? $this->ask(__('commands.make_node.daemonSFTP'), '2022');
$data['daemon_sftp_alias'] = $this->option('daemonSFTPAlias') ?? $this->ask(__('commands.make_node.daemonSFTPAlias'), '');
$data['daemon_base'] = $this->option('daemonBase') ?? $this->ask(__('commands.make_node.daemonBase'), '/var/lib/pelican/volumes'); $data['daemon_base'] = $this->option('daemonBase') ?? $this->ask(__('commands.make_node.daemonBase'), '/var/lib/pelican/volumes');
$node = $this->creationService->handle($data); $node = $this->creationService->handle($data);

View File

@ -215,6 +215,18 @@ class EditNode extends EditRecord
->minValue(1) ->minValue(1)
->maxValue(1024) ->maxValue(1024)
->suffix('MiB'), ->suffix('MiB'),
Forms\Components\TextInput::make('daemon_sftp')
->columnSpan(['default' => 1, 'sm' => 1, 'md' => 1, 'lg' => 3])
->label('SFTP Port')
->minValue(0)
->maxValue(65536)
->default(2022)
->required()
->integer(),
Forms\Components\TextInput::make('daemon_sftp_alias')
->columnSpan(['default' => 1, 'sm' => 1, 'md' => 1, 'lg' => 3])
->label('SFTP Alias')
->helperText('Display alias for the SFTP address. Leave empty to use the Node FQDN.'),
Forms\Components\ToggleButtons::make('public') Forms\Components\ToggleButtons::make('public')
->columnSpan(['default' => 1, 'sm' => 1, 'md' => 1, 'lg' => 3]) ->columnSpan(['default' => 1, 'sm' => 1, 'md' => 1, 'lg' => 3])
->label('Automatic Allocation')->inline() ->label('Automatic Allocation')->inline()

View File

@ -33,10 +33,9 @@ class StoreNodeRequest extends ApplicationApiRequest
'upload_size', 'upload_size',
'daemon_listen', 'daemon_listen',
'daemon_sftp', 'daemon_sftp',
'daemon_sftp_alias',
'daemon_base', 'daemon_base',
])->mapWithKeys(function ($value, $key) { ])->mapWithKeys(function ($value, $key) {
$key = ($key === 'daemon_sftp') ? 'daemon_sftp' : $key;
return [snake_case($key) => $value]; return [snake_case($key) => $value];
})->toArray(); })->toArray();
} }
@ -60,12 +59,8 @@ class StoreNodeRequest extends ApplicationApiRequest
public function validated($key = null, $default = null): array public function validated($key = null, $default = null): array
{ {
$response = parent::validated(); $response = parent::validated();
$response['daemon_listen'] = $response['daemon_listen'];
$response['daemon_sftp'] = $response['daemon_sftp'];
$response['daemon_base'] = $response['daemon_base'] ?? (new Node())->getAttribute('daemon_base'); $response['daemon_base'] = $response['daemon_base'] ?? (new Node())->getAttribute('daemon_base');
unset($response['daemon_base'], $response['daemon_listen'], $response['daemon_sftp']);
return $response; return $response;
} }
} }

View File

@ -33,6 +33,7 @@ use Illuminate\Database\Eloquent\Relations\HasManyThrough;
* @property string $daemon_token * @property string $daemon_token
* @property int $daemon_listen * @property int $daemon_listen
* @property int $daemon_sftp * @property int $daemon_sftp
* @property string|null $daemon_sftp_alias
* @property string $daemon_base * @property string $daemon_base
* @property \Carbon\Carbon $created_at * @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at * @property \Carbon\Carbon $updated_at
@ -72,7 +73,7 @@ class Node extends Model
'memory', 'memory_overallocate', 'disk', 'memory', 'memory_overallocate', 'disk',
'disk_overallocate', 'cpu', 'cpu_overallocate', 'disk_overallocate', 'cpu', 'cpu_overallocate',
'upload_size', 'daemon_base', 'upload_size', 'daemon_base',
'daemon_sftp', 'daemon_listen', 'daemon_sftp', 'daemon_sftp_alias', 'daemon_listen',
'description', 'maintenance_mode', 'description', 'maintenance_mode',
]; ];
@ -91,6 +92,7 @@ class Node extends Model
'cpu_overallocate' => 'required|numeric|min:-1', 'cpu_overallocate' => 'required|numeric|min:-1',
'daemon_base' => 'sometimes|required|regex:/^([\/][\d\w.\-\/]+)$/', 'daemon_base' => 'sometimes|required|regex:/^([\/][\d\w.\-\/]+)$/',
'daemon_sftp' => 'required|numeric|between:1,65535', 'daemon_sftp' => 'required|numeric|between:1,65535',
'daemon_sftp_alias' => 'nullable|string',
'daemon_listen' => 'required|numeric|between:1,65535', 'daemon_listen' => 'required|numeric|between:1,65535',
'maintenance_mode' => 'boolean', 'maintenance_mode' => 'boolean',
'upload_size' => 'int|between:1,1024', 'upload_size' => 'int|between:1,1024',

View File

@ -46,6 +46,7 @@ class ServerTransformer extends BaseClientTransformer
'is_node_under_maintenance' => $server->node->isUnderMaintenance(), 'is_node_under_maintenance' => $server->node->isUnderMaintenance(),
'sftp_details' => [ 'sftp_details' => [
'ip' => $server->node->fqdn, 'ip' => $server->node->fqdn,
'alias' => $server->node->daemon_sftp_alias,
'port' => $server->node->daemon_sftp, 'port' => $server->node->daemon_sftp,
], ],
'description' => $server->description, 'description' => $server->description,

View File

@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('nodes', function (Blueprint $table) {
$table->text('daemon_sftp_alias')->nullable()->after('daemon_sftp');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('nodes', function (Blueprint $table) {
$table->dropColumn('daemon_sftp_alias');
});
}
};

View File

@ -37,6 +37,7 @@ return [
'upload_size' => "'Enter the maximum filesize upload", 'upload_size' => "'Enter the maximum filesize upload",
'daemonListen' => 'Enter the daemon listening port', 'daemonListen' => 'Enter the daemon listening port',
'daemonSFTP' => 'Enter the daemon SFTP listening port', 'daemonSFTP' => 'Enter the daemon SFTP listening port',
'daemonSFTPAlias' => 'Enter the daemon SFTP alias (can be empty)',
'daemonBase' => 'Enter the base folder', 'daemonBase' => 'Enter the base folder',
'succes1' => 'Successfully created a new node with the name: ', 'succes1' => 'Successfully created a new node with the name: ',
'succes2' => 'and has an id of: ', 'succes2' => 'and has an id of: ',

View File

@ -21,6 +21,7 @@ export interface Server {
status: ServerStatus; status: ServerStatus;
sftpDetails: { sftpDetails: {
ip: string; ip: string;
alias: string;
port: number; port: number;
}; };
invocation: string; invocation: string;
@ -57,6 +58,7 @@ export const rawDataToServerObject = ({ attributes: data }: FractalResponseData)
dockerImage: data.docker_image, dockerImage: data.docker_image,
sftpDetails: { sftpDetails: {
ip: data.sftp_details.ip, ip: data.sftp_details.ip,
alias: data.sftp_details.alias,
port: data.sftp_details.port, port: data.sftp_details.port,
}, },
description: data.description ? (data.description.length > 0 ? data.description : null) : null, description: data.description ? (data.description.length > 0 ? data.description : null) : null,

View File

@ -31,8 +31,12 @@ export default () => {
<TitledGreyBox title={'SFTP Details'} css={tw`mb-6 md:mb-10`}> <TitledGreyBox title={'SFTP Details'} css={tw`mb-6 md:mb-10`}>
<div> <div>
<Label>Server Address</Label> <Label>Server Address</Label>
<CopyOnClick text={`sftp://${ip(sftp.ip)}:${sftp.port}`}> <CopyOnClick text={`sftp://${sftp.alias ? sftp.alias : ip(sftp.ip)}:${sftp.port}`}>
<Input type={'text'} value={`sftp://${ip(sftp.ip)}:${sftp.port}`} readOnly /> <Input
type={'text'}
value={`sftp://${sftp.alias ? sftp.alias : ip(sftp.ip)}:${sftp.port}`}
readOnly
/>
</CopyOnClick> </CopyOnClick>
</div> </div>
<div css={tw`mt-6`}> <div css={tw`mt-6`}>
@ -50,7 +54,10 @@ export default () => {
</div> </div>
</div> </div>
<div css={tw`ml-4`}> <div css={tw`ml-4`}>
<a href={`sftp://${username}.${id}@${ip(sftp.ip)}:${sftp.port}`}> <a
href={`sftp://${username}.${id}@${sftp.alias ? sftp.alias : ip(sftp.ip)}:${sftp.port
}`}
>
<Button.Text variant={Button.Variants.Secondary}>Launch SFTP</Button.Text> <Button.Text variant={Button.Variants.Secondary}>Launch SFTP</Button.Text>
</a> </a>
</div> </div>