Skip to content

Commit dd1407e

Browse files
committed
Implement ODS runbook report data source
Signed-off-by: Kobi Samoray <[email protected]>
1 parent 2546fb7 commit dd1407e

4 files changed

+183
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/* Copyright © 2023 VMware, Inc. All Rights Reserved.
2+
SPDX-License-Identifier: MPL-2.0 */
3+
4+
package nsxt
5+
6+
import (
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
8+
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/sha/runbook_invocations"
9+
)
10+
11+
func dataSourceNsxtPolicyODSRunbookInvocationReport() *schema.Resource {
12+
return &schema.Resource{
13+
Read: dataSourceNsxtPolicyODSPRunbookInvocationReportRead,
14+
15+
Schema: map[string]*schema.Schema{
16+
"invocation_id": {
17+
Type: schema.TypeString,
18+
Required: true,
19+
Description: "UUID of runbook invocation",
20+
},
21+
"target_node": {
22+
Type: schema.TypeString,
23+
Computed: true,
24+
Optional: true,
25+
Description: "Identifier of an appliance node or transport node",
26+
},
27+
"error_detail": {
28+
Type: schema.TypeString,
29+
Computed: true,
30+
Optional: true,
31+
Description: "The report error detail",
32+
},
33+
"invalid_reason": {
34+
Type: schema.TypeString,
35+
Computed: true,
36+
Optional: true,
37+
Description: "Invalid report reason",
38+
},
39+
"recommendation_code": {
40+
Type: schema.TypeInt,
41+
Computed: true,
42+
Optional: true,
43+
Description: "Online Diagnostic System recommendation code",
44+
},
45+
"recommendation_message": {
46+
Type: schema.TypeString,
47+
Computed: true,
48+
Optional: true,
49+
Description: "Online Diagnostic System recommendation message",
50+
},
51+
"result_code": {
52+
Type: schema.TypeInt,
53+
Computed: true,
54+
Optional: true,
55+
Description: "Online Diagnostic System result code",
56+
},
57+
"result_message": {
58+
Type: schema.TypeString,
59+
Computed: true,
60+
Optional: true,
61+
Description: "Online Diagnostic System result message",
62+
},
63+
"request_status": {
64+
Type: schema.TypeString,
65+
Computed: true,
66+
Optional: true,
67+
Description: "Request status of a runbook invocation",
68+
},
69+
"operation_state": {
70+
Type: schema.TypeString,
71+
Computed: true,
72+
Optional: true,
73+
Description: "Operation state of a runbook invocation on the target node",
74+
},
75+
},
76+
}
77+
}
78+
79+
func dataSourceNsxtPolicyODSPRunbookInvocationReportRead(d *schema.ResourceData, m interface{}) error {
80+
connector := getPolicyConnector(m)
81+
invocationID := d.Get("invocation_id").(string)
82+
client := runbook_invocations.NewReportClient(connector)
83+
84+
obj, err := client.Get(invocationID)
85+
if err != nil {
86+
return handleDataSourceReadError(d, "OdsRunbookInvocationReport", invocationID, err)
87+
}
88+
89+
d.SetId(invocationID)
90+
d.Set("target_node", obj.TargetNode)
91+
d.Set("error_detail", obj.ErrorDetail)
92+
d.Set("invalid_reason", obj.InvalidReason)
93+
d.Set("recommendation_code", obj.RecommendationCode)
94+
d.Set("recommendation_message", obj.RecommendationMessage)
95+
d.Set("result_code", obj.ResultCode)
96+
d.Set("result_message", obj.ResultMessage)
97+
if obj.Status != nil {
98+
d.Set("request_status", obj.Status.RequestStatus)
99+
d.Set("operation_state", obj.Status.OperationState)
100+
}
101+
102+
return nil
103+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* Copyright © 2023 VMware, Inc. All Rights Reserved.
2+
SPDX-License-Identifier: MPL-2.0 */
3+
4+
package nsxt
5+
6+
import (
7+
"testing"
8+
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
10+
)
11+
12+
func TestAccResourceNsxtPolicyODSRunbookInvocationReport_basic(t *testing.T) {
13+
name := getAccTestResourceName()
14+
testResourceName := "data.nsxt_policy_ods_runbook_invocation_report.test"
15+
16+
resource.ParallelTest(t, resource.TestCase{
17+
PreCheck: func() {
18+
testAccOnlyLocalManager(t)
19+
testAccPreCheck(t)
20+
testAccNSXVersion(t, "4.2.0")
21+
testAccEnvDefined(t, "NSXT_TEST_HOST_TRANSPORT_NODE")
22+
},
23+
Providers: testAccProviders,
24+
Steps: []resource.TestStep{
25+
{
26+
Config: testAccNsxtPolicyODSRunbookInvocationReportReadTemplate(name),
27+
Check: resource.ComposeTestCheckFunc(
28+
resource.TestCheckResourceAttrSet(testResourceName, "target_node"),
29+
resource.TestCheckResourceAttrSet(testResourceName, "request_status"),
30+
resource.TestCheckResourceAttrSet(testResourceName, "operation_state"),
31+
),
32+
},
33+
},
34+
})
35+
}
36+
37+
func testAccNsxtPolicyODSRunbookInvocationReportReadTemplate(name string) string {
38+
return testAccNsxtPolicyODSRunbookInvocationCreateTemplate(name, "ControllerConn", "") + `
39+
data "nsxt_policy_ods_runbook_invocation_report" "test" {
40+
invocation_id = nsxt_policy_ods_runbook_invocation.test.id
41+
}`
42+
}

Diff for: nsxt/provider.go

+1
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ func Provider() *schema.Provider {
323323
"nsxt_upgrade_prepare_ready": dataSourceNsxtUpgradePrepareReady(),
324324
"nsxt_policy_vtep_ha_host_switch_profile": dataSourceNsxtVtepHAHostSwitchProfile(),
325325
"nsxt_policy_ods_pre_defined_runbook": dataSourceNsxtPolicyODSPreDefinedRunbook(),
326+
"nsxt_policy_ods_runbook_invocation_report": dataSourceNsxtPolicyODSRunbookInvocationReport(),
326327
},
327328

328329
ResourcesMap: map[string]*schema.Resource{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
subcategory: "ODS Runbook"
3+
layout: "nsxt"
4+
page_title: "NSXT: nsxt_policy_ods_runbook_invocation_report"
5+
description: Policy ODS runbook invocation report data source.
6+
---
7+
8+
# nsxt_policy_ods_runbook_invocation_report
9+
10+
This data source provides information about policy ODS runbook invocation report on NSX.
11+
This data source is applicable to NSX Policy Manager.
12+
13+
## Example Usage
14+
15+
```hcl
16+
data "nsxt_policy_ods_runbook_invocation_report" "test" {
17+
invocation_id = nsxt_policy_ods_runbook_invocation.test.id
18+
}
19+
```
20+
21+
## Argument Reference
22+
23+
* `invocation_id` - (Required) UUID of runbook invocation.
24+
25+
## Attributes Reference
26+
27+
In addition to arguments listed above, the following attributes are exported:
28+
29+
* `target_node` - Identifier of an appliance node or transport node.
30+
* `error_detail` - The report error detail.
31+
* `invalid_reason` - Invalid report reason.
32+
* `recommendation_code` - Online Diagnostic System recommendation code.
33+
* `recommendation_message` - Online Diagnostic System recommendation message.
34+
* `result_code` - Online Diagnostic System result code.
35+
* `result_message` - Online Diagnostic System result message.
36+
* `request_status` - Request status of a runbook invocation.
37+
* `operation_state` - Operation state of a runbook invocation on the target node.

0 commit comments

Comments
 (0)