Skip to content

Commit

Permalink
Add missing adapter and mac address settings for Qemu and Docker nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
grossmj committed Feb 5, 2025
1 parent 10c1461 commit 55bc693
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 50 deletions.
1 change: 1 addition & 0 deletions src/app/cartography/models/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export class Properties {
qemu_path: string;
environment: string;
extra_hosts: string;
start_command: string;
replicate_network_connection_state: boolean;
memory: number;
tpm: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,27 @@ <h1 mat-dialog-title>Configurator for node {{ name }}</h1>
</mat-form-field>

<mat-form-field class="form-field">
<input formControlName="memory" matInput type="number" min="1" [(ngModel)]="node.properties.memory" placeholder="Maximum memory">
<input
matInput
formControlName="mac_address"
type="text"
[(ngModel)]="node.properties.mac_address"
placeholder="Base MAC"
/>
</mat-form-field>

<mat-form-field class="form-field">
<input formControlName="memory" matInput type="number" min="0" [(ngModel)]="node.properties.memory" placeholder="Maximum memory">
<span matSuffix>MB</span>
</mat-form-field>

<mat-form-field class="form-field">
<input formControlName="cpus" matInput type="number" min="1" [(ngModel)]="node.properties.cpus" placeholder="Maximum CPUs">
<input formControlName="cpus" matInput type="number" min="0" [(ngModel)]="node.properties.cpus" placeholder="Maximum CPUs">
</mat-form-field>

<button mat-button class="form-field" (click)="configureCustomAdapters()">
Configure custom adapters
</button>
<!-- <button mat-button class="form-field" (click)="configureCustomAdapters()">-->
<!-- Configure custom adapters-->
<!-- </button>-->

<mat-form-field class="select">
<mat-select
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class ConfiguratorDialogDockerComponent implements OnInit {
this.generalSettingsForm = this.formBuilder.group({
name: new UntypedFormControl('', Validators.required),
adapter: new UntypedFormControl('', Validators.required),
mac_address: new UntypedFormControl('', Validators.pattern(this.dockerConfigurationService.getMacAddrRegex())),
memory: new UntypedFormControl('', nonNegativeValidator.get),
cpus: new UntypedFormControl('', nonNegativeValidator.get),
startCommand: new UntypedFormControl(''),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,43 @@ <h1 mat-dialog-title>Configurator for Qemu VM {{ name }}</h1>
</mat-tab>
<mat-tab label="Network">
<br />
<br /><mat-checkbox [(ngModel)]="node.properties.replicate_network_connection_state">
<mat-form-field class="form-field">
<input
matInput
min=0
type="number"
[(ngModel)]="node.properties.adapters"
placeholder="Adapters"
/>
</mat-form-field>
<form [formGroup]="networkSettingsForm">
<mat-form-field class="form-field">
<input
matInput
formControlName="mac_address"
type="text"
[(ngModel)]="node.properties.mac_address"
placeholder="Base MAC"
/>
</mat-form-field>
</form>
<mat-select placeholder="Type" [(ngModel)]="node.properties.adapter_type">
<mat-option *ngFor="let type of networkTypes" [value]="type.value">
{{ type.name }} ({{ type.value }})
</mat-option>
</mat-select>
<!-- <button mat-button class="form-field" (click)="setCustomAdaptersConfiguratorState(true)">-->
<!-- Configure custom adapters-->
<!-- </button>-->
<br /><br /><mat-checkbox [(ngModel)]="node.properties.replicate_network_connection_state">
Replicate network connection state
</mat-checkbox>
<app-custom-adapters-table
#customAdapters
[networkTypes]="networkTypes"
[displayedColumns]="displayedColumns"
[adapters]="node.ports"
></app-custom-adapters-table>
<!-- <app-custom-adapters-table-->
<!-- #customAdapters-->
<!-- [networkTypes]="networkTypes"-->
<!-- [displayedColumns]="displayedColumns"-->
<!-- [adapters]="node.ports"-->
<!-- ></app-custom-adapters-table>-->
</mat-tab>
<mat-tab label="Advanced">
<mat-card>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class ConfiguratorDialogQemuComponent implements OnInit {
node: Node;
name: string;
generalSettingsForm: UntypedFormGroup;
networkSettingsForm: UntypedFormGroup;
consoleTypes: string[] = [];
onCloseOptions = [];
bootPriorities = [];
Expand Down Expand Up @@ -54,6 +55,10 @@ export class ConfiguratorDialogQemuComponent implements OnInit {
name: new UntypedFormControl('', Validators.required),
ram: new UntypedFormControl('', Validators.required),
});

this.networkSettingsForm = this.formBuilder.group({
mac_address: new UntypedFormControl('', Validators.pattern(this.qemuConfigurationService.getMacAddrRegex())),
});
}

ngOnInit() {
Expand Down Expand Up @@ -103,16 +108,16 @@ export class ConfiguratorDialogQemuComponent implements OnInit {
}

onSaveClick() {
if (this.generalSettingsForm.valid) {
this.node.custom_adapters = [];
this.customAdapters.adapters.forEach((n) => {
this.node.custom_adapters.push({
adapter_number: n.adapter_number,
adapter_type: n.adapter_type,
});
});

this.node.properties.adapters = this.node.custom_adapters.length;
if (this.generalSettingsForm.valid && this.networkSettingsForm.valid) {
// this.node.custom_adapters = [];
// this.customAdapters.adapters.forEach((n) => {
// this.node.custom_adapters.push({
// adapter_number: n.adapter_number,
// adapter_type: n.adapter_type,
// });
// });
//
// this.node.properties.adapters = this.node.custom_adapters.length;

this.nodeService.updateNodeWithCustomAdapters(this.controller, this.node).subscribe(() => {
this.toasterService.success(`Node ${this.node.name} updated.`);
Expand Down
4 changes: 4 additions & 0 deletions src/app/services/docker-configuration.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ export class DockerConfigurationService {

return consoleResolutions;
}

getMacAddrRegex() {
return /^([0-9a-fA-F]{2}[:]){5}([0-9a-fA-F]{2})$/;
}
}
32 changes: 4 additions & 28 deletions src/app/services/qemu-configuration.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,34 +76,6 @@ export class QemuConfigurationService {
{ value: 'vmxnet3', name: 'VMWare Paravirtualized Ethernet v3' },
];

// let networkTypes = [
// 'e1000',
// 'e1000-82544gc',
// 'e1000-82545em',
// 'e1000e',
// 'rocker',
// 'Intel Gigabit Ethernet',
// 'i82550',
// 'i82551',
// 'i82557a',
// 'i82557b',
// 'i82557c',
// 'i82558a',
// 'i82558b',
// 'i82559a',
// 'i82559b',
// 'i82559c',
// 'i82559er',
// 'i82562',
// 'i82801',
// 'ne2k_pci',
// 'pcnet',
// 'rtl8139',
// 'virtio',
// 'virtio-net-pci',
// 'vmxnet3',
// ];

return networkTypes;
}

Expand Down Expand Up @@ -146,4 +118,8 @@ export class QemuConfigurationService {

return priorities;
}

getMacAddrRegex() {
return /^([0-9a-fA-F]{2}[:]){5}([0-9a-fA-F]{2})$/;
}
}

0 comments on commit 55bc693

Please sign in to comment.