Skip to content

Commit e1c8522

Browse files
Fixed Re-Binding Issue
1 parent 805e085 commit e1c8522

File tree

2 files changed

+76
-43
lines changed

2 files changed

+76
-43
lines changed

a10vthunder-orchestrator/ImplementedStoreTypes/Ssl/Management.cs

Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,41 @@ protected internal virtual void Replace(ManagementJobConfiguration config, Inven
367367
{
368368
_logger.LogInformation($"Re-binding {virtualServiceBackups.Count} virtual service port bindings after certificate replacement.");
369369

370-
foreach (var backup in virtualServiceBackups)
371-
{
372-
_logger.LogTrace($"Re-binding {backup.TemplateType} template '{backup.TemplateName}' to virtual service '{backup.VirtualServerName}' port {backup.Port}");
373-
apiClient.BindTemplateToVirtualService(backup.VirtualServerName, backup.Port, backup.Protocol, backup.TemplateType, backup.TemplateName);
374-
}
370+
// 1. Group backups by virtual server + port + protocol
371+
var portBindings = virtualServiceBackups
372+
.GroupBy(b => new { b.VirtualServerName, b.Port, b.Protocol })
373+
.ToList();
374+
375+
// 2. For each unique port, build a single update with both template bindings
376+
foreach (var bindingGroup in portBindings)
377+
{
378+
var vsName = bindingGroup.Key.VirtualServerName;
379+
var port = bindingGroup.Key.Port;
380+
var protocol = bindingGroup.Key.Protocol;
381+
382+
var update = new VirtualServerPortUpdate
383+
{
384+
PortNumber = port,
385+
Protocol = protocol
386+
};
387+
388+
foreach (var b in bindingGroup)
389+
{
390+
if (b.TemplateType.Equals("server-ssl", StringComparison.OrdinalIgnoreCase))
391+
update.TemplateServerSsl = b.TemplateName;
392+
else if (b.TemplateType.Equals("client-ssl", StringComparison.OrdinalIgnoreCase))
393+
update.TemplateClientSsl = b.TemplateName;
394+
else
395+
throw new ArgumentException($"Unknown template type: {b.TemplateType}");
396+
}
397+
398+
var bindRequest = new VirtualServerPortUpdateRequest { Port = update };
399+
var requestJson = JsonConvert.SerializeObject(bindRequest);
400+
_logger.LogTrace($"Re-binding templates to VS={vsName} Port={port} Protocol={protocol} => {requestJson}");
401+
402+
apiClient.PutVirtualServerPort(vsName, port, protocol, requestJson);
403+
}
404+
375405
}
376406

377407
apiClient.WriteMemory();
@@ -388,8 +418,41 @@ protected internal virtual void Replace(ManagementJobConfiguration config, Inven
388418
{
389419
try
390420
{
391-
_logger.LogTrace($"Rolling back binding for virtual service '{backup.VirtualServerName}' port {backup.Port}");
392-
apiClient.BindTemplateToVirtualService(backup.VirtualServerName, backup.Port, backup.Protocol, backup.TemplateType, backup.OriginalTemplateName);
421+
_logger.LogTrace($"Rolling back binding for virtual service '{backup.VirtualServerName}' port {backup.Port}");
422+
// 1. Group backups by virtual server + port + protocol
423+
var portBindings = virtualServiceBackups
424+
.GroupBy(b => new { b.VirtualServerName, b.Port, b.Protocol })
425+
.ToList();
426+
427+
// 2. For each unique port, build a single update with both template bindings
428+
foreach (var bindingGroup in portBindings)
429+
{
430+
var vsName = bindingGroup.Key.VirtualServerName;
431+
var port = bindingGroup.Key.Port;
432+
var protocol = bindingGroup.Key.Protocol;
433+
434+
var update = new VirtualServerPortUpdate
435+
{
436+
PortNumber = port,
437+
Protocol = protocol
438+
};
439+
440+
foreach (var b in bindingGroup)
441+
{
442+
if (b.TemplateType.Equals("server-ssl", StringComparison.OrdinalIgnoreCase))
443+
update.TemplateServerSsl = b.TemplateName;
444+
else if (b.TemplateType.Equals("client-ssl", StringComparison.OrdinalIgnoreCase))
445+
update.TemplateClientSsl = b.TemplateName;
446+
else
447+
throw new ArgumentException($"Unknown template type: {b.TemplateType}");
448+
}
449+
450+
var bindRequest = new VirtualServerPortUpdateRequest { Port = update };
451+
var requestJson = JsonConvert.SerializeObject(bindRequest);
452+
_logger.LogTrace($"Re-binding templates to VS={vsName} Port={port} Protocol={protocol} => {requestJson}");
453+
454+
apiClient.PutVirtualServerPort(vsName, port, protocol, requestJson);
455+
}
393456
}
394457
catch (Exception rollbackEx)
395458
{

a10vthunder-orchestrator/api/ApiClient.cs

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -751,52 +751,22 @@ public void UnbindTemplateFromVirtualService(string virtualServerName, int port,
751751
}
752752
}
753753

754-
public void BindTemplateToVirtualService(string virtualServerName, int port, string protocol, string templateType, string templateName)
754+
public void PutVirtualServerPort(string virtualServerName, int port, string protocol, string jsonBody)
755755
{
756756
try
757757
{
758758
Logger.MethodEntry();
759-
Logger.LogTrace($"Binding {templateType} template '{templateName}' to virtual server: {virtualServerName}, port: {port}, protocol: {protocol}");
760-
761-
var bindRequest = new VirtualServerPortUpdateRequest();
762-
763-
if (templateType.Equals("server-ssl", StringComparison.OrdinalIgnoreCase))
764-
{
765-
bindRequest.Port = new VirtualServerPortUpdate
766-
{
767-
PortNumber = port,
768-
Protocol = protocol,
769-
TemplateServerSsl = templateName
770-
};
771-
}
772-
else if (templateType.Equals("client-ssl", StringComparison.OrdinalIgnoreCase))
773-
{
774-
bindRequest.Port = new VirtualServerPortUpdate
775-
{
776-
PortNumber = port,
777-
Protocol = protocol,
778-
TemplateClientSsl = templateName
779-
};
780-
}
781-
else
782-
{
783-
throw new ArgumentException($"Unsupported template type: {templateType}");
784-
}
785-
786-
var requestJson = JsonConvert.SerializeObject(bindRequest);
787-
Logger.LogTrace($"Bind request: {requestJson}");
788-
789-
ApiRequestString("PUT", $"/axapi/v3/slb/virtual-server/{virtualServerName}/port/{port}+{protocol}", "PUT", requestJson, false, true);
790-
791-
Logger.LogTrace($"Successfully bound {templateType} template '{templateName}' to virtual server {virtualServerName}");
759+
Logger.LogTrace($"PUT /axapi/v3/slb/virtual-server/{virtualServerName}/port/{port}+{protocol} BODY: {jsonBody}");
760+
ApiRequestString("PUT", $"/axapi/v3/slb/virtual-server/{virtualServerName}/port/{port}+{protocol}", "PUT", jsonBody, false, true);
792761
Logger.MethodExit();
793762
}
794763
catch (Exception ex)
795764
{
796-
Logger.LogError($"Error In BindTemplateToVirtualService: {LogHandler.FlattenException(ex)}");
765+
Logger.LogError($"Error in PutVirtualServerPort: {LogHandler.FlattenException(ex)}");
797766
throw;
798767
}
799-
}
768+
}
769+
800770

801771
#endregion
802772
}

0 commit comments

Comments
 (0)