Skip to content

Commit

Permalink
NAS-132491 / 25.04 / NAS-132402: Refactor dtype key in VM device attrs (
Browse files Browse the repository at this point in the history
#11039)

* NAS-132402: Refactor dtype key in VM device attrs

* NAS-132491: PR update

---------

Co-authored-by: undsoft <[email protected]>
  • Loading branch information
AlexKarpov98 and undsoft authored Nov 15, 2024
1 parent 33fd4dc commit b423d43
Show file tree
Hide file tree
Showing 17 changed files with 160 additions and 139 deletions.
147 changes: 73 additions & 74 deletions src/app/interfaces/vm-device.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,63 +3,6 @@ import {
VmDeviceType, VmDiskMode, VmDisplayType, VmNicType,
} from 'app/enums/vm.enum';

interface VmPciPassthroughAttributes {
pptdev: string;
type: string;
}

interface VmUsbPassthroughAttributes {
controller_type: string;
device: string | null;
usb?: {
product_id?: string;
vendor_id?: string;
};
}

export interface VmDisplayAttributes {
bind: string;
password: string;
password_configured?: boolean;
port: number;
resolution: string;
type: VmDisplayType;
wait: boolean;
web: boolean;
}

export interface VmCdRomAttributes {
path: string;
}

export interface VmRawFileAttributes {
boot: boolean;
logical_sectorsize: number;
path: string;
physical_sectorsize: number;
size: number;
type: VmDiskMode;
}

export interface VmNicAttributes {
mac: string;
nic_attach: string;
type: VmNicType;
trust_guest_rx_filters: boolean;
}

export interface VmDiskAttributes {
logical_sectorsize: number;
path: string;
physical_sectorsize: number;
type: VmDiskMode;

// TODO: May be only relevant when creating a vm
create_zvol?: boolean;
zvol_name?: string;
zvol_volsize?: number;
}

export interface BaseVmDevice {
id: number;
dtype: VmDeviceType;
Expand All @@ -69,38 +12,31 @@ export interface BaseVmDevice {
}

export interface VmPciPassthroughDevice extends BaseVmDevice {
dtype: VmDeviceType.Pci;
attributes: VmPciPassthroughAttributes;
}

export interface VmRawFileDevice extends BaseVmDevice {
dtype: VmDeviceType.Raw;
attributes: VmRawFileAttributes;
}

export interface VmNicDevice extends BaseVmDevice {
dtype: VmDeviceType.Nic;
attributes: VmNicAttributes;
export interface VmUsbPassthroughDevice extends BaseVmDevice {
attributes: VmUsbPassthroughAttributes;
}

export interface VmDisplayDevice extends BaseVmDevice {
dtype: VmDeviceType.Display;
attributes: VmDisplayAttributes;
}

export interface VmCdRomDevice extends BaseVmDevice {
dtype: VmDeviceType.Cdrom;
attributes: VmCdRomAttributes;
}

export interface VmDiskDevice extends BaseVmDevice {
dtype: VmDeviceType.Disk;
attributes: VmDiskAttributes;
export interface VmRawFileDevice extends BaseVmDevice {
attributes: VmRawFileAttributes;
}

export interface VmUsbPassthroughDevice extends BaseVmDevice {
dtype: VmDeviceType.Usb;
attributes: VmUsbPassthroughAttributes;
export interface VmNicDevice extends BaseVmDevice {
attributes: VmNicAttributes;
}

export interface VmDiskDevice extends BaseVmDevice {
attributes: VmDiskAttributes;
}

export type VmDevice =
Expand Down Expand Up @@ -162,3 +98,66 @@ export interface VmUsbPassthroughDeviceChoice {
available: boolean;
error: unknown;
}

interface VmDisplayAttributes {
bind: string;
password: string;
password_configured?: boolean;
port: number;
resolution: string;
type: VmDisplayType;
wait: boolean;
web: boolean;
dtype: VmDeviceType.Display;
}

interface VmCdRomAttributes {
path: string;
dtype: VmDeviceType.Cdrom;
}

interface VmRawFileAttributes {
boot: boolean;
logical_sectorsize: number;
path: string;
physical_sectorsize: number;
size: number;
type: VmDiskMode;
dtype: VmDeviceType.Raw;
}

interface VmNicAttributes {
mac: string;
nic_attach: string;
type: VmNicType;
trust_guest_rx_filters: boolean;
dtype: VmDeviceType.Nic;
}

interface VmDiskAttributes {
logical_sectorsize: number;
path: string;
physical_sectorsize: number;
type: VmDiskMode;
dtype: VmDeviceType.Disk;

create_zvol?: boolean;
zvol_name?: string;
zvol_volsize?: number;
}

interface VmPciPassthroughAttributes {
pptdev: string;
type: string;
dtype: VmDeviceType.Pci;
}

interface VmUsbPassthroughAttributes {
controller_type: string;
device: string | null;
usb?: {
product_id?: string;
vendor_id?: string;
};
dtype: VmDeviceType.Usb;
}
46 changes: 25 additions & 21 deletions src/app/pages/vm/devices/device-form/device-form.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ describe('DeviceFormComponent', () => {
describe('CD-ROM', () => {
const existingCdRom = {
id: 5,
dtype: VmDeviceType.Cdrom,
attributes: {
dtype: VmDeviceType.Cdrom,
path: '/mnt/bassein/cdrom',
},
order: 4,
Expand Down Expand Up @@ -143,8 +143,10 @@ describe('DeviceFormComponent', () => {
await saveButton.click();

expect(websocket.call).toHaveBeenLastCalledWith('vm.device.create', [{
dtype: VmDeviceType.Cdrom,
attributes: { path: '/mnt/cdrom' },
attributes: {
path: '/mnt/cdrom',
dtype: VmDeviceType.Cdrom,
},
order: 1002,
vm: 45,
}]);
Expand Down Expand Up @@ -186,8 +188,10 @@ describe('DeviceFormComponent', () => {
await saveButton.click();

expect(websocket.call).toHaveBeenLastCalledWith('vm.device.update', [5, {
attributes: { path: '/mnt/newcdrom' },
dtype: VmDeviceType.Cdrom,
attributes: {
path: '/mnt/newcdrom',
dtype: VmDeviceType.Cdrom,
},
order: 4,
vm: 45,
}]);
Expand All @@ -198,12 +202,12 @@ describe('DeviceFormComponent', () => {
describe('NIC', () => {
const existingNic = {
id: 2,
dtype: VmDeviceType.Nic,
attributes: {
type: 'E1000',
mac: '00:a0:98:53:a5:ac',
nic_attach: 'enp0s3',
trust_guest_rx_filters: false,
dtype: VmDeviceType.Nic,
},
order: 1002,
vm: 1,
Expand Down Expand Up @@ -246,8 +250,8 @@ describe('DeviceFormComponent', () => {
nic_attach: 'enp0s4',
type: VmNicType.Virtio,
trust_guest_rx_filters: true,
dtype: VmDeviceType.Nic,
},
dtype: VmDeviceType.Nic,
order: 1006,
vm: 45,
}]);
Expand Down Expand Up @@ -317,8 +321,8 @@ describe('DeviceFormComponent', () => {
describe('Disk', () => {
const existingDisk = {
id: 3,
dtype: VmDeviceType.Disk,
attributes: {
dtype: VmDeviceType.Disk,
path: '/dev/zvol/bassein/zvol1',
type: VmDiskMode.Ahci,
physical_sectorsize: 4096,
Expand Down Expand Up @@ -365,8 +369,8 @@ describe('DeviceFormComponent', () => {
physical_sectorsize: 512,
path: '/dev/zvol/bassein/zvol1',
type: VmDiskMode.Virtio,
dtype: VmDeviceType.Disk,
},
dtype: VmDeviceType.Disk,
order: 1002,
vm: 45,
}]);
Expand Down Expand Up @@ -416,8 +420,8 @@ describe('DeviceFormComponent', () => {
physical_sectorsize: null,
path: '/dev/zvol/bassein/zvol1',
type: VmDiskMode.Ahci,
dtype: VmDeviceType.Disk,
},
dtype: VmDeviceType.Disk,
order: 1001,
vm: 45,
}]);
Expand All @@ -428,8 +432,8 @@ describe('DeviceFormComponent', () => {
describe('Raw File', () => {
const existingRawFile = {
id: 6,
dtype: VmDeviceType.Raw,
attributes: {
dtype: VmDeviceType.Raw,
path: '/mnt/bassein/raw',
type: VmDiskMode.Ahci,
size: 3,
Expand Down Expand Up @@ -479,8 +483,8 @@ describe('DeviceFormComponent', () => {
path: '/mnt/bassein/newraw',
size: 3,
type: VmDiskMode.Ahci,
dtype: VmDeviceType.Raw,
},
dtype: VmDeviceType.Raw,
order: 6,
vm: 45,
}]);
Expand Down Expand Up @@ -531,8 +535,8 @@ describe('DeviceFormComponent', () => {
physical_sectorsize: null,
size: 5,
type: VmDiskMode.Ahci,
dtype: VmDeviceType.Raw,
},
dtype: VmDeviceType.Raw,
order: 5,
vm: 45,
}]);
Expand All @@ -543,8 +547,8 @@ describe('DeviceFormComponent', () => {
describe('PCI Passthrough Device', () => {
const existingPassthrough = {
id: 4,
dtype: VmDeviceType.Pci,
attributes: {
dtype: VmDeviceType.Pci,
pptdev: 'pci_0000_00_1c_0',
},
order: 5,
Expand Down Expand Up @@ -584,8 +588,8 @@ describe('DeviceFormComponent', () => {
expect(websocket.call).toHaveBeenLastCalledWith('vm.device.create', [{
attributes: {
pptdev: 'pci_0000_00_1c_0',
dtype: VmDeviceType.Pci,
},
dtype: VmDeviceType.Pci,
order: 6,
vm: 45,
}]);
Expand Down Expand Up @@ -635,8 +639,8 @@ describe('DeviceFormComponent', () => {
expect(websocket.call).toHaveBeenLastCalledWith('vm.device.update', [4, {
attributes: {
pptdev: 'pci_0000_00_1c_5',
dtype: VmDeviceType.Pci,
},
dtype: VmDeviceType.Pci,
order: 5,
vm: 45,
}]);
Expand All @@ -647,8 +651,8 @@ describe('DeviceFormComponent', () => {
describe('Display', () => {
const existingDisplay = {
id: 1,
dtype: VmDeviceType.Display,
attributes: {
dtype: VmDeviceType.Display,
bind: '0.0.0.0',
password: '12345678910',
web: true,
Expand Down Expand Up @@ -722,8 +726,8 @@ describe('DeviceFormComponent', () => {
describe('USB Passthrough Device', () => {
const existingUsb = {
id: 1,
dtype: VmDeviceType.Usb,
attributes: {
dtype: VmDeviceType.Usb,
controller_type: 'pci-ohci',
device: 'usb_device_2',
},
Expand Down Expand Up @@ -763,8 +767,8 @@ describe('DeviceFormComponent', () => {
attributes: {
controller_type: 'pci-ohci',
device: 'usb_device_2',
dtype: VmDeviceType.Usb,
},
dtype: VmDeviceType.Usb,
order: null,
vm: 45,
}]);
Expand Down Expand Up @@ -810,8 +814,8 @@ describe('DeviceFormComponent', () => {
attributes: {
controller_type: 'piix3-uhci',
device: 'usb_device_1',
dtype: VmDeviceType.Usb,
},
dtype: VmDeviceType.Usb,
order: 7,
vm: 45,
}]);
Expand All @@ -838,8 +842,8 @@ describe('DeviceFormComponent', () => {
vendor_id: 'vendor_1',
product_id: 'product_1',
},
dtype: VmDeviceType.Usb,
},
dtype: VmDeviceType.Usb,
order: 7,
vm: 45,
}]);
Expand Down
Loading

0 comments on commit b423d43

Please sign in to comment.