Skip to content

Commit

Permalink
introduce public methods for managing remote gateways
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismarget-j committed Nov 2, 2023
1 parent b78860a commit a97e1d1
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 25 deletions.
54 changes: 54 additions & 0 deletions apstra/two_stage_l3_clos_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -770,3 +770,57 @@ func (o *TwoStageL3ClosClient) UpdateIbaDashboard(ctx context.Context, id Object
func (o *TwoStageL3ClosClient) DeleteIbaDashboard(ctx context.Context, id ObjectId) error {
return o.client.deleteIbaDashboard(ctx, o.blueprintId, id)
}

// CreateRemoteGateway creates an EVPN remote / external gateway using the specified parameters
func (o *TwoStageL3ClosClient) CreateRemoteGateway(ctx context.Context, in *RemoteGatewayData) (ObjectId, error) {
return o.createRemoteGateway(ctx, in.raw())
}

// GetRemoteGateway retrieves the remote / external gateway specified by id
func (o *TwoStageL3ClosClient) GetRemoteGateway(ctx context.Context, id ObjectId) (*RemoteGateway, error) {
raw, err := o.getRemoteGateway(ctx, id)
if err != nil {
return nil, err
}

return raw.polish()
}

// GetRemoteGatewayByName retrieves the remote / external gateway specified by name
func (o *TwoStageL3ClosClient) GetRemoteGatewayByName(ctx context.Context, name string) (*RemoteGateway, error) {
raw, err := o.getRemoteGatewayByName(ctx, name)
if err != nil {
return nil, err
}

return raw.polish()
}

// GetAllRemoteGateways retrieves all remote / external gateways
func (o *TwoStageL3ClosClient) GetAllRemoteGateways(ctx context.Context) ([]RemoteGateway, error) {
rawGateways, err := o.getAllRemoteGateways(ctx)
if err != nil {
return nil, err
}

result := make([]RemoteGateway, len(rawGateways))
for i, rawGateway := range rawGateways {
gateway, err := rawGateway.polish()
if err != nil {
return nil, err
}
result[i] = *gateway
}

return result, nil
}

// UpdateRemoteGateway updates the remote / external gateway specified by id using the supplied parameters
func (o *TwoStageL3ClosClient) UpdateRemoteGateway(ctx context.Context, id ObjectId, in *RemoteGatewayData) error {
return o.updateRemoteGateway(ctx, id, in.raw())
}

// DeleteRemoteGateway deletes the specified remote / external gateway
func (o *TwoStageL3ClosClient) DeleteRemoteGateway(ctx context.Context, id ObjectId) error {
return o.deleteRemoteGateway(ctx, id)
}
40 changes: 15 additions & 25 deletions apstra/two_stage_l3_clos_remote_gateways_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,53 +128,43 @@ func TestCreateDeleteRemoteGateway(t *testing.T) {
for i, cfg := range remoteGwCfgs {
cfg.LocalGwNodes = localGwNodes

log.Printf("testing createRemoteGateway() against %s %s (%s)", client.clientType, clientName, client.client.ApiVersion())
ids[i], err = bp.createRemoteGateway(ctx, cfg.raw())
log.Printf("testing CreateRemoteGateway() against %s %s (%s)", client.clientType, clientName, client.client.ApiVersion())
ids[i], err = bp.CreateRemoteGateway(ctx, &cfg)
if err != nil {
t.Fatal(err)
}

log.Printf("testing getRemoteGateway() against %s %s (%s)", client.clientType, clientName, client.client.ApiVersion())
raw, err := bp.getRemoteGateway(ctx, ids[i])
log.Printf("testing GetRemoteGateway() against %s %s (%s)", client.clientType, clientName, client.client.ApiVersion())
gatewayById, err := bp.GetRemoteGateway(ctx, ids[i])
if err != nil {
t.Fatal(err)
}

polishedById, err := raw.polish()
if err != nil {
t.Fatal(err)
}

if ids[i] != polishedById.Id {
t.Fatalf("expected ID %q, got %q", ids[i], polishedById.Id)
if ids[i] != gatewayById.Id {
t.Fatalf("expected ID %q, got %q", ids[i], gatewayById.Id)
}

if cfg.Ttl == nil || cfg.KeepaliveTimer == nil || cfg.HoldtimeTimer == nil {
checkRemoteGatewayDataAreEqual(t, &cfg, polishedById.Data, true)
checkRemoteGatewayDataAreEqual(t, &cfg, gatewayById.Data, true)
} else {
checkRemoteGatewayDataAreEqual(t, &cfg, polishedById.Data, false)
}

log.Printf("testing getRemoteGatewayByName() against %s %s (%s)", client.clientType, clientName, client.client.ApiVersion())
raw, err = bp.getRemoteGatewayByName(ctx, remoteGwCfgs[i].GwName)
if err != nil {
t.Fatal(err)
checkRemoteGatewayDataAreEqual(t, &cfg, gatewayById.Data, false)
}

polishedByName, err := raw.polish()
log.Printf("testing GetRemoteGatewayByName() against %s %s (%s)", client.clientType, clientName, client.client.ApiVersion())
gatewayByName, err := bp.GetRemoteGatewayByName(ctx, remoteGwCfgs[i].GwName)
if err != nil {
t.Fatal(err)
}

if polishedById.Id != polishedByName.Id {
t.Fatalf("id fetched by ID doesn't match id fetched by name: %q vs. %q", polishedById.Id, polishedByName.Id)
if gatewayById.Id != gatewayByName.Id {
t.Fatalf("id fetched by ID doesn't match id fetched by name: %q vs. %q", gatewayById.Id, gatewayByName.Id)
}

checkRemoteGatewayDataAreEqual(t, polishedById.Data, polishedByName.Data, false)
checkRemoteGatewayDataAreEqual(t, gatewayById.Data, gatewayByName.Data, false)
}

log.Printf("testing getAllRemoteGateways() against %s %s (%s)", client.clientType, clientName, client.client.ApiVersion())
remoteGws, err := bp.getAllRemoteGateways(ctx)
remoteGws, err := bp.GetAllRemoteGateways(ctx)
if err != nil {
t.Fatal(err)
}
Expand All @@ -191,7 +181,7 @@ func TestCreateDeleteRemoteGateway(t *testing.T) {
}

log.Printf("testing getAllRemoteGateways() against %s %s (%s)", client.clientType, clientName, client.client.ApiVersion())
remoteGws, err = bp.getAllRemoteGateways(ctx)
remoteGws, err = bp.GetAllRemoteGateways(ctx)
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit a97e1d1

Please sign in to comment.