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

NAS-133481 / 25.04 / Changes for VMs in new virtualization #11323

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions src/app/enums/virtualization.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ export const virtualizationDeviceTypeLabels = new Map<VirtualizationDeviceType,
[VirtualizationDeviceType.Usb, 'USB'],
[VirtualizationDeviceType.Tpm, 'TPM'],
[VirtualizationDeviceType.Disk, T('Disk')],
[VirtualizationDeviceType.Disk, T('GPU')],
[VirtualizationDeviceType.Disk, T('NIC')],
[VirtualizationDeviceType.Disk, T('Proxy')],
[VirtualizationDeviceType.Gpu, T('GPU')],
[VirtualizationDeviceType.Nic, T('NIC')],
[VirtualizationDeviceType.Proxy, T('Proxy')],
]);

export enum VirtualizationGpuType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@
<ix-fieldset>
<ix-explorer
formControlName="source"
root="/"
[label]="'Source' | translate"
[required]="true"
[nodeProvider]="directoryNodeProvider"
[canCreateDataset]="isNew()"
></ix-explorer>

<ix-input
formControlName="destination"
[label]="'Destination' | translate"
[required]="true"
></ix-input>
@if (form.controls.destination.enabled) {
<ix-input
formControlName="destination"
[label]="'Destination' | translate"
[required]="true"
></ix-input>
}
</ix-fieldset>

<ix-form-actions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { MatCard, MatCardContent } from '@angular/material/card';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { Observable, of } from 'rxjs';
import { VirtualizationDeviceType } from 'app/enums/virtualization.enum';
import { VirtualizationDisk } from 'app/interfaces/virtualization.interface';
import { VirtualizationDeviceType, VirtualizationType } from 'app/enums/virtualization.enum';
import { VirtualizationDisk, VirtualizationInstance } from 'app/interfaces/virtualization.interface';
import { FormActionsComponent } from 'app/modules/forms/ix-forms/components/form-actions/form-actions.component';
import { IxExplorerComponent } from 'app/modules/forms/ix-forms/components/ix-explorer/ix-explorer.component';
import { IxFieldsetComponent } from 'app/modules/forms/ix-forms/components/ix-fieldset/ix-fieldset.component';
Expand All @@ -22,7 +22,7 @@ import { ApiService } from 'app/modules/websocket/api.service';
import { FilesystemService } from 'app/services/filesystem.service';

interface InstanceDiskFormOptions {
instanceId: string;
instance: VirtualizationInstance;
disk: VirtualizationDisk | undefined;
}

Expand Down Expand Up @@ -50,7 +50,7 @@ export class InstanceDiskFormComponent implements OnInit {
private existingDisk = signal<VirtualizationDisk | null>(null);

protected readonly isLoading = signal(false);
protected readonly directoryNodeProvider = this.filesystem.getFilesystemNodeProvider({ directoriesOnly: false });
protected readonly directoryNodeProvider = this.filesystem.getFilesystemNodeProvider({ datasetsAndZvols: true });

protected form = this.formBuilder.nonNullable.group({
source: ['', Validators.required],
Expand All @@ -63,6 +63,8 @@ export class InstanceDiskFormComponent implements OnInit {
return !this.isNew() ? this.translate.instant('Edit Disk') : this.translate.instant('Add Disk');
});

protected instance = computed(() => this.slideInRef.getData().instance);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The computed callback doesn't have a signal call. This could just be a signal.
protected instance = signal(this.slideInRef.getData().instance); Or maybe doesn't need to be a signal


constructor(
private formBuilder: FormBuilder,
private errorHandler: FormErrorHandlerService,
Expand All @@ -86,6 +88,9 @@ export class InstanceDiskFormComponent implements OnInit {
destination: disk.destination || '',
});
}
if (this.instance().type === VirtualizationType.Vm) {
this.form.controls.destination.disable();
}
}

onSubmit(): void {
Expand All @@ -112,7 +117,7 @@ export class InstanceDiskFormComponent implements OnInit {
}

private prepareRequest(): Observable<unknown> {
const instanceId = this.slideInRef.getData().instanceId;
const instanceId = this.slideInRef.getData().instance.id;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can reuse the signal


const payload = {
...this.form.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ <h3 mat-card-title>
} @else {
@for (disk of visibleDisks(); track disk.name) {
<div class="disk">
<div>
{{ disk.source }}
{{ disk.destination }}
</div>
@if (disk.destination) {
<div>{{ disk.source }} → {{ disk.destination }}</div>
} @else {
<div>{{ disk.source }}</div>
}

<ix-device-actions-menu
[device]="disk"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { MatButtonHarness } from '@angular/material/button/testing';
import { createComponentFactory, mockProvider, Spectator } from '@ngneat/spectator/jest';
import { MockComponent } from 'ng-mocks';
import { of } from 'rxjs';
import { VirtualizationDeviceType } from 'app/enums/virtualization.enum';
import { VirtualizationDisk, VirtualizationProxy } from 'app/interfaces/virtualization.interface';
import { VirtualizationDeviceType, VirtualizationType } from 'app/enums/virtualization.enum';
import { VirtualizationDisk, VirtualizationInstance, VirtualizationProxy } from 'app/interfaces/virtualization.interface';
import { SlideIn } from 'app/modules/slide-ins/slide-in';
import {
InstanceDiskFormComponent,
Expand Down Expand Up @@ -44,7 +44,7 @@ describe('InstanceDisksComponent', () => {
providers: [
mockProvider(VirtualizationDevicesStore, {
isLoading: () => false,
selectedInstance: () => ({ id: 'my-instance' }),
selectedInstance: () => ({ id: 'my-instance', type: VirtualizationType.Container }),
devices: () => disks,
loadDevices: jest.fn(),
}),
Expand All @@ -65,7 +65,7 @@ describe('InstanceDisksComponent', () => {
const diskRows = spectator.queryAll('.disk');

expect(diskRows).toHaveLength(1);
expect(diskRows[0]).toHaveText('source-path → destination');
expect(diskRows[0]).toHaveText('/mnt/source-path → destination');
});

it('renders a menu to manage the disk', () => {
Expand All @@ -74,23 +74,51 @@ describe('InstanceDisksComponent', () => {
expect(actionsMenu[0].device).toBe(disks[0]);
});

it('opens disk form when Add is pressed', async () => {
const addButton = await loader.getHarness(MatButtonHarness.with({ text: 'Add' }));
await addButton.click();
describe('container', () => {
it('opens disk form when Add is pressed', async () => {
const addButton = await loader.getHarness(MatButtonHarness.with({ text: 'Add' }));
await addButton.click();

expect(spectator.inject(SlideIn).open).toHaveBeenCalledWith(
InstanceDiskFormComponent,
{ data: { disk: undefined, instanceId: 'my-instance' } },
);
expect(spectator.inject(SlideIn).open).toHaveBeenCalledWith(
InstanceDiskFormComponent,
{ data: { disk: undefined, instance: { id: 'my-instance', type: VirtualizationType.Container } as VirtualizationInstance } },
);
});

it('opens disk for for edit when actions menu emits (edit)', () => {
const actionsMenu = spectator.query(DeviceActionsMenuComponent)!;
actionsMenu.edit.emit();

expect(spectator.inject(SlideIn).open).toHaveBeenCalledWith(
InstanceDiskFormComponent,
{ data: { disk: disks[0], instance: { id: 'my-instance', type: VirtualizationType.Container } as VirtualizationInstance } },
);
});
});
describe('vm', () => {
it('opens disk form when Add is pressed', async () => {
jest.spyOn(spectator.inject(VirtualizationDevicesStore), 'selectedInstance')
.mockReturnValue({ id: 'my-instance', type: VirtualizationType.Vm } as VirtualizationInstance);

const addButton = await loader.getHarness(MatButtonHarness.with({ text: 'Add' }));
await addButton.click();

expect(spectator.inject(SlideIn).open).toHaveBeenCalledWith(
InstanceDiskFormComponent,
{ data: { disk: undefined, instance: { id: 'my-instance', type: VirtualizationType.Vm } as VirtualizationInstance } },
);
});

it('opens disk for for edit when actions menu emits (edit)', () => {
const actionsMenu = spectator.query(DeviceActionsMenuComponent)!;
actionsMenu.edit.emit();
it('opens disk for for edit when actions menu emits (edit)', () => {
jest.spyOn(spectator.inject(VirtualizationDevicesStore), 'selectedInstance')
.mockReturnValue({ id: 'my-instance', type: VirtualizationType.Vm } as VirtualizationInstance);
const actionsMenu = spectator.query(DeviceActionsMenuComponent)!;
actionsMenu.edit.emit();

expect(spectator.inject(SlideIn).open).toHaveBeenCalledWith(
InstanceDiskFormComponent,
{ data: { disk: disks[0], instanceId: 'my-instance' } },
);
expect(spectator.inject(SlideIn).open).toHaveBeenCalledWith(
InstanceDiskFormComponent,
{ data: { disk: disks[0], instance: { id: 'my-instance', type: VirtualizationType.Vm } as VirtualizationInstance } },
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class InstanceDisksComponent {
}

private openDiskForm(disk?: VirtualizationDisk): void {
this.slideIn.open(InstanceDiskFormComponent, { data: { disk, instanceId: this.deviceStore.selectedInstance().id } })
this.slideIn.open(InstanceDiskFormComponent, { data: { disk, instance: this.deviceStore.selectedInstance() } })
.pipe(filter((result) => !!result.response), untilDestroyed(this))
.subscribe(() => this.deviceStore.loadDevices());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,21 @@
<ix-input
formControlName="cpu"
[label]="'CPU Configuration' | translate"
[hint]="containersHelptext.cpuHint | translate"
[required]="isVm()"
[hint]="isContainer() ? (containersHelptext.cpuHint | translate) : null"
></ix-input>

<ix-input
formControlName="memory"
[label]="'Memory Size' | translate"
[format]="formatter.memorySizeFormatting"
[parse]="formatter.memorySizeParsing"
[hint]="containersHelptext.memoryHint | translate"
[required]="isVm()"
[hint]="isContainer() ? (containersHelptext.memoryHint | translate) : null"
></ix-input>
</ix-form-section>

@if (isContainer()) {
<ix-form-section
[label]="'Environment' | translate"
[help]="'Environment' | translate"
Expand Down Expand Up @@ -94,6 +97,7 @@
}
</ix-list>
</ix-form-section>
}

<ix-form-section
[label]="'Disks' | translate"
Expand All @@ -114,17 +118,20 @@
>
<ix-explorer
formControlName="source"
root="/"
[label]="'Source' | translate"
[required]="true"
[nodeProvider]="directoryNodeProvider"
[nodeProvider]="directoryNodeProvider()"
[canCreateDataset]="true"
></ix-explorer>

<ix-input
formControlName="destination"
[label]="'Destination' | translate"
[required]="true"
></ix-input>
@if (isContainer()) {
<ix-input
formControlName="destination"
[label]="'Destination' | translate"
[required]="true"
></ix-input>
}
</ix-list-item>
}
</ix-list>
Expand Down
Loading
Loading