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

Add missing settings for nodes/templates #1541

Merged
merged 5 commits into from
Feb 5, 2025
Merged
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
30 changes: 29 additions & 1 deletion src/app/cartography/models/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ export class Properties {
headless: boolean;
linked_clone: boolean;
on_close: string;
aux_type: boolean;
aux: number;
aux_type: boolean;
ram: number;
system_id: string;
npe?: string;
midplane?: string;
nvram: number;
image: string;
usage: string;
use_any_adapter: boolean;
vmname: string;
Expand Down Expand Up @@ -48,16 +52,40 @@ export class Properties {
kernel_image: string;
kernel_image_md5sum?: any;
mac_address: string;
mac_addr: string;
options: string;
platform: string;
chassis?: string;
iomem?: number;
disk0: number;
disk1: number;
idlepc: string;
idlemax: number;
idlesleep: number;
exec_area: number;
mmap: boolean;
sparsemem: boolean;
auto_delete_disks: boolean;
process_priority: string;
qemu_path: string;
environment: string;
extra_hosts: string;
start_command: string;
replicate_network_connection_state: boolean;
memory: number;
tpm: boolean;
uefi: boolean;
slot0?: string;
slot1?: string;
slot2?: string;
slot3?: string;
slot4?: string;
slot5?: string;
slot6?: string;
slot7?: string;
wic0?: string;
wic1?: string;
wic2?: string;
}

export class Node {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,32 +109,24 @@ <h1 class="col">New IOS router template</h1>
</mat-step>

<mat-step label="Network adapters">
<!-- <div *ngIf="chassis[iosNameForm.get('platform').value]">
<div *ngFor="let index of [0,1,2,3,4,5,6,7]">
<mat-select
placeholder="Slot {{index}}"
[(ngModel)]="networkAdaptersForTemplate[index]"
[ngModelOptions]="{standalone: true}"
*ngIf="networkAdapters[iosNameForm.get('chassis').value] && networkAdapters[iosNameForm.get('chassis').value][index]">
<mat-option *ngFor="let option of networkAdapters[iosNameForm.get('chassis').value][index]" [value]="option">
{{option}}
</mat-option>
</mat-select>
</div>
</div> -->
<div *ngIf="selectedPlatform">
<div *ngFor="let index of [0, 1, 2, 3, 4, 5, 6, 7]">
<div *ngIf="iosNameForm.get('platform').value">
<div *ngFor="let index of [0, 1, 2, 3, 4, 5, 6]">
<mat-select
placeholder="Slot {{ index }}"
[(ngModel)]="networkAdaptersForTemplate[index]"
[ngModelOptions]="{ standalone: true }"
*ngIf="
networkAdaptersForPlatform[iosNameForm.get('platform').value] &&
networkAdaptersForPlatform[iosNameForm.get('platform').value][index]
"
*ngIf="adapterMatrix[iosNameForm.get('platform').value][iosNameForm.get('chassis').value || '']
&& adapterMatrix[iosNameForm.get('platform').value][iosNameForm.get('chassis').value || ''][index]"
>
<mat-option
*ngFor="let option of networkAdaptersForPlatform[iosNameForm.get('platform').value][index]"
*ngIf="adapterMatrix[iosNameForm.get('platform').value][iosNameForm.get('chassis').value|| ''][index].length > 1 &&
!adapterMatrix[iosNameForm.get('platform').value][iosNameForm.get('chassis').value|| ''][index][0].startsWith('C7200')"
[value]=""
>
{{ "" }}
</mat-option>
<mat-option
*ngFor="let option of adapterMatrix[iosNameForm.get('platform').value][iosNameForm.get('chassis').value || ''][index]"
[value]="option"
>
{{ option }}
Expand All @@ -144,33 +136,33 @@ <h1 class="col">New IOS router template</h1>
</div>
</mat-step>

<mat-step label="WIC modules">
<div *ngIf="iosNameForm.get('platform').value">
<div *ngFor="let index of [0, 1, 2, 3]">
<mat-select
placeholder="WIC {{ index }}"
[(ngModel)]="networkModulesForTemplate[index]"
[ngModelOptions]="{ standalone: true }"
*ngIf="
networkModules[iosNameForm.get('platform').value] &&
networkModules[iosNameForm.get('platform').value][index]
"
<mat-step label="WIC modules" *ngIf="iosNameForm.get('platform').value && wicMatrix[iosNameForm.get('platform').value]">
<div *ngFor="let index of [0, 1, 2]">
<mat-select
placeholder="WIC {{ index }}"
[(ngModel)]="wicsForTemplate[index]"
[ngModelOptions]="{ standalone: true }"
*ngIf="wicMatrix[iosNameForm.get('platform').value] && wicMatrix[iosNameForm.get('platform').value][index]"
>
<mat-option [value]="">
{{ "" }}
</mat-option>
<mat-option
*ngFor="let option of wicMatrix[iosNameForm.get('platform').value][index]"
[value]="option"
>
<mat-option
*ngFor="let option of networkModules[iosNameForm.get('platform').value][index]"
[value]="option"
>
{{ option }}
</mat-option>
</mat-select>
</div>
{{ option }}
</mat-option>
</mat-select>
</div>
</mat-step>

<mat-step label="Idle-PC">
<mat-form-field class="form-field">
<input matInput type="text" [(ngModel)]="iosTemplate.idlepc" placeholder="Idle-PC" />
</mat-form-field>
<form [formGroup]="iosIdlePCForm">
<mat-form-field class="form-field">
<input matInput type="text" formControlName="idlepc" [(ngModel)]="iosTemplate.idlepc" placeholder="Idle-PC" />
</mat-form-field>
</form>
</mat-step>
</mat-vertical-stepper>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,19 @@ export class AddIosTemplateComponent implements OnInit, OnDestroy {
iosImageForm: UntypedFormGroup;
iosNameForm: UntypedFormGroup;
iosMemoryForm: UntypedFormGroup;
iosIdlePCForm: UntypedFormGroup;
selectedPlatform: string;

networkAdaptersForTemplate: string[] = [];
networkModulesForTemplate: string[] = [];

iosImages: IosImage[] = [];
platforms: string[] = [];
platformsWithEtherSwitchRouterOption = {};
platformsWithChassis = {};
chassis = {};
defaultRam = {};
defaultNvram = {};
networkAdapters = {};
networkAdaptersForPlatform = {};
networkModules = {};
networkAdaptersForTemplate: string[] = [];
wicsForTemplate: string[] = [];
adapterMatrix = {};
wicMatrix = {};

ciscoUrl: string = 'https://cfn.cloudapps.cisco.com/ITDIT/CFN/jsp/SearchBySoftware.jsp';
uploader: FileUploader;
Expand Down Expand Up @@ -82,6 +80,10 @@ export class AddIosTemplateComponent implements OnInit, OnDestroy {
this.iosMemoryForm = this.formBuilder.group({
memory: new UntypedFormControl(null, [Validators.required]),
});

this.iosIdlePCForm = this.formBuilder.group({
idlepc: new UntypedFormControl(null, [Validators.pattern(this.iosConfigurationService.getIdlepcRegex())]),
});
}

ngOnInit() {
Expand Down Expand Up @@ -120,19 +122,31 @@ export class AddIosTemplateComponent implements OnInit, OnDestroy {

this.templateMocksService.getIosTemplate().subscribe((iosTemplate: IosTemplate) => {
this.iosTemplate = iosTemplate;

this.networkModules = this.iosConfigurationService.getNetworkModules();
this.networkAdaptersForPlatform = this.iosConfigurationService.getNetworkAdaptersForPlatform();
this.networkAdapters = this.iosConfigurationService.getNetworkAdapters();
this.platforms = this.iosConfigurationService.getAvailablePlatforms();
this.platformsWithEtherSwitchRouterOption = this.iosConfigurationService.getPlatformsWithEtherSwitchRouterOption();
this.platformsWithChassis = this.iosConfigurationService.getPlatformsWithChassis();
this.chassis = this.iosConfigurationService.getChassis();
this.defaultRam = this.iosConfigurationService.getDefaultRamSettings();
this.adapterMatrix = this.iosConfigurationService.getAdapterMatrix();
this.wicMatrix = this.iosConfigurationService.getWicMatrix();
});
});
}

fillDefaultSlots() {

console.log("Fill default slots");
if (this.iosNameForm.get('platform').value) {
for (let i = 0; i <= 6; i++) {
let adapters = this.adapterMatrix[this.iosNameForm.get('platform').value][this.iosNameForm.get('chassis').value || ''][i];
if (adapters && (adapters.length === 1 || adapters[0].startsWith('C7200'))) {
console.log("Set default adapter for slot" + i + " to " + adapters[0]);
this.networkAdaptersForTemplate[i] = adapters[0];
}
}
}
}

setControllerType(controllerType: string) {
if (controllerType === 'local') {
this.isLocalComputerChosen = true;
Expand Down Expand Up @@ -166,6 +180,7 @@ export class AddIosTemplateComponent implements OnInit, OnDestroy {
if (
!this.iosImageForm.invalid &&
!this.iosMemoryForm.invalid &&
!this.iosIdlePCForm.invalid &&
this.iosNameForm.get('templateName').value &&
this.iosNameForm.get('platform').value
) {
Expand All @@ -184,7 +199,7 @@ export class AddIosTemplateComponent implements OnInit, OnDestroy {
}

if (this.networkAdaptersForTemplate.length > 0) this.completeAdaptersData();
if (this.networkModulesForTemplate.length > 0) this.completeModulesData();
if (this.wicsForTemplate.length > 0) this.completeWicsData();
this.iosTemplate.compute_id = 'local';

this.iosService.addTemplate(this.controller, this.iosTemplate).subscribe((template: IosTemplate) => {
Expand All @@ -196,44 +211,25 @@ export class AddIosTemplateComponent implements OnInit, OnDestroy {
}

completeAdaptersData() {
if (this.chassis[this.iosTemplate.platform]) {
if (Object.keys(this.networkAdapters[this.iosTemplate.chassis])) {
for (let i = 0; i < Object.keys(this.networkAdapters[this.iosTemplate.chassis]).length; i++) {
if (!this.networkAdaptersForTemplate[i]) this.networkAdaptersForTemplate[i] = '';
}
}
} else {
if (this.networkAdaptersForPlatform[this.iosNameForm.get('platform').value]) {
for (
let i = 0;
i < Object.keys(this.networkAdaptersForPlatform[this.iosNameForm.get('platform').value]).length;
i++
) {
if (!this.networkAdaptersForTemplate[i]) this.networkAdaptersForTemplate[i] = '';
}
for (let i = 0; i <= 6; i++) {
if (this.adapterMatrix[this.iosTemplate.platform][this.iosTemplate.chassis || ''][i]) {
if (this.networkAdaptersForTemplate[i] === undefined)
this.iosTemplate[`slot${i}`] = ""
else
this.iosTemplate[`slot${i}`] = this.networkAdaptersForTemplate[i];
}
}

if (this.networkAdaptersForTemplate[0]) this.iosTemplate.slot0 = this.networkAdaptersForTemplate[0];
if (this.networkAdaptersForTemplate[1]) this.iosTemplate.slot1 = this.networkAdaptersForTemplate[1];
if (this.networkAdaptersForTemplate[2]) this.iosTemplate.slot2 = this.networkAdaptersForTemplate[2];
if (this.networkAdaptersForTemplate[3]) this.iosTemplate.slot3 = this.networkAdaptersForTemplate[3];
if (this.networkAdaptersForTemplate[4]) this.iosTemplate.slot4 = this.networkAdaptersForTemplate[4];
if (this.networkAdaptersForTemplate[5]) this.iosTemplate.slot5 = this.networkAdaptersForTemplate[5];
if (this.networkAdaptersForTemplate[6]) this.iosTemplate.slot6 = this.networkAdaptersForTemplate[6];
if (this.networkAdaptersForTemplate[7]) this.iosTemplate.slot7 = this.networkAdaptersForTemplate[7];
}

completeModulesData() {
if (Object.keys(this.networkModules[this.iosTemplate.platform])) {
for (let i = 0; i < Object.keys(this.networkModules[this.iosTemplate.platform]).length; i++) {
if (!this.networkModulesForTemplate[i]) this.networkModulesForTemplate[i] = '';
completeWicsData() {
for (let i = 0; i <= 3; i++) {
if (this.wicMatrix[this.iosTemplate.platform][i]) {
if (this.wicsForTemplate[i] === undefined)
this.iosTemplate[`wic${i}`] = ""
else
this.iosTemplate[`wic${i}`] = this.wicsForTemplate[i];
}
}

if (this.networkModulesForTemplate[0]) this.iosTemplate.wic0 = this.networkModulesForTemplate[0];
if (this.networkModulesForTemplate[1]) this.iosTemplate.wic1 = this.networkModulesForTemplate[1];
if (this.networkModulesForTemplate[2]) this.iosTemplate.wic2 = this.networkModulesForTemplate[2];
}

goBack() {
Expand All @@ -252,25 +248,31 @@ export class AddIosTemplateComponent implements OnInit, OnDestroy {
this.selectedPlatform = name;
}

if (name === 'c1700') {
this.iosNameForm.controls['chassis'].setValue('1720');
if (name === 'c3620' || name === 'c3640' || name === 'c3660')
this.iosNameForm.controls['chassis'].setValue(name.substring(1));
else if (name === 'c1700') {
this.iosNameForm.controls['chassis'].setValue('1760');
} else if (name === 'c2600') {
this.iosNameForm.controls['chassis'].setValue('2610');
this.iosNameForm.controls['chassis'].setValue('2651XM');
} else {
this.iosNameForm.controls['chassis'].setValue('');
}

this.iosMemoryForm.controls['memory'].setValue(this.defaultRam[name]);
this.iosMemoryForm.controls['memory'].setValue(this.defaultRam[this.selectedPlatform]);
this.fillDefaultSlots();
}

onPlatformChosen() {
this.iosTemplate.chassis = '';
this.networkAdaptersForTemplate = [];
this.networkModulesForTemplate = [];
this.wicsForTemplate = [];
if (!this.chassis[this.iosNameForm.get('platform').value])
this.fillDefaultSlots();
}

onChassisChosen() {
this.networkAdaptersForTemplate = [];
if (this.chassis[this.iosNameForm.get('platform').value])
this.fillDefaultSlots();
}

cancelUploading() {
Expand Down
Loading
Loading