Skip to content

Commit

Permalink
Implement ODS runbook report data source
Browse files Browse the repository at this point in the history
Signed-off-by: Kobi Samoray <ksamoray@vmware.com>
  • Loading branch information
ksamoray committed Apr 2, 2024
1 parent 2546fb7 commit f1e185c
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 0 deletions.
103 changes: 103 additions & 0 deletions nsxt/data_source_nsxt_policy_ods_runbook_invocation_report.go
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 nsxt/data_source_nsxt_policy_ods_runbook_invocation_report_test.go
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.2.0")
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(`

Check failure on line 39 in nsxt/data_source_nsxt_policy_ods_runbook_invocation_report_test.go

View workflow job for this annotation

GitHub Actions / lint

S1039: unnecessary use of fmt.Sprintf (gosimple)
data "nsxt_policy_ods_runbook_invocation_report" "test" {
invocation_id = nsxt_policy_ods_runbook_invocation.test.id
}`)
}
1 change: 1 addition & 0 deletions nsxt/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ func Provider() *schema.Provider {
"nsxt_upgrade_prepare_ready": dataSourceNsxtUpgradePrepareReady(),
"nsxt_policy_vtep_ha_host_switch_profile": dataSourceNsxtVtepHAHostSwitchProfile(),
"nsxt_policy_ods_pre_defined_runbook": dataSourceNsxtPolicyODSPreDefinedRunbook(),
"nsxt_policy_ods_runbook_invocation_report": dataSourceNsxtPolicyODSRunbookInvocationReport(),
},

ResourcesMap: map[string]*schema.Resource{
Expand Down
37 changes: 37 additions & 0 deletions website/docs/d/policy_ods_runbook_invocation_report.html.markdown
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.

0 comments on commit f1e185c

Please sign in to comment.