-
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.
Resource to prepare for NSXT cluster upgrade
Signed-off-by: Shizhao Liu <[email protected]>
- Loading branch information
Shizhao Liu
committed
Jan 16, 2024
1 parent
b8b33d1
commit f179c93
Showing
5 changed files
with
478 additions
and
0 deletions.
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
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,88 @@ | ||
/* 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" | ||
nsxModel "github.com/vmware/vsphere-automation-sdk-go/services/nsxt-mp/nsx/model" | ||
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt-mp/nsx/upgrade" | ||
) | ||
|
||
func resourceNsxtUpgradePrecheckAcknowledge() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceNsxtUpgradePrecheckAcknowledgeCreate, | ||
Read: resourceNsxtUpgradePrecheckAcknowledgeRead, | ||
Update: resourceNsxtUpgradePrecheckAcknowledgeUpdate, | ||
Delete: resourceNsxtUpgradePrecheckAcknowledgeDelete, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"precheck_id": { | ||
Type: schema.TypeList, | ||
Description: "IDs of failed prechecks that user wants to acknowledge before upgrade", | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"id": { | ||
Type: schema.TypeString, | ||
Description: "ID of failed precheck to acknowledge", | ||
Required: true, | ||
}, | ||
}, | ||
}, | ||
Required: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceNsxtUpgradePrecheckAcknowledgeCreate(d *schema.ResourceData, m interface{}) error { | ||
id := d.Id() | ||
if id == "" { | ||
id = newUUID() | ||
} | ||
d.SetId(id) | ||
precheckIDs := interface2StringList(d.Get("precheck_id").([]interface{})) | ||
connector := getPolicyConnector(m) | ||
client := upgrade.NewPreUpgradeChecksClient(connector) | ||
for _, precheckID := range precheckIDs { | ||
err := client.Acknowledge(precheckID) | ||
if err != nil { | ||
return handleCreateError("NsxtUpgradePrecheckAcknowledge", id, err) | ||
} | ||
} | ||
return resourceNsxtUpgradePrecheckAcknowledgeRead(d, m) | ||
} | ||
|
||
func resourceNsxtUpgradePrecheckAcknowledgeRead(d *schema.ResourceData, m interface{}) error { | ||
id := d.Id() | ||
precheckWarnings, err := getPrecheckErrors(m, nsxModel.UpgradeCheckFailure_TYPE_WARNING) | ||
if err != nil { | ||
return handleReadError(d, "NsxtUpgradePrecheckAcknowledge", id, err) | ||
} | ||
err = setAcknowledgedPrecheckIDsInSchema(d, precheckWarnings) | ||
if err != nil { | ||
return handleReadError(d, "NsxtUpgradePrecheckAcknowledge", id, err) | ||
} | ||
return nil | ||
} | ||
|
||
func setAcknowledgedPrecheckIDsInSchema(d *schema.ResourceData, precheckWarnings []nsxModel.UpgradeCheckFailure) error { | ||
var precheckWarningIDs []map[string]interface{} | ||
for _, precheckWarning := range precheckWarnings { | ||
elem := make(map[string]interface{}) | ||
if !(*precheckWarning.NeedsAck) { | ||
id := *precheckWarning.Id | ||
elem["id"] = id | ||
precheckWarningIDs = append(precheckWarningIDs, elem) | ||
} | ||
} | ||
return d.Set("precheck_id", precheckWarningIDs) | ||
} | ||
|
||
func resourceNsxtUpgradePrecheckAcknowledgeUpdate(d *schema.ResourceData, m interface{}) error { | ||
return nil | ||
} | ||
|
||
func resourceNsxtUpgradePrecheckAcknowledgeDelete(d *schema.ResourceData, m interface{}) error { | ||
return nil | ||
} |
Oops, something went wrong.