-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement ODS runbook report data source
Signed-off-by: Kobi Samoray <[email protected]>
- Loading branch information
Showing
4 changed files
with
255 additions
and
71 deletions.
There are no files selected for viewing
103 changes: 103 additions & 0 deletions
103
nsxt/data_source_nsxt_policy_ods_runbook_invocation_report.go
This file contains 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,103 @@ | ||
/* Copyright © 2023 VMware, Inc. All Rights Reserved. | ||
SPDX-License-Identifier: MPL-2.0 */ | ||
|
||
package nsxt | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/sha/runbook_invocations" | ||
) | ||
|
||
func dataSourceNsxtPolicyODSRunbookInvocationReport() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceNsxtPolicyODSPRunbookInvocationReportRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"invocation_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "UUID of runbook invocation", | ||
}, | ||
"target_node": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Optional: true, | ||
Description: "Identifier of an appliance node or transport node", | ||
}, | ||
"error_detail": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Optional: true, | ||
Description: "The report error detail", | ||
}, | ||
"invalid_reason": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Optional: true, | ||
Description: "Invalid report reason", | ||
}, | ||
"recommendation_code": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Optional: true, | ||
Description: "Online Diagnostic System recommendation code", | ||
}, | ||
"recommendation_message": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Optional: true, | ||
Description: "Online Diagnostic System recommendation message", | ||
}, | ||
"result_code": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Optional: true, | ||
Description: "Online Diagnostic System result code", | ||
}, | ||
"result_message": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Optional: true, | ||
Description: "Online Diagnostic System result message", | ||
}, | ||
"request_status": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Optional: true, | ||
Description: "Request status of a runbook invocation", | ||
}, | ||
"operation_state": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Optional: true, | ||
Description: "Operation state of a runbook invocation on the target node", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceNsxtPolicyODSPRunbookInvocationReportRead(d *schema.ResourceData, m interface{}) error { | ||
connector := getPolicyConnector(m) | ||
invocationID := d.Get("invocation_id").(string) | ||
client := runbook_invocations.NewReportClient(connector) | ||
|
||
obj, err := client.Get(invocationID) | ||
if err != nil { | ||
return handleDataSourceReadError(d, "OdsRunbookInvocationReport", invocationID, err) | ||
} | ||
|
||
d.SetId(invocationID) | ||
d.Set("target_node", obj.TargetNode) | ||
d.Set("error_detail", obj.ErrorDetail) | ||
d.Set("invalid_reason", obj.InvalidReason) | ||
d.Set("recommendation_code", obj.RecommendationCode) | ||
d.Set("recommendation_message", obj.RecommendationMessage) | ||
d.Set("result_code", obj.ResultCode) | ||
d.Set("result_message", obj.ResultMessage) | ||
if obj.Status != nil { | ||
d.Set("request_status", obj.Status.RequestStatus) | ||
d.Set("operation_state", obj.Status.OperationState) | ||
} | ||
|
||
return nil | ||
} |
43 changes: 43 additions & 0 deletions
43
nsxt/data_source_nsxt_policy_ods_runbook_invocation_report_test.go
This file contains 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,43 @@ | ||
/* Copyright © 2023 VMware, Inc. All Rights Reserved. | ||
SPDX-License-Identifier: MPL-2.0 */ | ||
|
||
package nsxt | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccResourceNsxtPolicyODSRunbookInvocationReport_basic(t *testing.T) { | ||
name := getAccTestResourceName() | ||
testResourceName := "data.nsxt_policy_ods_runbook_invocation_report.test" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { | ||
testAccOnlyLocalManager(t) | ||
testAccPreCheck(t) | ||
testAccNSXVersion(t, "4.1.1") | ||
testAccEnvDefined(t, "NSXT_TEST_HOST_TRANSPORT_NODE") | ||
}, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccNsxtPolicyODSRunbookInvocationReportReadTemplate(name), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet(testResourceName, "target_node"), | ||
resource.TestCheckResourceAttrSet(testResourceName, "request_status"), | ||
resource.TestCheckResourceAttrSet(testResourceName, "operation_state"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccNsxtPolicyODSRunbookInvocationReportReadTemplate(name string) string { | ||
return testAccNsxtPolicyODSRunbookInvocationCreateTemplate(name, "ControllerConn", "") + fmt.Sprintf(` | ||
data "nsxt_policy_ods_runbook_invocation_report" "test" { | ||
invocation_id = nsxt_policy_ods_runbook_invocation.test.id | ||
}`) | ||
} |
This file contains 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
37 changes: 37 additions & 0 deletions
37
website/docs/d/policy_ods_runbook_invocation_report.html.markdown
This file contains 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,37 @@ | ||
--- | ||
subcategory: "ODS Runbook" | ||
layout: "nsxt" | ||
page_title: "NSXT: nsxt_policy_ods_runbook_invocation_report" | ||
description: Policy ODS runbook invocation report data source. | ||
--- | ||
|
||
# nsxt_policy_ods_runbook_invocation_report | ||
|
||
This data source provides information about policy ODS runbook invocation report on NSX. | ||
This data source is applicable to NSX Policy Manager. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "nsxt_policy_ods_runbook_invocation_report" "test" { | ||
invocation_id = nsxt_policy_ods_runbook_invocation.test.id | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `invocation_id` - (Required) UUID of runbook invocation. | ||
|
||
## Attributes Reference | ||
|
||
In addition to arguments listed above, the following attributes are exported: | ||
|
||
* `target_node` - Identifier of an appliance node or transport node. | ||
* `error_detail` - The report error detail. | ||
* `invalid_reason` - Invalid report reason. | ||
* `recommendation_code` - Online Diagnostic System recommendation code. | ||
* `recommendation_message` - Online Diagnostic System recommendation message. | ||
* `result_code` - Online Diagnostic System result code. | ||
* `result_message` - Online Diagnostic System result message. | ||
* `request_status` - Request status of a runbook invocation. | ||
* `operation_state` - Operation state of a runbook invocation on the target node. |