Skip to content

Commit

Permalink
rename utils.Known() to utils.HasValue()
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismarget-j committed Jul 13, 2024
1 parent 69dd8aa commit 68ab227
Show file tree
Hide file tree
Showing 20 changed files with 109 additions and 109 deletions.
2 changes: 1 addition & 1 deletion apstra/apstra_validator/different_from_values.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (o DifferentFromValuesValidator) MarkdownDescription(_ context.Context) str

func (o DifferentFromValuesValidator) Validate(ctx context.Context, req DifferentFromValuesValidatorRequest, resp *DifferentFromValuesValidatorResponse) {
// If attribute configuration isn't known, there is nothing else to validate
if !utils.Known(req.ConfigValue) {
if !utils.HasValue(req.ConfigValue) {
return
}

Expand Down
50 changes: 25 additions & 25 deletions apstra/blueprint/blueprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -648,56 +648,56 @@ func (o *Blueprint) SetName(ctx context.Context, bpClient *apstra.TwoStageL3Clos
func (o Blueprint) VersionConstraints() apiversions.Constraints {
var response apiversions.Constraints

if utils.Known(o.FabricAddressing) {
if utils.HasValue(o.FabricAddressing) {
response.AddAttributeConstraints(apiversions.AttributeConstraint{
Path: path.Root("fabric_addressing"),
Constraints: apiversions.Ge411,
})
}

if utils.Known(o.DefaultSviL3Mtu) {
if utils.HasValue(o.DefaultSviL3Mtu) {
response.AddAttributeConstraints(apiversions.AttributeConstraint{
Path: path.Root("default_svi_l3_mtu"),
Constraints: apiversions.Ge420,
})
}

if utils.Known(o.FabricMtu) {
if utils.HasValue(o.FabricMtu) {
response.AddAttributeConstraints(apiversions.AttributeConstraint{
Path: path.Root("fabric_mtu"),
Constraints: apiversions.Ge420,
})
}

if utils.Known(o.JunosEvpnMaxNexthopAndInterfaceNumber) {
if utils.HasValue(o.JunosEvpnMaxNexthopAndInterfaceNumber) {
response.AddAttributeConstraints(apiversions.AttributeConstraint{
Path: path.Root("junos_evpn_max_nexthop_and_interface_number"),
Constraints: apiversions.Ge420,
})
}

if utils.Known(o.JunosEvpnRoutingInstanceModeMacVrf) {
if utils.HasValue(o.JunosEvpnRoutingInstanceModeMacVrf) {
response.AddAttributeConstraints(apiversions.AttributeConstraint{
Path: path.Root("junos_evpn_routing_instance_mode_mac_vrf"),
Constraints: apiversions.Ge420,
})
}

if utils.Known(o.JunosExOverlayEcmp) {
if utils.HasValue(o.JunosExOverlayEcmp) {
response.AddAttributeConstraints(apiversions.AttributeConstraint{
Path: path.Root("junos_ex_overlay_ecmp"),
Constraints: apiversions.Ge420,
})
}

if utils.Known(o.JunosGracefulRestart) {
if utils.HasValue(o.JunosGracefulRestart) {
response.AddAttributeConstraints(apiversions.AttributeConstraint{
Path: path.Root("junos_graceful_restart"),
Constraints: apiversions.Ge420,
})
}

if utils.Known(o.OptimizeRoutingZoneFootprint) {
if utils.HasValue(o.OptimizeRoutingZoneFootprint) {
response.AddAttributeConstraints(apiversions.AttributeConstraint{
Path: path.Root("optimize_routing_zone_footprint"),
Constraints: apiversions.Ge420,
Expand Down Expand Up @@ -781,7 +781,7 @@ func (o *Blueprint) Request(ctx context.Context, diags *diag.Diagnostics) *apstr
FabricSettings: fabricSettings,
}

if utils.Known(o.FabricAddressing) {
if utils.HasValue(o.FabricAddressing) {
result.FabricSettings.SpineLeafLinks = utils.FabricAddressing(ctx, o.FabricAddressing,
utils.ToPtr(path.Root("fabric_addressing")), diags)
if diags.HasError() {
Expand Down Expand Up @@ -813,7 +813,7 @@ func (o *Blueprint) LoadAntiAffninityPolicy(ctx context.Context, antiAffinitypol
func (o *Blueprint) FabricSettings(ctx context.Context, diags *diag.Diagnostics) *apstra.FabricSettings {
var result apstra.FabricSettings

if utils.Known(o.AntiAffinityMode) && utils.Known(o.AntiAffinityPolicy) {
if utils.HasValue(o.AntiAffinityMode) && utils.HasValue(o.AntiAffinityPolicy) {
var aap AntiAffinityPolicy
diags.Append(o.AntiAffinityPolicy.As(ctx, &aap, basetypes.ObjectAsOptions{})...)
if diags.HasError() {
Expand All @@ -836,78 +836,78 @@ func (o *Blueprint) FabricSettings(ctx context.Context, diags *diag.Diagnostics)
}
}

if utils.Known(o.DefaultSviL3Mtu) {
if utils.HasValue(o.DefaultSviL3Mtu) {
result.DefaultSviL3Mtu = utils.ToPtr(uint16(o.DefaultSviL3Mtu.ValueInt64()))
}

if utils.Known(o.EsiMacMsb) {
if utils.HasValue(o.EsiMacMsb) {
result.EsiMacMsb = utils.ToPtr(uint8(o.EsiMacMsb.ValueInt64()))
}

if utils.Known(o.EvpnType5Routes) {
if utils.HasValue(o.EvpnType5Routes) {
result.EvpnGenerateType5HostRoutes = &apstra.FeatureSwitchEnumDisabled
if o.EvpnType5Routes.ValueBool() {
result.EvpnGenerateType5HostRoutes = &apstra.FeatureSwitchEnumEnabled
}
}

if utils.Known(o.DefaultIpLinksToGenericMtu) {
if utils.HasValue(o.DefaultIpLinksToGenericMtu) {
result.ExternalRouterMtu = utils.ToPtr(uint16(o.DefaultIpLinksToGenericMtu.ValueInt64()))
}

if utils.Known(o.FabricMtu) {
if utils.HasValue(o.FabricMtu) {
result.FabricL3Mtu = utils.ToPtr(uint16(o.FabricMtu.ValueInt64()))
}

if utils.Known(o.Ipv6Applications) {
if utils.HasValue(o.Ipv6Applications) {
result.Ipv6Enabled = utils.ToPtr(o.Ipv6Applications.ValueBool())
}

if utils.Known(o.JunosEvpnMaxNexthopAndInterfaceNumber) {
if utils.HasValue(o.JunosEvpnMaxNexthopAndInterfaceNumber) {
result.JunosEvpnMaxNexthopAndInterfaceNumber = &apstra.FeatureSwitchEnumDisabled
if o.JunosEvpnMaxNexthopAndInterfaceNumber.ValueBool() {
result.JunosEvpnMaxNexthopAndInterfaceNumber = &apstra.FeatureSwitchEnumEnabled
}
}

if utils.Known(o.JunosEvpnRoutingInstanceModeMacVrf) {
if utils.HasValue(o.JunosEvpnRoutingInstanceModeMacVrf) {
result.JunosEvpnRoutingInstanceVlanAware = &apstra.FeatureSwitchEnumDisabled
if o.JunosEvpnRoutingInstanceModeMacVrf.ValueBool() {
result.JunosEvpnRoutingInstanceVlanAware = &apstra.FeatureSwitchEnumEnabled
}
}

if utils.Known(o.JunosExOverlayEcmp) {
if utils.HasValue(o.JunosExOverlayEcmp) {
result.JunosExOverlayEcmp = &apstra.FeatureSwitchEnumDisabled
if o.JunosExOverlayEcmp.ValueBool() {
result.JunosExOverlayEcmp = &apstra.FeatureSwitchEnumEnabled
}
}

if utils.Known(o.JunosGracefulRestart) {
if utils.HasValue(o.JunosGracefulRestart) {
result.JunosGracefulRestart = &apstra.FeatureSwitchEnumDisabled
if o.JunosGracefulRestart.ValueBool() {
result.JunosGracefulRestart = &apstra.FeatureSwitchEnumEnabled
}
}

if utils.Known(o.MaxEvpnRoutesCount) {
if utils.HasValue(o.MaxEvpnRoutesCount) {
result.MaxEvpnRoutes = utils.ToPtr(uint32(o.MaxEvpnRoutesCount.ValueInt64()))
}

if utils.Known(o.MaxExternalRoutesCount) {
if utils.HasValue(o.MaxExternalRoutesCount) {
result.MaxExternalRoutes = utils.ToPtr(uint32(o.MaxExternalRoutesCount.ValueInt64()))
}

if utils.Known(o.MaxFabricRoutesCount) {
if utils.HasValue(o.MaxFabricRoutesCount) {
result.MaxFabricRoutes = utils.ToPtr(uint32(o.MaxFabricRoutesCount.ValueInt64()))
}

if utils.Known(o.MaxMlagRoutesCount) {
if utils.HasValue(o.MaxMlagRoutesCount) {
result.MaxMlagRoutes = utils.ToPtr(uint32(o.MaxMlagRoutesCount.ValueInt64()))
}

if utils.Known(o.OptimizeRoutingZoneFootprint) {
if utils.HasValue(o.OptimizeRoutingZoneFootprint) {
result.OptimiseSzFootprint = &apstra.FeatureSwitchEnumDisabled
if o.OptimizeRoutingZoneFootprint.ValueBool() {
result.OptimiseSzFootprint = &apstra.FeatureSwitchEnumEnabled
Expand Down
8 changes: 4 additions & 4 deletions apstra/blueprint/datacenter_external_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,25 +242,25 @@ func (o *DatacenterExternalGateway) Request(ctx context.Context, diags *diag.Dia
}

var ttl *uint8
if utils.Known(o.Ttl) {
if utils.HasValue(o.Ttl) {
t := uint8(o.Ttl.ValueInt64())
ttl = &t
}

var keepaliveTimer *uint16
if utils.Known(o.KeepaliveTime) {
if utils.HasValue(o.KeepaliveTime) {
t := uint16(o.KeepaliveTime.ValueInt64())
keepaliveTimer = &t
}

var holdtimeTimer *uint16
if utils.Known(o.HoldTime) {
if utils.HasValue(o.HoldTime) {
t := uint16(o.HoldTime.ValueInt64())
holdtimeTimer = &t
}

var password *string
if utils.Known(o.Password) {
if utils.HasValue(o.Password) {
t := o.Password.ValueString()
password = &t
}
Expand Down
6 changes: 3 additions & 3 deletions apstra/blueprint/datacenter_generic_system_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ func (o *DatacenterGenericSystemLink) loadApiData(ctx context.Context, in *apstr
}

func (o *DatacenterGenericSystemLink) getTransformId(ctx context.Context, client *apstra.TwoStageL3ClosClient, diags *diag.Diagnostics) {
if !utils.Known(o.TargetSwitchId) {
if !utils.HasValue(o.TargetSwitchId) {
diags.AddError(
"provider bug",
"attempt to get interface transform ID without TargetSwitchId - please report this issue to the maintainers")
return
}

if !utils.Known(o.TargetSwitchIfName) {
if !utils.HasValue(o.TargetSwitchIfName) {
diags.AddError(
"provider bug",
"attempt to get interface transform ID without TargetSwitchIfName - please report this issue to the maintainers")
Expand Down Expand Up @@ -199,7 +199,7 @@ func (o *DatacenterGenericSystemLink) versionConstraintsAsGenericSystemLink(_ co
var result apiversions.Constraints

// can't use tags in 4.1.1 or earlier because the API endpoint we use in Read() doesn't return them
if utils.Known(o.Tags) {
if utils.HasValue(o.Tags) {
result.AddAttributeConstraints(apiversions.AttributeConstraint{
Path: path.AtName("tags"),
Constraints: version.MustConstraints(version.NewConstraint("> " + apiversions.Apstra411)),
Expand Down
Loading

0 comments on commit 68ab227

Please sign in to comment.