From 2a225b9539d7746c4bd014e5eece98b6470f8a59 Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Tue, 7 Jul 2026 17:23:48 +0200 Subject: [PATCH] ref 2979. Generar instrucciones de deploy imagen actualizado. --- .../deploy-image/deploy-image.component.ts | 106 +++++++++++++++++- 1 file changed, 105 insertions(+), 1 deletion(-) diff --git a/ogWebconsole/src/app/components/groups/components/client-main-view/deploy-image/deploy-image.component.ts b/ogWebconsole/src/app/components/groups/components/client-main-view/deploy-image/deploy-image.component.ts index 8fcbf2a..0faf0fd 100644 --- a/ogWebconsole/src/app/components/groups/components/client-main-view/deploy-image/deploy-image.component.ts +++ b/ogWebconsole/src/app/components/groups/components/client-main-view/deploy-image/deploy-image.component.ts @@ -217,6 +217,17 @@ export class DeployImageComponent implements OnInit { this.filteredPartitions = fullClientData.partitions; this.selectedRepository = fullClientData.repository ?? null; + if (this.selectedRepository?.uuid) { + this.http.get(`${this.baseUrl}/image-repositories/${this.selectedRepository.uuid}`).subscribe( + (repository: any) => { + this.selectedRepository = repository; + }, + (error) => { + console.error(this.translate.instant('errorLoadingRepositories1'), error); + } + ); + } + if (fullClientData.partitions) { this.filteredPartitions = fullClientData.partitions.filter((partition: any) => { return partition.partitionNumber !== 0; @@ -586,9 +597,102 @@ export class DeployImageComponent implements OnInit { }); } + generateOgInstructions() { this.showInstructions = true; - this.ogInstructions = `og-deploy-image --image ${this.selectedImage.name} --partition ${this.selectedPartition?.partitionNumber || 1} --method ${this.selectedMethod}`; + this.ogInstructions = this.imageType === 'git' + ? this.buildGitOgInstructions() + : this.buildMonolithicOgInstructions(); + } + + private getTargetClients(): any[] { + if (this.selectedClients.length) { + return this.selectedClients; + } + return this.selectedModelClient ? [this.selectedModelClient] : []; + } + + + private getProto(method: string | null): string { + switch (method) { + case 'uftp-direct': + case 'udpcast-direct': + return 'MULTICAST-DIRECT'; + case 'multicast': + case 'uftp': + case 'udpcast': + return 'MULTICAST'; + case 'unicast-direct': + return 'UNICAST-DIRECT'; + case 'unicast': + return 'UNICAST'; + case 'p2p': + return 'TORRENT'; + default: + return (method || '').toUpperCase(); + } + } + + private getProtoOpt(method: string | null): string { + if (method === 'udpcast' || method === 'uftp' || method === 'udpcast-direct') { + const mcastMode = `${this.mcastMode}-duplex`; + const mcastSpeed = `${this.mcastSpeed}M`; + return `${this.mcastPort}:${mcastMode}:${this.mcastIp}:${mcastSpeed}:${this.mcastMaxClients}:${this.mcastMaxTime}`; + } + if (method === 'p2p') { + return `${this.p2pMode}:${this.p2pTime}`; + } + return ''; + } + + private buildMonolithicOgInstructions(): string { + const method = this.selectedMethod; + const proto = this.getProto(method); + const protoOpt = this.getProtoOpt(method); + + const disk = String(this.selectedPartition?.diskNumber || 1); + const par = String(this.selectedPartition?.partitionNumber || 1); + const imgname = this.selectedImage?.name || ''; + const repo = this.selectedRepository?.ip || ''; + + const effectiveDeployMode = this.isDirectMethod() ? 'deploy' : this.deployMode; + const isCache = effectiveDeployMode === 'update-cache'; + + const restaurarArgs = [disk, par, imgname, repo, proto, protoOpt].filter(a => a !== '').join(' '); + const scriptName = isCache ? 'ActualizarCache' : 'RestaurarImagen'; + + const innerCommand = isCache + ? ['updateCache', repo, `/${imgname}.img`, proto, protoOpt].filter(a => a !== '').join(' ') + : ['deployImage', repo, imgname, disk, par, proto, protoOpt].filter(a => a !== '').join(' '); + + const clients = this.getTargetClients(); + const targets = clients.length ? clients : [{ name: '', ip: '' }]; + + return targets.map(client => + `# Cliente ${client.name || client.ip} (${client.ip || ''})\n` + + `${scriptName} ${restaurarArgs}\n` + + ` ↳ ${innerCommand}` + ).join('\n\n'); + } + + private buildGitOgInstructions(): string { + const disk = String(this.selectedPartition?.diskNumber || 1); + const par = String(this.selectedPartition?.partitionNumber || 1); + const repo = this.selectedRepository?.ip || ''; + const imageName = this.selectedGitRepository || ''; + const branch = this.selectedBranch || ''; + const commit = this.selectedCommit?.hexsha || ''; + + const command = + `RestaurarImagenGit --disk ${disk} --partition ${par} --repository ${repo} ` + + `--image-name ${imageName} --branch ${branch} --commit ${commit}`; + + const clients = this.getTargetClients(); + const targets = clients.length ? clients : [{ name: '', ip: '' }]; + + return targets.map(client => + `# Cliente ${client.name || client.ip} (${client.ip || ''})\n${command}` + ).join('\n\n'); }