Skip to content

Commit

Permalink
Merge pull request #172 from Juniper/170-apstra-421-anti-affinity-beh…
Browse files Browse the repository at this point in the history
…avior-change

Apstra 421 anti affinity behavior change
  • Loading branch information
bwJuniper authored Dec 22, 2023
2 parents b402a33 + 1fe9341 commit 587ecce
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 29 deletions.
73 changes: 46 additions & 27 deletions apstra/api_design_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ func (o *TemplateRackBased) OverlayControlProtocol() OverlayControlProtocol {

type TemplateRackBasedData struct {
DisplayName string
AntiAffinityPolicy AntiAffinityPolicy
AntiAffinityPolicy *AntiAffinityPolicy
VirtualNetworkPolicy VirtualNetworkPolicy
AsnAllocationPolicy AsnAllocationPolicy
FabricAddressingPolicy *FabricAddressingPolicy
Expand All @@ -789,7 +789,7 @@ type rawTemplateRackBased struct {
Id ObjectId `json:"id"`
Type templateType `json:"type"`
DisplayName string `json:"display_name"`
AntiAffinityPolicy rawAntiAffinityPolicy `json:"anti_affinity_policy"`
AntiAffinityPolicy *rawAntiAffinityPolicy `json:"anti_affinity_policy,omitempty"`
CreatedAt time.Time `json:"created_at"`
LastModifiedAt time.Time `json:"last_modified_at"`
VirtualNetworkPolicy rawVirtualNetworkPolicy `json:"virtual_network_policy"`
Expand Down Expand Up @@ -830,10 +830,12 @@ func (o rawTemplateRackBased) polish() (*TemplateRackBased, error) {
if err != nil {
return nil, err
}

antiAffinityPolicy, err := o.AntiAffinityPolicy.polish()
if err != nil {
return nil, err
var aap *AntiAffinityPolicy
if o.AntiAffinityPolicy != nil {
aap, err = o.AntiAffinityPolicy.polish()
if err != nil {
return nil, err
}
}

if len(o.RackTypes) != len(o.RackTypeCounts) {
Expand Down Expand Up @@ -867,7 +869,7 @@ OUTER:
LastModifiedAt: o.LastModifiedAt,
Data: &TemplateRackBasedData{
DisplayName: o.DisplayName,
AntiAffinityPolicy: *antiAffinityPolicy,
AntiAffinityPolicy: aap,
VirtualNetworkPolicy: *v,
AsnAllocationPolicy: *a,
FabricAddressingPolicy: f,
Expand Down Expand Up @@ -906,7 +908,7 @@ func (o *TemplatePodBased) OverlayControlProtocol() OverlayControlProtocol {

type TemplatePodBasedData struct {
DisplayName string
AntiAffinityPolicy AntiAffinityPolicy
AntiAffinityPolicy *AntiAffinityPolicy
FabricAddressingPolicy *FabricAddressingPolicy
Superspine Superspine
Capability TemplateCapability
Expand All @@ -918,7 +920,7 @@ type rawTemplatePodBased struct {
Id ObjectId `json:"id"`
Type templateType `json:"type"`
DisplayName string `json:"display_name"`
AntiAffinityPolicy rawAntiAffinityPolicy `json:"anti_affinity_policy"`
AntiAffinityPolicy *rawAntiAffinityPolicy `json:"anti_affinity_policy,omitempty"`
FabricAddressingPolicy *rawFabricAddressingPolicy `json:"fabric_addressing_policy,omitempty"`
Superspine rawSuperspine `json:"superspine"`
CreatedAt time.Time `json:"created_at"`
Expand Down Expand Up @@ -961,9 +963,12 @@ func (o rawTemplatePodBased) polish() (*TemplatePodBased, error) {
if err != nil {
return nil, err
}
antiAffinityPolicy, err := o.AntiAffinityPolicy.polish()
if err != nil {
return nil, err
var aap *AntiAffinityPolicy
if o.AntiAffinityPolicy != nil {
aap, err = o.AntiAffinityPolicy.polish()
if err != nil {
return nil, err
}
}
return &TemplatePodBased{
Id: o.Id,
Expand All @@ -972,7 +977,7 @@ func (o rawTemplatePodBased) polish() (*TemplatePodBased, error) {
LastModifiedAt: o.LastModifiedAt,
Data: &TemplatePodBasedData{
DisplayName: o.DisplayName,
AntiAffinityPolicy: *antiAffinityPolicy,
AntiAffinityPolicy: aap,
FabricAddressingPolicy: fap,
Superspine: *superspine,
Capability: TemplateCapability(capability),
Expand Down Expand Up @@ -1009,7 +1014,7 @@ func (o *TemplateL3Collapsed) OverlayControlProtocol() OverlayControlProtocol {

type TemplateL3CollapsedData struct {
DisplayName string
AntiAffinityPolicy AntiAffinityPolicy
AntiAffinityPolicy *AntiAffinityPolicy
RackTypes []RackType
Capability TemplateCapability
MeshLinkSpeed LogicalDevicePortSpeed
Expand All @@ -1023,7 +1028,7 @@ type rawTemplateL3Collapsed struct {
Id ObjectId `json:"id"`
Type templateType `json:"type"`
DisplayName string `json:"display_name"`
AntiAffinityPolicy rawAntiAffinityPolicy `json:"anti_affinity_policy"`
AntiAffinityPolicy *rawAntiAffinityPolicy `json:"anti_affinity_policy,omitempty"`
CreatedAt time.Time `json:"created_at"`
LastModifiedAt time.Time `json:"last_modified_at"`
RackTypes []rawRackType `json:"rack_types"`
Expand Down Expand Up @@ -1056,9 +1061,12 @@ func (o rawTemplateL3Collapsed) polish() (*TemplateL3Collapsed, error) {
if err != nil {
return nil, err
}
antiAffinityPolicy, err := o.AntiAffinityPolicy.polish()
if err != nil {
return nil, err
var aap *AntiAffinityPolicy
if o.AntiAffinityPolicy != nil {
aap, err = o.AntiAffinityPolicy.polish()
if err != nil {
return nil, err
}
}
return &TemplateL3Collapsed{
Id: o.Id,
Expand All @@ -1067,7 +1075,7 @@ func (o rawTemplateL3Collapsed) polish() (*TemplateL3Collapsed, error) {
LastModifiedAt: o.LastModifiedAt,
Data: &TemplateL3CollapsedData{
DisplayName: o.DisplayName,
AntiAffinityPolicy: *antiAffinityPolicy,
AntiAffinityPolicy: aap,
RackTypes: prt,
Capability: TemplateCapability(capability),
MeshLinkSpeed: o.MeshLinkSpeed.parse(),
Expand Down Expand Up @@ -1392,7 +1400,12 @@ func (o *CreateRackBasedTemplateRequest) raw(ctx context.Context, client *Client
if err != nil {
return nil, err
}
antiAffinityPolicy := o.AntiAffinityPolicy.raw()

var antiAffinityPolicy *rawAntiAffinityPolicy
if o.AntiAffinityPolicy != nil {
antiAffinityPolicy = o.AntiAffinityPolicy.raw()
}

asnAllocationPolicy := o.AsnAllocationPolicy.raw()

var fabricAddressingPolicy *rawFabricAddressingPolicy
Expand All @@ -1410,7 +1423,7 @@ func (o *CreateRackBasedTemplateRequest) raw(ctx context.Context, client *Client
RackTypes: rackTypes,
RackTypeCounts: rackTypeCounts,
DhcpServiceIntent: dhcpServiceIntent,
AntiAffinityPolicy: *antiAffinityPolicy,
AntiAffinityPolicy: antiAffinityPolicy,
AsnAllocationPolicy: *asnAllocationPolicy,
FabricAddressingPolicy: fabricAddressingPolicy,
VirtualNetworkPolicy: *virtualNetworkPolicy,
Expand All @@ -1425,7 +1438,7 @@ type rawCreateRackBasedTemplateRequest struct {
RackTypes []rawRackType `json:"rack_types"`
RackTypeCounts []RackTypeCount `json:"rack_type_counts"`
DhcpServiceIntent DhcpServiceIntent `json:"dhcp_service_intent"`
AntiAffinityPolicy rawAntiAffinityPolicy `json:"anti_affinity_policy"`
AntiAffinityPolicy *rawAntiAffinityPolicy `json:"anti_affinity_policy,omitempty"`
AsnAllocationPolicy rawAsnAllocationPolicy `json:"asn_allocation_policy"`
FabricAddressingPolicy *rawFabricAddressingPolicy `json:"fabric_addressing_policy,omitempty"`
VirtualNetworkPolicy rawVirtualNetworkPolicy `json:"virtual_network_policy"`
Expand Down Expand Up @@ -1509,7 +1522,7 @@ func (o *CreatePodBasedTemplateRequest) raw(ctx context.Context, client *Client)
Superspine: *superspine,
RackBasedTemplates: rawRackBasedTemplates,
RackBasedTemplateCounts: o.RackBasedTemplateCounts,
AntiAffinityPolicy: *antiAffinityPolicy,
AntiAffinityPolicy: antiAffinityPolicy,
FabricAddressingPolicy: fabricAddressingPolicy,
}, nil
}
Expand All @@ -1521,7 +1534,7 @@ type rawCreatePodBasedTemplateRequest struct {
Superspine rawSuperspine `json:"superspine"`
RackBasedTemplates []rawTemplateRackBased `json:"rack_based_templates"`
RackBasedTemplateCounts []RackBasedTemplateCount `json:"rack_based_template_counts"`
AntiAffinityPolicy rawAntiAffinityPolicy `json:"anti_affinity_policy"`
AntiAffinityPolicy *rawAntiAffinityPolicy `json:"anti_affinity_policy,omitempty"`
FabricAddressingPolicy *rawFabricAddressingPolicy `json:"fabric_addressing_policy,omitempty"`
}

Expand Down Expand Up @@ -1565,7 +1578,7 @@ type CreateL3CollapsedTemplateRequest struct {
RackTypeIds []ObjectId `json:"rack_types"`
RackTypeCounts []RackTypeCount `json:"rack_type_counts"`
DhcpServiceIntent DhcpServiceIntent `json:"dhcp_service_intent"`
AntiAffinityPolicy AntiAffinityPolicy `json:"anti_affinity_policy"`
AntiAffinityPolicy *AntiAffinityPolicy `json:"anti_affinity_policy,omitempty"`
VirtualNetworkPolicy VirtualNetworkPolicy `json:"virtual_network_policy"`
}

Expand All @@ -1578,6 +1591,12 @@ func (o *CreateL3CollapsedTemplateRequest) raw(ctx context.Context, client *Clie
}
rackTypes[i] = *rt
}

var antiAffinityPolicy *rawAntiAffinityPolicy
if o.AntiAffinityPolicy != nil {
antiAffinityPolicy = o.AntiAffinityPolicy.raw()
}

return &rawCreateL3CollapsedTemplateRequest{
Type: templateTypeL3Collapsed,
DisplayName: o.DisplayName,
Expand All @@ -1587,7 +1606,7 @@ func (o *CreateL3CollapsedTemplateRequest) raw(ctx context.Context, client *Clie
RackTypes: rackTypes,
RackTypeCounts: o.RackTypeCounts,
DhcpServiceIntent: o.DhcpServiceIntent,
AntiAffinityPolicy: *o.AntiAffinityPolicy.raw(),
AntiAffinityPolicy: antiAffinityPolicy,
VirtualNetworkPolicy: *o.VirtualNetworkPolicy.raw(),
}, nil
}
Expand All @@ -1601,7 +1620,7 @@ type rawCreateL3CollapsedTemplateRequest struct {
RackTypes []rawRackType `json:"rack_types"`
RackTypeCounts []RackTypeCount `json:"rack_type_counts"`
DhcpServiceIntent DhcpServiceIntent `json:"dhcp_service_intent"`
AntiAffinityPolicy rawAntiAffinityPolicy `json:"anti_affinity_policy"`
AntiAffinityPolicy *rawAntiAffinityPolicy `json:"anti_affinity_policy,omitempty"`
VirtualNetworkPolicy rawVirtualNetworkPolicy `json:"virtual_network_policy"`
}

Expand Down
2 changes: 1 addition & 1 deletion apstra/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ func testTemplateB(ctx context.Context, t *testing.T, client *Client) (ObjectId,
},
RackInfos: rbt.Data.RackInfo,
DhcpServiceIntent: &rbt.Data.DhcpServiceIntent,
AntiAffinityPolicy: &rbt.Data.AntiAffinityPolicy,
AntiAffinityPolicy: rbt.Data.AntiAffinityPolicy,
AsnAllocationPolicy: &rbt.Data.AsnAllocationPolicy,
FabricAddressingPolicy: rbt.Data.FabricAddressingPolicy,
VirtualNetworkPolicy: &rbt.Data.VirtualNetworkPolicy,
Expand Down
2 changes: 1 addition & 1 deletion cmd/example_streaming/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func main() {
Pass: "password",
HttpClient: &http.Client{Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}},
}
client, err := clientCfg.NewClient()
client, err := clientCfg.NewClient(context.TODO())
if err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit 587ecce

Please sign in to comment.