Skip to content

Commit

Permalink
Template & Templates WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ericwang401 committed Oct 15, 2024
1 parent 3898ebc commit 3b8431b
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 10 deletions.
24 changes: 24 additions & 0 deletions app/Data/Node/Storage/StorageData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace App\Data\Node\Storage;

use Spatie\LaravelData\Data;

class StorageData extends Data
{
public function __construct(
public string $name,
public int $used,
public int $free,
public int $total,
public bool $enabled,
public bool $online,
public bool $has_kvm,
public bool $has_lxc,
public bool $has_lxc_templates,
public bool $has_backups,
public bool $has_iso,
public bool $has_snippets,
) {
}
}
2 changes: 1 addition & 1 deletion app/Models/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Storage extends Model
'has_lxc' => 'required|boolean',
'has_lxc_templates' => 'required|boolean',
'has_backups' => 'required|boolean',
'has_isos' => 'required|boolean',
'has_iso' => 'required|boolean',
'has_snippets' => 'required|boolean',
];

Expand Down
50 changes: 42 additions & 8 deletions app/Repositories/Proxmox/Node/ProxmoxStorageRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,59 @@

namespace App\Repositories\Proxmox\Node;

use Carbon\CarbonImmutable;
use App\Data\Helpers\ChecksumData;
use App\Data\Node\Storage\FileMetaData;
use App\Data\Node\Storage\IsoData;
use App\Data\Node\Storage\StorageData;
use App\Enums\Node\Storage\ContentType;
use App\Exceptions\Repository\Proxmox\ProxmoxConnectionException;
use App\Exceptions\Service\Node\IsoLibrary\InvalidIsoLinkException;
use App\Models\Node;
use App\Repositories\Proxmox\ProxmoxRepository;
use Carbon\CarbonImmutable;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Spatie\LaravelData\DataCollection;
use Webmozart\Assert\Assert;

class ProxmoxStorageRepository extends ProxmoxRepository
{
public function getStorage(string $name): StorageData
{
Assert::isInstanceOf($this->node, Node::class);

$response = $this->getHttpClient()
->withUrlParameters([
'node' => $this->node->cluster,
'storage' => $name,
])
->get('/api2/json/nodes/{node}/storage/{storage}/status')
->json();

$response = $this->getData($response);

$has = fn (string $content) => Str::contains($response['content'], $content);

return new StorageData(
name : $name,
used : $response['used'],
free : $response['avail'],
total : $response['total'],
enabled: $response['enabled'],
online : $response['active'],
has_kvm: $has('images'),
has_lxc: $has('rootdir'),
has_lxc_templates: $has('templates'),
has_backups: $has('backup'),
has_iso: $has('iso'),
has_snippets: $has('snippets'),
);
}

public function download(
ContentType $contentType,
string $fileName,
string $link,
string $fileName,
string $link,
?bool $verifyCertificates = true,
?ChecksumData $checksumData = null,
) {
Expand Down Expand Up @@ -83,11 +117,11 @@ public function getIsos(): DataCollection
$isos = [];

foreach ($response as $iso) {
$isos[] = IsoData::from([
'file_name' => explode('/', $iso['volid'])[1],
'size' => $iso['size'],
'created_at' => CarbonImmutable::createFromTimestamp($iso['ctime']),
]);
$isos[] = new IsoData(
file_name : explode('/', $iso['volid'])[1],
size : $iso['size'],
created_at: CarbonImmutable::createFromTimestamp($iso['ctime']),
);
}

return IsoData::collection($isos);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function up(): void
$table->boolean('has_lxc');
$table->boolean('has_lxc_templates');
$table->boolean('has_backups');
$table->boolean('has_isos');
$table->boolean('has_iso');
$table->boolean('has_snippets');
});
}
Expand Down
Empty file.
17 changes: 17 additions & 0 deletions resources/scripts/routes/_app/servers.$serverUuid/rebuild.lazy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { createLazyFileRoute } from '@tanstack/react-router'

import { Heading } from '@/components/ui/Typography'

export const Route = createLazyFileRoute('/_app/servers/$serverUuid/rebuild')({
component: RebuildServerPage,
// @ts-ignore
meta: () => [{ title: 'Rebuild' }],
})

function RebuildServerPage() {
return (
<>
<Heading>Rebuild Server</Heading>
</>
)
}
14 changes: 14 additions & 0 deletions resources/scripts/types/template.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export interface TemplateGroup {
uuid: string
name: string
hidden: boolean
templates: Template[]
orderColumn: number
}

export interface Template {
uuid: string
name: string
hidden: boolean
orderColumn: number
}

0 comments on commit 3b8431b

Please sign in to comment.