-
Notifications
You must be signed in to change notification settings - Fork 310
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-132721 / 25.04 / Support for NICs in containers #11116
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
02d2425
NAS-132721: Support for NICs in containers
AlexKarpov98 4bbcc63
NAS-132721: Support for NICs in containers
AlexKarpov98 57c22b6
NAS-132721: Support for NICs in containers
AlexKarpov98 8a3ac55
Merge branch 'master' into NAS-132721
AlexKarpov98 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...nts/all-instances/instance-details/instance-nics/add-nic-menu/add-nic-menu.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
@if (isLoadingDevices()) { | ||
<ngx-skeleton-loader class="loader"></ngx-skeleton-loader> | ||
} @else if (hasNicsToAdd()) { | ||
<button | ||
mat-button | ||
ixTest="add-nic" | ||
[disabled]="" | ||
[matMenuTriggerFor]="addNicMenu" | ||
> | ||
{{ 'Add' | translate }} | ||
</button> | ||
|
||
<mat-menu #addNicMenu="matMenu"> | ||
@if (availableBridgedNics().length) { | ||
<h4 class="menu-header">{{ bridgedNicTypeLabel | translate }}</h4> | ||
@for (nic of availableBridgedNics(); track nic) { | ||
<button | ||
mat-menu-item | ||
[ixTest]="['add-bridged-nic', nic]" | ||
(click)="addBridgedNic(nic)" | ||
> | ||
{{ nic }} | ||
</button> | ||
} | ||
} | ||
|
||
@if (availableMacVlanNics().length) { | ||
<h4 class="menu-header">{{ macVlanNicTypeLabel | translate }}</h4> | ||
@for (nic of availableMacVlanNics(); track nic) { | ||
<button | ||
mat-menu-item | ||
[ixTest]="['add-mac-vlan-nic', nic]" | ||
(click)="addMacVlanNic(nic)" | ||
> | ||
{{ nic }} | ||
</button> | ||
} | ||
} | ||
</mat-menu> | ||
} |
18 changes: 18 additions & 0 deletions
18
...nts/all-instances/instance-details/instance-nics/add-nic-menu/add-nic-menu.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
.menu-header { | ||
border-bottom: 1px solid var(--lines); | ||
font-size: 12px; | ||
margin-top: 12px; | ||
padding-bottom: 6px; | ||
padding-left: 15px; | ||
} | ||
|
||
:host .loader { | ||
display: block; | ||
flex: unset; | ||
width: 80px; | ||
|
||
::ng-deep .loader { | ||
margin-bottom: -6px; | ||
} | ||
} | ||
|
71 changes: 71 additions & 0 deletions
71
.../all-instances/instance-details/instance-nics/add-nic-menu/add-nic-menu.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { HarnessLoader } from '@angular/cdk/testing'; | ||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; | ||
import { MatMenuHarness } from '@angular/material/menu/testing'; | ||
import { createComponentFactory, mockProvider, Spectator } from '@ngneat/spectator/jest'; | ||
import { mockApi, mockCall } from 'app/core/testing/utils/mock-api.utils'; | ||
import { VirtualizationDeviceType, VirtualizationNicType } from 'app/enums/virtualization.enum'; | ||
import { VirtualizationDevice } from 'app/interfaces/virtualization.interface'; | ||
import { SnackbarService } from 'app/modules/snackbar/services/snackbar.service'; | ||
import { AddNicMenuComponent } from 'app/pages/virtualization/components/all-instances/instance-details/instance-nics/add-nic-menu/add-nic-menu.component'; | ||
import { VirtualizationDevicesStore } from 'app/pages/virtualization/stores/virtualization-devices.store'; | ||
import { ApiService } from 'app/services/websocket/api.service'; | ||
|
||
describe('AddNicMenuComponent', () => { | ||
let spectator: Spectator<AddNicMenuComponent>; | ||
let loader: HarnessLoader; | ||
const createComponent = createComponentFactory({ | ||
component: AddNicMenuComponent, | ||
providers: [ | ||
mockApi([ | ||
mockCall('virt.device.nic_choices', { | ||
nic1: 'Intel E1000', | ||
nic2: 'Realtek RTL8139', | ||
}), | ||
mockCall('virt.instance.device_add'), | ||
]), | ||
mockProvider(VirtualizationDevicesStore, { | ||
selectedInstance: () => ({ id: 'my-instance' }), | ||
devices: () => [ | ||
{ | ||
dev_type: VirtualizationDeviceType.Nic, | ||
nic_type: VirtualizationNicType.Macvlan, | ||
parent: 'already-added', | ||
}, | ||
] as VirtualizationDevice[], | ||
loadDevices: jest.fn(), | ||
isLoading: () => false, | ||
}), | ||
mockProvider(SnackbarService), | ||
], | ||
}); | ||
|
||
beforeEach(() => { | ||
spectator = createComponent(); | ||
loader = TestbedHarnessEnvironment.loader(spectator.fixture); | ||
}); | ||
|
||
it('shows available NIC devices that have not been already added to this system', async () => { | ||
const menu = await loader.getHarness(MatMenuHarness.with({ triggerText: 'Add' })); | ||
await menu.open(); | ||
|
||
const menuItems = await menu.getItems(); | ||
expect(menuItems).toHaveLength(4); | ||
expect(await menuItems[0].getText()).toContain('Intel E1000'); | ||
expect(await menuItems[1].getText()).toContain('Realtek RTL8139'); | ||
}); | ||
|
||
it('adds a NIC device when it is selected', async () => { | ||
const menu = await loader.getHarness(MatMenuHarness.with({ triggerText: 'Add' })); | ||
await menu.open(); | ||
|
||
await menu.clickItem({ text: 'Intel E1000' }); | ||
|
||
expect(spectator.inject(ApiService).call).toHaveBeenCalledWith('virt.instance.device_add', ['my-instance', { | ||
dev_type: VirtualizationDeviceType.Nic, | ||
nic_type: VirtualizationNicType.Bridged, | ||
parent: 'Intel E1000', | ||
} as VirtualizationDevice]); | ||
expect(spectator.inject(VirtualizationDevicesStore).loadDevices).toHaveBeenCalled(); | ||
expect(spectator.inject(SnackbarService).success).toHaveBeenCalledWith('NIC was added'); | ||
}); | ||
}); |
114 changes: 114 additions & 0 deletions
114
...nents/all-instances/instance-details/instance-nics/add-nic-menu/add-nic-menu.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import { ChangeDetectionStrategy, Component, computed } from '@angular/core'; | ||
import { toSignal } from '@angular/core/rxjs-interop'; | ||
import { MatButton } from '@angular/material/button'; | ||
import { MatMenu, MatMenuItem, MatMenuTrigger } from '@angular/material/menu'; | ||
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; | ||
import { TranslateModule, TranslateService } from '@ngx-translate/core'; | ||
import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader'; | ||
import { Observable } from 'rxjs'; | ||
import { | ||
VirtualizationDeviceType, VirtualizationNicType, | ||
virtualizationNicTypeLabels, | ||
} from 'app/enums/virtualization.enum'; | ||
import { | ||
VirtualizationDevice, | ||
VirtualizationNic, | ||
} from 'app/interfaces/virtualization.interface'; | ||
import { AppLoaderService } from 'app/modules/loader/app-loader.service'; | ||
import { SnackbarService } from 'app/modules/snackbar/services/snackbar.service'; | ||
import { TestDirective } from 'app/modules/test-id/test.directive'; | ||
import { VirtualizationDevicesStore } from 'app/pages/virtualization/stores/virtualization-devices.store'; | ||
import { ErrorHandlerService } from 'app/services/error-handler.service'; | ||
import { ApiService } from 'app/services/websocket/api.service'; | ||
|
||
@UntilDestroy() | ||
@Component({ | ||
selector: 'ix-add-nic-menu', | ||
templateUrl: './add-nic-menu.component.html', | ||
styleUrls: ['./add-nic-menu.component.scss'], | ||
standalone: true, | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
imports: [ | ||
MatButton, | ||
MatMenu, | ||
MatMenuItem, | ||
TestDirective, | ||
TranslateModule, | ||
MatMenuTrigger, | ||
NgxSkeletonLoaderModule, | ||
], | ||
}) | ||
export class AddNicMenuComponent { | ||
private readonly bridgedChoices = toSignal(this.getNicChoices(VirtualizationNicType.Bridged), { initialValue: {} }); | ||
private readonly macVlanChoices = toSignal(this.getNicChoices(VirtualizationNicType.Macvlan), { initialValue: {} }); | ||
|
||
protected readonly bridgedNicTypeLabel = virtualizationNicTypeLabels.get(VirtualizationNicType.Bridged); | ||
protected readonly macVlanNicTypeLabel = virtualizationNicTypeLabels.get(VirtualizationNicType.Macvlan); | ||
|
||
protected readonly isLoadingDevices = this.deviceStore.isLoading; | ||
|
||
protected readonly availableBridgedNics = computed(() => { | ||
const choices = Object.values(this.bridgedChoices()); | ||
const existingItems = this.deviceStore.devices() | ||
.filter((device) => device.dev_type === VirtualizationDeviceType.Nic | ||
&& device.nic_type === VirtualizationNicType.Bridged) as VirtualizationNic[]; | ||
|
||
return choices.filter((nic) => !existingItems.find((device) => device.parent === nic)); | ||
}); | ||
|
||
protected readonly availableMacVlanNics = computed(() => { | ||
const choices = Object.values(this.macVlanChoices()); | ||
const existingItems = this.deviceStore.devices() | ||
.filter((device) => device.dev_type === VirtualizationDeviceType.Nic | ||
&& device.nic_type === VirtualizationNicType.Macvlan) as VirtualizationNic[]; | ||
|
||
return choices.filter((nic) => !existingItems.find((device) => device.parent === nic)); | ||
}); | ||
|
||
protected readonly hasNicsToAdd = computed(() => { | ||
return this.availableBridgedNics().length > 0 || Object.keys(this.availableMacVlanNics()).length > 0; | ||
}); | ||
|
||
constructor( | ||
private api: ApiService, | ||
private errorHandler: ErrorHandlerService, | ||
private loader: AppLoaderService, | ||
private snackbar: SnackbarService, | ||
private translate: TranslateService, | ||
private deviceStore: VirtualizationDevicesStore, | ||
) {} | ||
|
||
protected addBridgedNic(nic: string): void { | ||
this.addDevice({ | ||
dev_type: VirtualizationDeviceType.Nic, | ||
nic_type: VirtualizationNicType.Bridged, | ||
parent: nic, | ||
} as VirtualizationNic); | ||
} | ||
|
||
protected addMacVlanNic(nic: string): void { | ||
this.addDevice({ | ||
dev_type: VirtualizationDeviceType.Nic, | ||
nic_type: VirtualizationNicType.Macvlan, | ||
parent: nic, | ||
} as VirtualizationNic); | ||
} | ||
|
||
private getNicChoices(nicType: VirtualizationNicType): Observable<Record<string, string>> { | ||
return this.api.call('virt.device.nic_choices', [nicType]); | ||
} | ||
|
||
private addDevice(payload: VirtualizationDevice): void { | ||
const instanceId = this.deviceStore.selectedInstance().id; | ||
this.api.call('virt.instance.device_add', [instanceId, payload]) | ||
.pipe( | ||
this.loader.withLoader(), | ||
this.errorHandler.catchError(), | ||
untilDestroyed(this), | ||
) | ||
.subscribe(() => { | ||
this.snackbar.success(this.translate.instant('NIC was added')); | ||
this.deviceStore.loadDevices(); | ||
}); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...tion/components/all-instances/instance-details/instance-nics/instance-nics.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<mat-card class="card"> | ||
<mat-card-header> | ||
<h3 mat-card-title> | ||
{{ 'NIC' | translate }} | ||
</h3> | ||
|
||
@if (!hasPendingInterfaceChanges()) { | ||
<ix-add-nic-menu></ix-add-nic-menu> | ||
} | ||
</mat-card-header> | ||
|
||
<mat-card-content> | ||
@if (hasPendingInterfaceChanges()) { | ||
<p class="warning"> | ||
{{ 'NIC modifications are currently restricted due to pending network changes.' | translate }} | ||
</p> | ||
} | ||
|
||
@if (isLoadingDevices()) { | ||
<ngx-skeleton-loader></ngx-skeleton-loader> | ||
} @else { | ||
@for (device of shownDevices(); track device.name) { | ||
<div class="device"> | ||
<span>{{ getDeviceDescription(device) }}</span> | ||
|
||
@if (!hasPendingInterfaceChanges()) { | ||
<ix-device-actions-menu | ||
[device]="device" | ||
[showEdit]="false" | ||
></ix-device-actions-menu> | ||
} | ||
</div> | ||
} @empty { | ||
{{ 'No NICs added.' | translate }} | ||
} | ||
} | ||
</mat-card-content> | ||
</mat-card> |
5 changes: 5 additions & 0 deletions
5
...tion/components/all-instances/instance-details/instance-nics/instance-nics.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.device { | ||
align-items: center; | ||
display: flex; | ||
justify-content: space-between; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MAC VLAN