-
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.
Transport node realization data source
Realization data source for nsxt_transport_node resource. Signed-off-by: Kobi Samoray <[email protected]>
- Loading branch information
Showing
20 changed files
with
1,985 additions
and
1 deletion.
There are no files selected for viewing
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,96 @@ | ||
/* Copyright © 2023 VMware, Inc. All Rights Reserved. | ||
SPDX-License-Identifier: MPL-2.0 */ | ||
|
||
package nsxt | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"time" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" | ||
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt-mp/nsx/model" | ||
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt-mp/nsx/transport_nodes" | ||
) | ||
|
||
func dataSourceNsxtTransportNodeRealization() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceNsxtTransportNodeRealizationRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "Unique ID of this resource", | ||
}, | ||
"timeout": { | ||
Type: schema.TypeInt, | ||
Description: "Realization timeout in seconds", | ||
Optional: true, | ||
Default: 1200, | ||
ValidateFunc: validation.IntAtLeast(1), | ||
}, | ||
"delay": { | ||
Type: schema.TypeInt, | ||
Description: "Initial delay to start realization checks in seconds", | ||
Optional: true, | ||
Default: 1, | ||
ValidateFunc: validation.IntAtLeast(0), | ||
}, | ||
"state": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Overall state of desired configuration", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceNsxtTransportNodeRealizationRead(d *schema.ResourceData, m interface{}) error { | ||
connector := getPolicyConnector(m) | ||
client := transport_nodes.NewStateClient(connector) | ||
|
||
id := d.Get("id").(string) | ||
delay := d.Get("delay").(int) | ||
timeout := d.Get("timeout").(int) | ||
|
||
pendingStates := []string{ | ||
model.TransportNodeState_STATE_PENDING, | ||
model.TransportNodeState_STATE_IN_PROGRESS, | ||
model.TransportNodeState_STATE_IN_SYNC, | ||
model.TransportNodeState_STATE_UNKNOWN, | ||
} | ||
targetStates := []string{ | ||
model.TransportNodeState_STATE_SUCCESS, | ||
model.TransportNodeState_STATE_FAILED, | ||
model.TransportNodeState_STATE_PARTIAL_SUCCESS, | ||
model.TransportNodeState_STATE_ORPHANED, | ||
model.TransportNodeState_STATE_ERROR, | ||
} | ||
stateConf := &resource.StateChangeConf{ | ||
Pending: pendingStates, | ||
Target: targetStates, | ||
Refresh: func() (interface{}, string, error) { | ||
state, err := client.Get(id) | ||
if err != nil { | ||
return state, model.TransportNodeState_STATE_ERROR, logAPIError("Error while waiting for realization of transport node", err) | ||
} | ||
|
||
log.Printf("[DEBUG] Current realization state for Transport Node %s is %s", id, *state.State) | ||
|
||
d.Set("state", state.State) | ||
return state, *state.State, nil | ||
}, | ||
Timeout: time.Duration(timeout) * time.Second, | ||
MinTimeout: 1 * time.Second, | ||
Delay: time.Duration(delay) * time.Second, | ||
} | ||
_, err := stateConf.WaitForState() | ||
if err != nil { | ||
return fmt.Errorf("failed to get realization information for %s: %v", id, err) | ||
} | ||
|
||
return nil | ||
} |
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
91 changes: 91 additions & 0 deletions
91
...ware/vsphere-automation-sdk-go/services/nsxt-mp/nsx/transport_nodes/CapabilitiesClient.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
69 changes: 69 additions & 0 deletions
69
...mware/vsphere-automation-sdk-go/services/nsxt-mp/nsx/transport_nodes/CapabilitiesTypes.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
94 changes: 94 additions & 0 deletions
94
...om/vmware/vsphere-automation-sdk-go/services/nsxt-mp/nsx/transport_nodes/ModulesClient.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.