From c086df48301ecce284cc523d6537f5204dd96cc0 Mon Sep 17 00:00:00 2001 From: Chris Marget Date: Thu, 26 Dec 2024 16:51:51 -0500 Subject: [PATCH 1/2] introduce `compatibility.HasDeviceOsImageDownloadTimeout` --- apstra/api_system_agent.go | 1 + apstra/api_system_agent_test.go | 4 ++++ apstra/client.go | 3 +++ apstra/compatibility/compatibility.go | 1 + apstra/compatibility/constraints.go | 7 +++++-- 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/apstra/api_system_agent.go b/apstra/api_system_agent.go index 1100fa13..86332061 100644 --- a/apstra/api_system_agent.go +++ b/apstra/api_system_agent.go @@ -12,6 +12,7 @@ import ( const apiUrlSystemAgentManagerConfig = "/api/system-agent/manager-config" type SystemAgentManagerConfig struct { + DeviceOsImageDownloadTimeout *int `json:"device_os_image_download_timeout"` // introduced in and required by 5.1.0 (1-2700) SkipRevertToPristineOnUninstall bool `json:"skip_revert_to_pristine_on_uninstall"` SkipPristineValidation bool `json:"skip_pristine_validation"` SkipInterfaceShutdownOnUpgrade bool `json:"skip_interface_shutdown_on_upgrade"` diff --git a/apstra/api_system_agent_test.go b/apstra/api_system_agent_test.go index 5d48f56f..0f4213ac 100644 --- a/apstra/api_system_agent_test.go +++ b/apstra/api_system_agent_test.go @@ -10,6 +10,7 @@ package apstra import ( "context" "log" + "math/rand/v2" "testing" "github.com/Juniper/apstra-go-sdk/apstra/compatibility" @@ -35,6 +36,9 @@ func TestGetSetSystemAgentManagerConfiguration(t *testing.T) { SkipPristineValidation: !mgrCfg.SkipPristineValidation, SkipInterfaceShutdownOnUpgrade: !mgrCfg.SkipInterfaceShutdownOnUpgrade, } + if compatibility.HasDeviceOsImageDownloadTimeout.Check(client.client.apiVersion) { + testCfg.DeviceOsImageDownloadTimeout = toPtr(rand.IntN(2700) + 1) + } // set new config log.Printf("testing SetSystemAgentManagerConfig() against %s %s (%s)", client.clientType, clientName, client.client.ApiVersion()) diff --git a/apstra/client.go b/apstra/client.go index b84d2481..f305aa35 100644 --- a/apstra/client.go +++ b/apstra/client.go @@ -1674,6 +1674,9 @@ func (o *Client) GetSystemAgentManagerConfig(ctx context.Context) (*SystemAgentM // SetSystemAgentManagerConfig uses a *SystemAgentManagerConfig object to configure the Advanced Settings // found on the Managed Devices page of the Web UI. func (o *Client) SetSystemAgentManagerConfig(ctx context.Context, cfg *SystemAgentManagerConfig) error { + if compatibility.HasDeviceOsImageDownloadTimeout.Check(o.apiVersion) != (cfg.DeviceOsImageDownloadTimeout != nil) { + return fmt.Errorf("DeviceOsImageDownloadTimeout is required with apstra %s, and must not be used with other versions", compatibility.HasDeviceOsImageDownloadTimeout) + } if !compatibility.SystemManagerHasSkipInterfaceShutdownOnUpgrade.Check(o.apiVersion) && cfg.SkipInterfaceShutdownOnUpgrade { return fmt.Errorf("SkipInterfaceShutdownOnUpgrade may only be used with apstra %s", compatibility.SystemManagerHasSkipInterfaceShutdownOnUpgrade) } diff --git a/apstra/compatibility/compatibility.go b/apstra/compatibility/compatibility.go index 733c272f..dc88492e 100644 --- a/apstra/compatibility/compatibility.go +++ b/apstra/compatibility/compatibility.go @@ -15,6 +15,7 @@ const ( apstra422 = "4.2.2" apstra500 = "5.0.0" apstra501 = "5.0.1" + apstra510 = "5.1.0" ) var ( diff --git a/apstra/compatibility/constraints.go b/apstra/compatibility/constraints.go index 47b8ae2d..9c6bceed 100644 --- a/apstra/compatibility/constraints.go +++ b/apstra/compatibility/constraints.go @@ -17,11 +17,14 @@ var ( BpHasVirtualNetworkPolicyNode = Constraint{ constraints: version.MustConstraints(version.NewConstraint("<=" + apstra420)), } + EmptyVnBindingsOk = Constraint{ + constraints: version.MustConstraints(version.NewConstraint(">=" + apstra500)), + } FabricSettingsApiOk = Constraint{ constraints: version.MustConstraints(version.NewConstraint(">=" + apstra421)), } - EmptyVnBindingsOk = Constraint{ - constraints: version.MustConstraints(version.NewConstraint(">=" + apstra500)), + HasDeviceOsImageDownloadTimeout = Constraint{ + constraints: version.MustConstraints(version.NewConstraint(">=" + apstra510)), } IbaDashboardSupported = Constraint{ constraints: version.MustConstraints(version.NewConstraint(">=" + apstra500)), From d0ef7e59e79ce41b0c673853b3fa0e96f14f122d Mon Sep 17 00:00:00 2001 From: Chris Marget Date: Thu, 26 Dec 2024 23:46:43 -0500 Subject: [PATCH 2/2] add `omitempty` to new struct field --- apstra/api_system_agent.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apstra/api_system_agent.go b/apstra/api_system_agent.go index 86332061..e6e815a8 100644 --- a/apstra/api_system_agent.go +++ b/apstra/api_system_agent.go @@ -12,7 +12,7 @@ import ( const apiUrlSystemAgentManagerConfig = "/api/system-agent/manager-config" type SystemAgentManagerConfig struct { - DeviceOsImageDownloadTimeout *int `json:"device_os_image_download_timeout"` // introduced in and required by 5.1.0 (1-2700) + DeviceOsImageDownloadTimeout *int `json:"device_os_image_download_timeout,omitempty"` // introduced in and required by 5.1.0 (1-2700) SkipRevertToPristineOnUninstall bool `json:"skip_revert_to_pristine_on_uninstall"` SkipPristineValidation bool `json:"skip_pristine_validation"` SkipInterfaceShutdownOnUpgrade bool `json:"skip_interface_shutdown_on_upgrade"`