Skip to content

Commit

Permalink
add support for fabric l3 mtu at blueprint creation time
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismarget-j committed Jan 23, 2024
1 parent fec4a91 commit 4fed17e
Show file tree
Hide file tree
Showing 10 changed files with 482 additions and 92 deletions.
64 changes: 57 additions & 7 deletions apstra/api_blueprints.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,56 @@ const (
refDesignUnknown = refDesign("unknown reference design %d")
)

type BlueprintRequestFabricAddressingPolicy struct {
SpineSuperspineLinks AddressingScheme
SpineLeafLinks AddressingScheme
FabricL3Mtu *uint16
}

func (o *BlueprintRequestFabricAddressingPolicy) raw() *rawBlueprintRequestFabricAddressingPolicy {
var fabricL3Mtu *uint16
if o.FabricL3Mtu != nil {
t := *o.FabricL3Mtu // copy the pointed-to value
fabricL3Mtu = &t
}

return &rawBlueprintRequestFabricAddressingPolicy{
SpineSuperspineLinks: o.SpineSuperspineLinks.raw(),
SpineLeafLinks: o.SpineLeafLinks.raw(),
FabricL3Mtu: fabricL3Mtu,
}
}

type rawBlueprintRequestFabricAddressingPolicy struct {
SpineSuperspineLinks addressingScheme `json:"spine_superspine_links"`
SpineLeafLinks addressingScheme `json:"spine_leaf_links"`
FabricL3Mtu *uint16 `json:"fabric_l3_mtu,omitempty"`
}

func (o *rawBlueprintRequestFabricAddressingPolicy) polish() (*BlueprintRequestFabricAddressingPolicy, error) {
var fabricL3Mtu *uint16
if o.FabricL3Mtu != nil {
t := *o.FabricL3Mtu // copy the pointed-to value
fabricL3Mtu = &t
}

ssl, err := o.SpineSuperspineLinks.parse()
if err != nil {
return nil, err
}

sll, err := o.SpineLeafLinks.parse()
if err != nil {
return nil, err
}

return &BlueprintRequestFabricAddressingPolicy{
SpineSuperspineLinks: AddressingScheme(ssl),
SpineLeafLinks: AddressingScheme(sll),
FabricL3Mtu: fabricL3Mtu,
}, nil
}

type RefDesign int
type refDesign string

Expand Down Expand Up @@ -262,11 +312,11 @@ type CreateBlueprintFromTemplateRequest struct {
RefDesign RefDesign
Label string
TemplateId ObjectId
FabricAddressingPolicy *FabricAddressingPolicy
FabricAddressingPolicy *BlueprintRequestFabricAddressingPolicy
}

func (o *CreateBlueprintFromTemplateRequest) raw() *rawCreateBlueprintFromTemplateRequest {
var fap *rawFabricAddressingPolicy
var fap *rawBlueprintRequestFabricAddressingPolicy
if o.FabricAddressingPolicy != nil {
fap = o.FabricAddressingPolicy.raw()
}
Expand All @@ -280,11 +330,11 @@ func (o *CreateBlueprintFromTemplateRequest) raw() *rawCreateBlueprintFromTempla
}

type rawCreateBlueprintFromTemplateRequest struct {
RefDesign string `json:"design"`
Label string `json:"label"`
InitType string `json:"init_type"`
TemplateId ObjectId `json:"template_id"`
FabricAddressingPolicy *rawFabricAddressingPolicy `json:"fabric_addressing_policy,omitempty"`
RefDesign string `json:"design"`
Label string `json:"label"`
InitType string `json:"init_type"`
TemplateId ObjectId `json:"template_id"`
FabricAddressingPolicy *rawBlueprintRequestFabricAddressingPolicy `json:"fabric_addressing_policy,omitempty"`
}

func (o *Client) listAllBlueprintIds(ctx context.Context) ([]ObjectId, error) {
Expand Down
62 changes: 54 additions & 8 deletions apstra/api_blueprints_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"encoding/json"
"log"
"math/rand"
"testing"
)

Expand Down Expand Up @@ -49,26 +50,71 @@ func TestGetAllBlueprintStatus(t *testing.T) {
}

func TestCreateDeleteBlueprint(t *testing.T) {
clients, err := getTestClients(context.Background(), t)
ctx := context.Background()

clients, err := getTestClients(ctx, t)
if err != nil {
t.Fatal(err)
}

for clientName, client := range clients {
var blueprintFabricAddressingPolicy *BlueprintRequestFabricAddressingPolicy
if rackBasedTemplateFabricAddressingPolicyForbidden().Includes(client.client.apiVersion) {
// forbidden in the template means we can use this feature in the blueprint
blueprintFabricAddressingPolicy = &BlueprintRequestFabricAddressingPolicy{}

if !fabricL3MtuForbidden().Includes(client.client.apiVersion) {
fabricL3Mtu := uint16(rand.Intn(550)*2 + 8000) // even number 8000 - 9100
blueprintFabricAddressingPolicy.FabricL3Mtu = &fabricL3Mtu
blueprintFabricAddressingPolicy.SpineLeafLinks = AddressingSchemeIp46
blueprintFabricAddressingPolicy.SpineSuperspineLinks = AddressingSchemeIp46
}
}

req := CreateBlueprintFromTemplateRequest{
RefDesign: RefDesignTwoStageL3Clos,
Label: randString(10, "hex"),
TemplateId: "L2_Virtual_EVPN",
FabricAddressingPolicy: blueprintFabricAddressingPolicy,
}

log.Printf("testing createBlueprintFromTemplate() against %s %s (%s)", client.clientType, clientName, client.client.ApiVersion())
name := randString(10, "hex")
id, err := client.client.CreateBlueprintFromTemplate(context.TODO(), &CreateBlueprintFromTemplateRequest{
RefDesign: RefDesignTwoStageL3Clos,
Label: name,
TemplateId: "L2_Virtual_EVPN",
})
id, err := client.client.CreateBlueprintFromTemplate(ctx, &req)
if err != nil {
t.Fatal(err)
}

bp, err := client.client.GetBlueprint(ctx, id)
if err != nil {
t.Fatal(err)
}

if id != bp.Id {
t.Fatalf("expected id %q, got %q", id, bp.Id)
}

if req.Label != bp.Label {
t.Fatalf("expected label %q, got %q", req.Label, bp.Label)
}

bpClient, err := client.client.NewTwoStageL3ClosClient(ctx, id)
if err != nil {
t.Fatal(err)
}

if req.FabricAddressingPolicy != nil && req.FabricAddressingPolicy.FabricL3Mtu != nil {
fap, err := bpClient.GetFabricAddressingPolicy(ctx)
if err != nil {
t.Fatal(err)
}
if *req.FabricAddressingPolicy.FabricL3Mtu != *fap.FabricL3Mtu {
t.Fatalf("expected fabric MTU %d, got %d", *req.FabricAddressingPolicy.FabricL3Mtu, *fap.FabricL3Mtu)
}
}

log.Printf("got id '%s', deleting blueprint...\n", id)
log.Printf("testing deleteBlueprint() against %s %s (%s)", client.clientType, clientName, client.client.ApiVersion())
err = client.client.deleteBlueprint(context.TODO(), id)
err = client.client.deleteBlueprint(ctx, id)
if err != nil {
t.Fatal(err)
}
Expand Down
112 changes: 56 additions & 56 deletions apstra/api_design_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,24 +470,24 @@ func (o *rawAsnAllocationPolicy) polish() (*AsnAllocationPolicy, error) {
return &AsnAllocationPolicy{SpineAsnScheme: AsnAllocationScheme(sas)}, err
}

type FabricAddressingPolicy struct {
type TemplateFabricAddressingPolicy410Only struct {
SpineSuperspineLinks AddressingScheme
SpineLeafLinks AddressingScheme
}

func (o *FabricAddressingPolicy) raw() *rawFabricAddressingPolicy {
return &rawFabricAddressingPolicy{
func (o *TemplateFabricAddressingPolicy410Only) raw() *rawTemplateFabricAddressingPolicy410Only {
return &rawTemplateFabricAddressingPolicy410Only{
SpineSuperspineLinks: o.SpineSuperspineLinks.raw(),
SpineLeafLinks: o.SpineLeafLinks.raw(),
}
}

type rawFabricAddressingPolicy struct {
type rawTemplateFabricAddressingPolicy410Only struct {
SpineSuperspineLinks addressingScheme `json:"spine_superspine_links"`
SpineLeafLinks addressingScheme `json:"spine_leaf_links"`
}

func (o *rawFabricAddressingPolicy) polish() (*FabricAddressingPolicy, error) {
func (o *rawTemplateFabricAddressingPolicy410Only) polish() (*TemplateFabricAddressingPolicy410Only, error) {
ssl, err := o.SpineSuperspineLinks.parse()
if err != nil {
return nil, err
Expand All @@ -498,7 +498,7 @@ func (o *rawFabricAddressingPolicy) polish() (*FabricAddressingPolicy, error) {
return nil, err
}

return &FabricAddressingPolicy{
return &TemplateFabricAddressingPolicy410Only{
SpineSuperspineLinks: AddressingScheme(ssl),
SpineLeafLinks: AddressingScheme(sll),
}, nil
Expand Down Expand Up @@ -727,7 +727,7 @@ type TemplateRackBasedData struct {
AntiAffinityPolicy *AntiAffinityPolicy
VirtualNetworkPolicy VirtualNetworkPolicy
AsnAllocationPolicy AsnAllocationPolicy
FabricAddressingPolicy *FabricAddressingPolicy
FabricAddressingPolicy *TemplateFabricAddressingPolicy410Only // Apstra 4.1.0 only
Capability TemplateCapability
Spine Spine
RackInfo map[ObjectId]TemplateRackBasedRackInfo
Expand All @@ -744,20 +744,20 @@ type DhcpServiceIntent struct {
}

type rawTemplateRackBased struct {
Id ObjectId `json:"id"`
Type templateType `json:"type"`
DisplayName string `json:"display_name"`
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"`
AsnAllocationPolicy rawAsnAllocationPolicy `json:"asn_allocation_policy"`
FabricAddressingPolicy *rawFabricAddressingPolicy `json:"fabric_addressing_policy,omitempty"`
Capability templateCapability `json:"capability,omitempty"`
Spine rawSpine `json:"spine"`
RackTypes []rawRackType `json:"rack_types"`
RackTypeCounts []RackTypeCount `json:"rack_type_counts"`
DhcpServiceIntent DhcpServiceIntent `json:"dhcp_service_intent"`
Id ObjectId `json:"id"`
Type templateType `json:"type"`
DisplayName string `json:"display_name"`
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"`
AsnAllocationPolicy rawAsnAllocationPolicy `json:"asn_allocation_policy"`
FabricAddressingPolicy *rawTemplateFabricAddressingPolicy410Only `json:"fabric_addressing_policy,omitempty"` // Apstra 4.1.0 only
Capability templateCapability `json:"capability,omitempty"`
Spine rawSpine `json:"spine"`
RackTypes []rawRackType `json:"rack_types"`
RackTypeCounts []RackTypeCount `json:"rack_type_counts"`
DhcpServiceIntent DhcpServiceIntent `json:"dhcp_service_intent"`
}

func (o rawTemplateRackBased) polish() (*TemplateRackBased, error) {
Expand All @@ -773,7 +773,7 @@ func (o rawTemplateRackBased) polish() (*TemplateRackBased, error) {
if err != nil {
return nil, err
}
var f *FabricAddressingPolicy
var f *TemplateFabricAddressingPolicy410Only
if o.FabricAddressingPolicy != nil {
f, err = o.FabricAddressingPolicy.polish()
if err != nil {
Expand Down Expand Up @@ -867,30 +867,30 @@ func (o *TemplatePodBased) OverlayControlProtocol() OverlayControlProtocol {
type TemplatePodBasedData struct {
DisplayName string
AntiAffinityPolicy *AntiAffinityPolicy
FabricAddressingPolicy *FabricAddressingPolicy
FabricAddressingPolicy *TemplateFabricAddressingPolicy410Only // Apstra 4.1.0 only
Superspine Superspine
Capability TemplateCapability
RackBasedTemplates []TemplateRackBased
RackBasedTemplateCounts []RackBasedTemplateCount
}

type rawTemplatePodBased struct {
Id ObjectId `json:"id"`
Type templateType `json:"type"`
DisplayName string `json:"display_name"`
AntiAffinityPolicy *rawAntiAffinityPolicy `json:"anti_affinity_policy,omitempty"`
FabricAddressingPolicy *rawFabricAddressingPolicy `json:"fabric_addressing_policy,omitempty"`
Superspine rawSuperspine `json:"superspine"`
CreatedAt time.Time `json:"created_at"`
LastModifiedAt time.Time `json:"last_modified_at"`
Capability templateCapability `json:"capability,omitempty"`
RackBasedTemplates []rawTemplateRackBased `json:"rack_based_templates"`
RackBasedTemplateCounts []RackBasedTemplateCount `json:"rack_based_template_counts"`
Id ObjectId `json:"id"`
Type templateType `json:"type"`
DisplayName string `json:"display_name"`
AntiAffinityPolicy *rawAntiAffinityPolicy `json:"anti_affinity_policy,omitempty"`
FabricAddressingPolicy *rawTemplateFabricAddressingPolicy410Only `json:"fabric_addressing_policy,omitempty"` // Apstra 4.1.0 only
Superspine rawSuperspine `json:"superspine"`
CreatedAt time.Time `json:"created_at"`
LastModifiedAt time.Time `json:"last_modified_at"`
Capability templateCapability `json:"capability,omitempty"`
RackBasedTemplates []rawTemplateRackBased `json:"rack_based_templates"`
RackBasedTemplateCounts []RackBasedTemplateCount `json:"rack_based_template_counts"`
}

func (o rawTemplatePodBased) polish() (*TemplatePodBased, error) {
var err error
var fap *FabricAddressingPolicy
var fap *TemplateFabricAddressingPolicy410Only
if o.FabricAddressingPolicy != nil {
fap, err = o.FabricAddressingPolicy.polish()
if err != nil {
Expand Down Expand Up @@ -1310,7 +1310,7 @@ type CreateRackBasedTemplateRequest struct {
DhcpServiceIntent *DhcpServiceIntent
AntiAffinityPolicy *AntiAffinityPolicy
AsnAllocationPolicy *AsnAllocationPolicy
FabricAddressingPolicy *FabricAddressingPolicy
FabricAddressingPolicy *TemplateFabricAddressingPolicy410Only // Apstra 4.1.0 only
VirtualNetworkPolicy *VirtualNetworkPolicy
}

Expand Down Expand Up @@ -1365,7 +1365,7 @@ func (o *CreateRackBasedTemplateRequest) raw(ctx context.Context, client *Client

asnAllocationPolicy := o.AsnAllocationPolicy.raw()

var fabricAddressingPolicy *rawFabricAddressingPolicy
var fabricAddressingPolicy *rawTemplateFabricAddressingPolicy410Only
if o.FabricAddressingPolicy != nil && !rackBasedTemplateFabricAddressingPolicyForbidden().Includes(client.apiVersion) {
fabricAddressingPolicy = o.FabricAddressingPolicy.raw()
}
Expand All @@ -1387,16 +1387,16 @@ func (o *CreateRackBasedTemplateRequest) raw(ctx context.Context, client *Client
}

type rawCreateRackBasedTemplateRequest struct {
Type templateType `json:"type"`
DisplayName string `json:"display_name"`
Spine rawSpine `json:"spine"`
RackTypes []rawRackType `json:"rack_types"`
RackTypeCounts []RackTypeCount `json:"rack_type_counts"`
DhcpServiceIntent DhcpServiceIntent `json:"dhcp_service_intent"`
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"`
Type templateType `json:"type"`
DisplayName string `json:"display_name"`
Spine rawSpine `json:"spine"`
RackTypes []rawRackType `json:"rack_types"`
RackTypeCounts []RackTypeCount `json:"rack_type_counts"`
DhcpServiceIntent DhcpServiceIntent `json:"dhcp_service_intent"`
AntiAffinityPolicy *rawAntiAffinityPolicy `json:"anti_affinity_policy,omitempty"`
AsnAllocationPolicy rawAsnAllocationPolicy `json:"asn_allocation_policy"`
FabricAddressingPolicy *rawTemplateFabricAddressingPolicy410Only `json:"fabric_addressing_policy,omitempty"`
VirtualNetworkPolicy rawVirtualNetworkPolicy `json:"virtual_network_policy"`
}

func (o *Client) createRackBasedTemplate(ctx context.Context, in *rawCreateRackBasedTemplateRequest) (ObjectId, error) {
Expand Down Expand Up @@ -1435,7 +1435,7 @@ type CreatePodBasedTemplateRequest struct {
RackBasedTemplateIds []ObjectId
RackBasedTemplateCounts []RackBasedTemplateCount
AntiAffinityPolicy *AntiAffinityPolicy
FabricAddressingPolicy *FabricAddressingPolicy
FabricAddressingPolicy *TemplateFabricAddressingPolicy410Only // Apstra 4.1.0 only
}

func (o *CreatePodBasedTemplateRequest) raw(ctx context.Context, client *Client) (*rawCreatePodBasedTemplateRequest, error) {
Expand Down Expand Up @@ -1464,7 +1464,7 @@ func (o *CreatePodBasedTemplateRequest) raw(ctx context.Context, client *Client)
antiAffinityPolicy = o.AntiAffinityPolicy.raw()
}

var fabricAddressingPolicy *rawFabricAddressingPolicy
var fabricAddressingPolicy *rawTemplateFabricAddressingPolicy410Only
if o.FabricAddressingPolicy != nil && !podBasedTemplateFabricAddressingPolicyForbidden().Includes(client.apiVersion) {
fabricAddressingPolicy = o.FabricAddressingPolicy.raw()
}
Expand All @@ -1481,13 +1481,13 @@ func (o *CreatePodBasedTemplateRequest) raw(ctx context.Context, client *Client)
}

type rawCreatePodBasedTemplateRequest struct {
Type templateType `json:"type"`
DisplayName string `json:"display_name"`
Superspine rawSuperspine `json:"superspine"`
RackBasedTemplates []rawTemplateRackBased `json:"rack_based_templates"`
RackBasedTemplateCounts []RackBasedTemplateCount `json:"rack_based_template_counts"`
AntiAffinityPolicy *rawAntiAffinityPolicy `json:"anti_affinity_policy,omitempty"`
FabricAddressingPolicy *rawFabricAddressingPolicy `json:"fabric_addressing_policy,omitempty"`
Type templateType `json:"type"`
DisplayName string `json:"display_name"`
Superspine rawSuperspine `json:"superspine"`
RackBasedTemplates []rawTemplateRackBased `json:"rack_based_templates"`
RackBasedTemplateCounts []RackBasedTemplateCount `json:"rack_based_template_counts"`
AntiAffinityPolicy *rawAntiAffinityPolicy `json:"anti_affinity_policy,omitempty"`
FabricAddressingPolicy *rawTemplateFabricAddressingPolicy410Only `json:"fabric_addressing_policy,omitempty"` // Apstra 4.1.0 only
}

func (o *Client) createPodBasedTemplate(ctx context.Context, in *rawCreatePodBasedTemplateRequest) (ObjectId, error) {
Expand Down
Loading

0 comments on commit 4fed17e

Please sign in to comment.