Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce PatchNodes() #171

Merged
merged 1 commit into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions apstra/api_blueprints.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,3 +520,16 @@ func (o *Client) patchNode(ctx context.Context, blueprint ObjectId, node ObjectI
})
return convertTtaeToAceWherePossible(err)
}

func (o *Client) patchNodes(ctx context.Context, blueprint ObjectId, request []interface{}) error {
err := o.talkToApstra(ctx, &talkToApstraIn{
method: http.MethodPatch,
urlStr: fmt.Sprintf(apiUrlBlueprintNodes, blueprint),
apiInput: request,
})
if err != nil {
return convertTtaeToAceWherePossible(err)
}

return nil
}
63 changes: 60 additions & 3 deletions apstra/api_blueprints_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,6 @@ func TestGetNodes(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if err != nil {
t.Fatal(err)
}

log.Printf("got %d nodes. Fetch each one...", len(response.Nodes))
var nodeB node
Expand All @@ -207,3 +204,63 @@ func TestGetNodes(t *testing.T) {
}
}
}

func TestPatchNodes(t *testing.T) {
ctx := context.Background()
clients, err := getTestClients(ctx, t)
if err != nil {
t.Fatal(err)
}

for clientName, client := range clients {
bpClient, bpDel := testBlueprintB(ctx, t, client.client)
defer func() {
err = bpDel(ctx)
if err != nil {
t.Fatal(err)
}
}()

type node struct {
Id ObjectId `json:"id"`
Label string `json:"label"`
SystemType string `json:"system_type,omitempty"`
}

var getResponse struct {
Nodes map[ObjectId]node `json:"nodes"`
}
log.Printf("testing GetNodes() against %s %s (%s)", client.clientType, clientName, client.client.ApiVersion())
err = bpClient.Client().GetNodes(ctx, bpClient.Id(), NodeTypeSystem, &getResponse)
if err != nil {
t.Fatal(err)
}

var patch []interface{}
for k, v := range getResponse.Nodes {
if v.SystemType == "server" {
patch = append(patch, node{
Id: k,
Label: randString(5, "hex"),
})
}
}

err = client.client.PatchNodes(ctx, bpClient.Id(), patch)
if err != nil {
t.Fatal(err)
}

for _, n := range patch {
var result node
err = client.client.GetNode(ctx, bpClient.Id(), n.(node).Id, &result)
if err != nil {
t.Fatal(err)
}

if n.(node).Label != result.Label {
t.Fatalf("patch expected label %s, got label %s", n.(node).Label, result.Label)
}
}
}
}
6 changes: 6 additions & 0 deletions apstra/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,12 @@ func (o *Client) PatchNode(ctx context.Context, blueprint ObjectId, node ObjectI
return o.patchNode(ctx, blueprint, node, request, response)
}

// PatchNodes patches (only submitted fields are changed) nodes described
// using the contents of 'request'.
func (o *Client) PatchNodes(ctx context.Context, blueprint ObjectId, request []interface{}) error {
return o.patchNodes(ctx, blueprint, request)
}

// CreateRackType creates an Apstra Rack Type based on the contents of the
// supplied RackTypeRequest.
// Consistent with the Apstra UI and documentation, logical devices (switches,
Expand Down