-
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.
Add support for configuring cluster virtual IP
Implement cluster virtual IP resource to configure Ipv4 and Ipv6 virtual IP of NSX cluster. Signed-off-by: Shizhao Liu <[email protected]>
- Loading branch information
Shizhao Liu
authored and
root
committed
Aug 30, 2023
1 parent
3f7ab1e
commit d46b2e1
Showing
21 changed files
with
2,632 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,113 @@ | ||
/* Copyright © 2023 VMware, Inc. All Rights Reserved. | ||
SPDX-License-Identifier: MPL-2.0 */ | ||
|
||
package nsxt | ||
|
||
import ( | ||
"fmt" | ||
|
||
"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/cluster" | ||
nsxModel "github.com/vmware/vsphere-automation-sdk-go/services/nsxt-mp/nsx/model" | ||
) | ||
|
||
var ClusterVirtualIPForceType = []string{ | ||
nsxModel.ClusterVirtualIpProperties_FORCE_TRUE, | ||
nsxModel.ClusterVirtualIpProperties_FORCE_FALSE, | ||
} | ||
|
||
var DefaultIPv4VirtualAddress string = "0.0.0.0" | ||
|
||
var DefaultIPv6VirtualAddress string = "::" | ||
|
||
func resourceNsxtClusterVirualIP() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceNsxtClusterVirualIPCreate, | ||
Read: resourceNsxtClusterVirualIPRead, | ||
Update: resourceNsxtClusterVirualIPUpdate, | ||
Delete: resourceNsxtClusterVirualIPDelete, | ||
Importer: &schema.ResourceImporter{ | ||
State: schema.ImportStatePassthrough, | ||
}, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"force": { | ||
Type: schema.TypeString, | ||
Description: "On enable it ignores duplicate address detection and DNS lookup validation check", | ||
Optional: true, | ||
ValidateFunc: validation.StringInSlice(ClusterVirtualIPForceType, false), | ||
Default: nsxModel.ClusterVirtualIpProperties_FORCE_FALSE, | ||
}, | ||
"ip_address": { | ||
Type: schema.TypeString, | ||
Description: "Virtual IPv4 address", | ||
Optional: true, | ||
ValidateFunc: validation.IsIPv4Address, | ||
Default: DefaultIPv4VirtualAddress, | ||
}, | ||
"ipv6_address": { | ||
Type: schema.TypeString, | ||
Description: "IP address of the cluster node that will join the cluster of the host node", | ||
Optional: true, | ||
ValidateFunc: validation.IsIPv6Address, | ||
Default: DefaultIPv6VirtualAddress, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceNsxtClusterVirualIPCreate(d *schema.ResourceData, m interface{}) error { | ||
// Virtual IP is a property of the cluster and does not have its NSX ID | ||
// For create and update we can use the same client function setvirtual IP | ||
return resourceNsxtClusterVirualIPUpdate(d, m) | ||
} | ||
|
||
func resourceNsxtClusterVirualIPRead(d *schema.ResourceData, m interface{}) error { | ||
connector := getPolicyConnector(m) | ||
client := cluster.NewApiVirtualIpClient(connector) | ||
|
||
obj, err := client.Get() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
d.Set("force", obj.Force) | ||
d.Set("ip_address", obj.IpAddress) | ||
d.Set("ipv6_address", obj.Ip6Address) | ||
|
||
return nil | ||
} | ||
|
||
func resourceNsxtClusterVirualIPUpdate(d *schema.ResourceData, m interface{}) error { | ||
|
||
id := d.Id() | ||
if id == "" { | ||
id = newUUID() | ||
} | ||
connector := getPolicyConnector(m) | ||
client := cluster.NewApiVirtualIpClient(connector) | ||
force := d.Get("force").(string) | ||
ipAddress := d.Get("ip_address").(string) | ||
ipv6Address := d.Get("ipv6_address").(string) | ||
_, err := client.Setvirtualip(&force, &ipv6Address, &ipAddress) | ||
if err != nil { | ||
return fmt.Errorf("Failed to set cluster virtual ip: %s", err) | ||
} | ||
d.SetId(id) | ||
return resourceNsxtClusterVirualIPRead(d, m) | ||
} | ||
|
||
func resourceNsxtClusterVirualIPDelete(d *schema.ResourceData, m interface{}) error { | ||
connector := getPolicyConnector(m) | ||
client := cluster.NewApiVirtualIpClient(connector) | ||
_, err := client.Clearvirtualip() | ||
if err != nil { | ||
return fmt.Errorf("Failed to clear cluster virtual IPv4 address: %s", err) | ||
} | ||
_, err = client.Clearvirtualip6() | ||
if err != nil { | ||
return fmt.Errorf("Failed to clear cluster virtual IPv6 address: %s", err) | ||
} | ||
return nil | ||
} |
182 changes: 182 additions & 0 deletions
182
...com/vmware/vsphere-automation-sdk-go/services/nsxt-mp/nsx/cluster/ApiCertificateClient.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.