-
Notifications
You must be signed in to change notification settings - Fork 6
feat: adding fcp service and fc interface tools #94
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
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
e961d9a
feat: adding fcp service and fc interface tools
Hardikl f41b6ba
feat: handled copilot comments
Hardikl dd159ed
feat: minor change
Hardikl 99bc8d7
feat: handle comment
Hardikl b151955
Merge remote-tracking branch 'origin/main' into hl_fcp
Hardikl c776563
feat: update fcp tools validation
Hardikl c3ba0d1
Merge remote-tracking branch 'origin/main' into hl_fcp
Hardikl 8385939
Merge remote-tracking branch 'origin/main' into hl_fcp
Hardikl 268e588
feat: adding svm clean in tests
Hardikl 8a4a384
feat: sar cluster svm clean tests not supported
Hardikl b40767f
feat: handled copilot comment
Hardikl 61dd3cb
Merge remote-tracking branch 'origin/main' into hl_fcp
Hardikl 7bbd7c4
feat: handled review comments
Hardikl 8359035
Merge remote-tracking branch 'origin/main' into hl_fcp
Hardikl d19ad26
feat: handled review comments
Hardikl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "crypto/tls" | ||
| "log/slog" | ||
| "net/http" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/netapp/ontap-mcp/config" | ||
| ) | ||
|
|
||
| const SarCluster = "sar" | ||
| const SarClusterStr = "On the " + SarCluster + " cluster, " | ||
|
|
||
| func TestFCP(t *testing.T) { | ||
| SkipIfMissing(t, CheckTools) | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| input string | ||
| expectedOntapErr string | ||
| verifyAPI ontapVerifier | ||
| }{ | ||
| { | ||
| name: "Clean FC Interface", | ||
| input: SarClusterStr + "delete fc interface " + rn("fc1") + " in marketing svm", | ||
| expectedOntapErr: "because it does not exist", | ||
| verifyAPI: ontapVerifier{api: "api/network/fc/interfaces?name=" + rn("fc1") + "&svm.name=marketing", validationFunc: deleteObject}, | ||
| }, | ||
| { | ||
| name: "Create FC Interface", | ||
| input: SarClusterStr + "create fc interface " + rn("fc1") + " in marketing svm at port 0e in node umeng-aff300-01 of fcp data protocol", | ||
| expectedOntapErr: "", | ||
| verifyAPI: ontapVerifier{api: "api/network/fc/interfaces?name=" + rn("fc1") + "&svm.name=marketing", validationFunc: createObject}, | ||
| }, | ||
| { | ||
| name: "Update FC Interface", | ||
| input: SarClusterStr + "disable fc interface " + rn("fc1") + " in marketing svm", | ||
| expectedOntapErr: "", | ||
| verifyAPI: ontapVerifier{}, | ||
| }, | ||
| { | ||
| name: "Clean FC Interface", | ||
| input: SarClusterStr + "delete fc interface " + rn("fc1") + " in marketing svm", | ||
| expectedOntapErr: "", | ||
| verifyAPI: ontapVerifier{api: "api/network/fc/interfaces?name=" + rn("fc1") + "&svm.name=marketing", validationFunc: deleteObject}, | ||
| }, | ||
|
Hardikl marked this conversation as resolved.
|
||
| } | ||
|
Hardikl marked this conversation as resolved.
|
||
|
|
||
| cfg, err := config.ReadConfig(ConfigFile) | ||
| if err != nil { | ||
| t.Fatalf("Error parsing the config: %v", err) | ||
| } | ||
|
|
||
| poller := cfg.Pollers[SarCluster] | ||
| if poller == nil { | ||
| t.Skipf("Cluster %q not found in %s, skipping FCP tests", SarCluster, ConfigFile) | ||
| } | ||
| transport := &http.Transport{ | ||
| TLSClientConfig: &tls.Config{ | ||
| InsecureSkipVerify: poller.UseInsecureTLS, // #nosec G402 | ||
| }, | ||
| } | ||
| client := &http.Client{Transport: transport, Timeout: 10 * time.Second} | ||
|
Hardikl marked this conversation as resolved.
|
||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| slog.Debug("", slog.String("Input", tt.input)) | ||
| ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute) | ||
| defer cancel() | ||
| if _, err := testAgent.ChatWithResponse(ctx, t, tt.input, tt.expectedOntapErr); err != nil { | ||
| t.Fatalf("Error processing input %q: %v", tt.input, err) | ||
| } | ||
| if tt.verifyAPI.api != "" && !tt.verifyAPI.validationFunc(t, tt.verifyAPI.api, poller, client) { | ||
| t.Errorf("Error while accessing the object via prompt %q", tt.input) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,196 @@ | ||
| package rest | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "net/http" | ||
| "net/url" | ||
|
|
||
| "github.com/netapp/ontap-mcp/ontap" | ||
| ) | ||
|
|
||
| func (c *Client) CreateFCPService(ctx context.Context, fcpService ontap.FCPService) error { | ||
| var statusCode int | ||
|
|
||
| responseHeaders := http.Header{} | ||
|
|
||
| builder := c.baseRequestBuilder(`/api/protocols/san/fcp/services`, &statusCode, responseHeaders). | ||
| BodyJSON(fcpService) | ||
|
|
||
| if err := c.buildAndExecuteRequest(ctx, builder); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return c.checkStatus(statusCode) | ||
| } | ||
|
|
||
| func (c *Client) UpdateFCPService(ctx context.Context, svmName string, fcpService ontap.FCPService) error { | ||
| var ( | ||
| statusCode int | ||
| fcpSr ontap.GetData | ||
| ) | ||
|
|
||
| responseHeaders := http.Header{} | ||
|
|
||
| params := url.Values{} | ||
| params.Set("svm.name", svmName) | ||
|
|
||
| builder := c.baseRequestBuilder(`/api/protocols/san/fcp/services`, &statusCode, responseHeaders). | ||
| Params(params). | ||
| ToJSON(&fcpSr) | ||
|
|
||
| if err := c.buildAndExecuteRequest(ctx, builder); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if fcpSr.NumRecords == 0 { | ||
| return fmt.Errorf("failed to get detail of fcp service in svm %s because it does not exist", svmName) | ||
| } | ||
|
|
||
| if fcpSr.NumRecords != 1 { | ||
| return fmt.Errorf("failed to get fcp service on svm=%s because there are %d matching records", | ||
| svmName, fcpSr.NumRecords) | ||
| } | ||
|
|
||
| builder = c.baseRequestBuilder(`/api/protocols/san/fcp/services/`+fcpSr.Records[0].Svm.UUID, &statusCode, responseHeaders). | ||
| BodyJSON(fcpService). | ||
| Patch() | ||
|
|
||
| if err := c.buildAndExecuteRequest(ctx, builder); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return c.checkStatus(statusCode) | ||
| } | ||
|
|
||
| func (c *Client) DeleteFCPService(ctx context.Context, svmName string) error { | ||
| var ( | ||
| statusCode int | ||
| fcpSr ontap.GetData | ||
| ) | ||
|
|
||
| responseHeaders := http.Header{} | ||
|
|
||
| params := url.Values{} | ||
| params.Set("svm.name", svmName) | ||
|
|
||
| builder := c.baseRequestBuilder(`/api/protocols/san/fcp/services`, &statusCode, responseHeaders). | ||
| Params(params). | ||
| ToJSON(&fcpSr) | ||
|
|
||
| if err := c.buildAndExecuteRequest(ctx, builder); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if fcpSr.NumRecords == 0 { | ||
| return fmt.Errorf("failed to get detail of fcp service in svm %s because it does not exist", svmName) | ||
| } | ||
|
|
||
| if fcpSr.NumRecords != 1 { | ||
| return fmt.Errorf("failed to get fcp service on svm=%s because there are %d matching records", | ||
| svmName, fcpSr.NumRecords) | ||
| } | ||
|
|
||
| builder = c.baseRequestBuilder(`/api/protocols/san/fcp/services/`+fcpSr.Records[0].Svm.UUID, &statusCode, responseHeaders). | ||
| Delete() | ||
|
|
||
| if err := c.buildAndExecuteRequest(ctx, builder); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return c.checkStatus(statusCode) | ||
| } | ||
|
|
||
| func (c *Client) CreateFCInterface(ctx context.Context, fcInterface ontap.FCInterface) error { | ||
| var statusCode int | ||
|
|
||
| responseHeaders := http.Header{} | ||
|
|
||
| builder := c.baseRequestBuilder(`/api/network/fc/interfaces`, &statusCode, responseHeaders). | ||
| BodyJSON(fcInterface) | ||
|
|
||
| if err := c.buildAndExecuteRequest(ctx, builder); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return c.checkStatus(statusCode) | ||
| } | ||
|
|
||
| func (c *Client) UpdateFCInterface(ctx context.Context, svmName string, name string, fcInterface ontap.FCInterface) error { | ||
| var ( | ||
| statusCode int | ||
| fcIfSr ontap.GetData | ||
| ) | ||
|
|
||
| responseHeaders := http.Header{} | ||
|
|
||
| params := url.Values{} | ||
| params.Set("svm.name", svmName) | ||
| params.Set("name", name) | ||
|
|
||
| builder := c.baseRequestBuilder(`/api/network/fc/interfaces`, &statusCode, responseHeaders). | ||
| Params(params). | ||
| ToJSON(&fcIfSr) | ||
|
|
||
| if err := c.buildAndExecuteRequest(ctx, builder); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if fcIfSr.NumRecords == 0 { | ||
| return fmt.Errorf("failed to get detail of fc interface %s in svm %s because it does not exist", name, svmName) | ||
| } | ||
|
|
||
| if fcIfSr.NumRecords != 1 { | ||
| return fmt.Errorf("failed to get unique fc interface %s in svm=%s because there are %d matching records", | ||
| name, svmName, fcIfSr.NumRecords) | ||
| } | ||
|
Hardikl marked this conversation as resolved.
|
||
|
|
||
| builder = c.baseRequestBuilder(`/api/network/fc/interfaces/`+fcIfSr.Records[0].UUID, &statusCode, responseHeaders). | ||
| BodyJSON(fcInterface). | ||
| Patch() | ||
|
|
||
| if err := c.buildAndExecuteRequest(ctx, builder); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return c.checkStatus(statusCode) | ||
| } | ||
|
|
||
| func (c *Client) DeleteFCInterface(ctx context.Context, svmName string, name string) error { | ||
| var ( | ||
| statusCode int | ||
| fcIfSr ontap.GetData | ||
| ) | ||
|
|
||
| responseHeaders := http.Header{} | ||
|
|
||
| params := url.Values{} | ||
| params.Set("svm.name", svmName) | ||
| params.Set("name", name) | ||
|
|
||
| builder := c.baseRequestBuilder(`/api/network/fc/interfaces`, &statusCode, responseHeaders). | ||
| Params(params). | ||
| ToJSON(&fcIfSr) | ||
|
|
||
| if err := c.buildAndExecuteRequest(ctx, builder); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if fcIfSr.NumRecords == 0 { | ||
| return fmt.Errorf("failed to get detail of fc interface %s in svm %s because it does not exist", name, svmName) | ||
| } | ||
|
|
||
| if fcIfSr.NumRecords != 1 { | ||
| return fmt.Errorf("failed to delete fc interface %s in svm=%s because there are %d matching records", | ||
| name, svmName, fcIfSr.NumRecords) | ||
| } | ||
|
|
||
| builder = c.baseRequestBuilder(`/api/network/fc/interfaces/`+fcIfSr.Records[0].UUID, &statusCode, responseHeaders). | ||
| Delete() | ||
|
|
||
| if err := c.buildAndExecuteRequest(ctx, builder); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return c.checkStatus(statusCode) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.