Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VM IPv6 support #694

Merged
merged 6 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changes/v2.26.0/694-improvements.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Improve `types.NetworkConnection` structure to support VM Secondary IP allocations (IPv6) [GH-694]
1 change: 1 addition & 0 deletions govcd/api_vcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ type TestConfig struct {
NsxtEdgeCluster string `yaml:"nsxtEdgeCluster"`
RoutedNetwork string `yaml:"routedNetwork"`
IsolatedNetwork string `yaml:"isolatedNetwork"`
DualStackNetwork string `yaml:"dualStackNetwork"`
NsxtAlbControllerUrl string `yaml:"nsxtAlbControllerUrl"`
NsxtAlbControllerUser string `yaml:"nsxtAlbControllerUser"`
NsxtAlbControllerPassword string `yaml:"nsxtAlbControllerPassword"`
Expand Down
115 changes: 115 additions & 0 deletions govcd/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2350,3 +2350,118 @@ func testVmExtraConfig(vcd *TestVCD, label string, vm *VM, check *C, wantPowerOn
check.Assert(containsKey(afterDeleteXtraConfig, configWithValidKey.Key), Equals, false)
check.Assert(containsKey(afterDeleteXtraConfig, configSimilar.Key), Equals, false)
}

func (vcd *TestVCD) Test_VmDualStackIPv6(check *C) {
config := vcd.config
if config.VCD.Nsxt.DualStackNetwork == "" {
check.Skip("Skipping test because no dual stack network was given")
}

vapp, err := deployVappWithOrgVdcNetwork(check.TestName(), config.VCD.Nsxt.DualStackNetwork, vcd.nsxtVdc)
check.Assert(err, IsNil)
check.Assert(vapp, NotNil)

desiredNetConfig := &types.NetworkConnectionSection{}
desiredNetConfig.PrimaryNetworkConnectionIndex = 0
desiredNetConfig.NetworkConnection = append(desiredNetConfig.NetworkConnection,
&types.NetworkConnection{
NetworkConnectionIndex: 0,
NetworkAdapterType: "VMXNET3",
IsConnected: true,
IPAddressAllocationMode: types.IPAllocationModePool,
IpType: "IPV4",
Network: config.VCD.Nsxt.DualStackNetwork,
SecondaryIpAddressAllocationMode: types.IPAllocationModePool,
SecondaryIpType: "IPV6",
},
&types.NetworkConnection{
IsConnected: true,
IPAddressAllocationMode: types.IPAllocationModeNone,
Network: types.NoneNetwork,
NetworkConnectionIndex: 1,
})

newDisk := types.DiskSettings{
AdapterType: "5",
SizeMb: int64(16384),
BusNumber: 0,
UnitNumber: 0,
ThinProvisioned: addrOf(true),
OverrideVmDefault: true}

requestDetails := &types.RecomposeVAppParamsForEmptyVm{
CreateItem: &types.CreateItem{
Name: check.TestName(),
NetworkConnectionSection: desiredNetConfig,
GuestCustomizationSection: nil,
VmSpecSection: &types.VmSpecSection{
Modified: addrOf(true),
Info: "Virtual Machine specification",
OsType: "debian10Guest",
NumCpus: addrOf(2),
NumCoresPerSocket: addrOf(1),
CpuResourceMhz: &types.CpuResourceMhz{Configured: 1},
MemoryResourceMb: &types.MemoryResourceMb{Configured: 1024},
DiskSection: &types.DiskSection{DiskSettings: []*types.DiskSettings{&newDisk}},
HardwareVersion: &types.HardwareVersion{Value: "vmx-13"},
VmToolsVersion: "",
VirtualCpuType: "VM32",
TimeSyncWithHost: nil,
},
},
AllEULAsAccepted: true,
}

createdVm, err := vapp.AddEmptyVm(requestDetails)
check.Assert(err, IsNil)
check.Assert(createdVm, NotNil)

// Ensure network config was valid
actualNetConfig, err := createdVm.GetNetworkConnectionSection()
check.Assert(err, IsNil)

check.Assert(len(actualNetConfig.NetworkConnection) > 0, Equals, true)
check.Assert(strings.HasPrefix(actualNetConfig.NetworkConnection[0].SecondaryIpAddress, "2002:0:0:1234:abcd:ffff:a0a6"), Equals, true)
check.Assert(actualNetConfig.NetworkConnection[0].SecondaryIpAddressAllocationMode, Equals, "POOL")

// Cleanup
err = vapp.RemoveVM(*createdVm)
check.Assert(err, IsNil)

// Ensure network is detached from vApp to avoid conflicts in other tests
task, err := vapp.RemoveAllNetworks()
check.Assert(err, IsNil)
err = task.WaitTaskCompletion()
check.Assert(err, IsNil)
task, err = vapp.Delete()
check.Assert(err, IsNil)
err = task.WaitTaskCompletion()
check.Assert(err, IsNil)
check.Assert(task.Task.Status, Equals, "success")
}

func deployVappWithOrgVdcNetwork(vappName, orgNetworkName string, vdc *Vdc) (*VApp, error) {
// Populate OrgVDCNetwork
net, err := vdc.GetOrgVdcNetworkByName(orgNetworkName, false)
if err != nil {
return nil, fmt.Errorf("error finding network : %s", err)
}

// Create empty vApp
vapp, err := vdc.CreateRawVApp(vappName, "description")
if err != nil {
return nil, fmt.Errorf("error creating vapp: %s", err)
Didainius marked this conversation as resolved.
Show resolved Hide resolved
}

// After a successful creation, the entity is added to the cleanup list.
// If something fails after this point, the entity will be removed
AddToCleanupList(vappName, "vapp", "", "createTestVapp")

// Create vApp networking
_, err = vapp.AddOrgNetwork(&VappNetworkSettings{}, net.OrgVDCNetwork, false)
if err != nil {
return nil, fmt.Errorf("error creating vApp network. %s", err)
}

return vapp, nil
}
23 changes: 14 additions & 9 deletions types/v56/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,16 +318,21 @@ func (n NetworkConfigSection) NetworkNames() []string {
// Namespace: http://www.vmware.com/vcloud/v1.5
// Description: Represents a network connection in the virtual machine.
// Since: 0.9
// Note. Order of fields does matter and shuffling it might cause API errors
type NetworkConnection struct {
Network string `xml:"network,attr"` // Name of the network to which this NIC is connected.
NeedsCustomization bool `xml:"needsCustomization,attr,omitempty"` // True if this NIC needs customization.
NetworkConnectionIndex int `xml:"NetworkConnectionIndex"` // Virtual slot number associated with this NIC. First slot number is 0.
IPAddress string `xml:"IpAddress,omitempty"` // IP address assigned to this NIC.
ExternalIPAddress string `xml:"ExternalIpAddress,omitempty"` // If the network to which this NIC connects provides NAT services, the external address assigned to this NIC appears here.
IsConnected bool `xml:"IsConnected"` // If the virtual machine is undeployed, this value specifies whether the NIC should be connected upon deployment. If the virtual machine is deployed, this value reports the current status of this NIC's connection, and can be updated to change that connection status.
MACAddress string `xml:"MACAddress,omitempty"` // MAC address associated with the NIC.
IPAddressAllocationMode string `xml:"IpAddressAllocationMode"` // IP address allocation mode for this connection. One of: POOL (A static IP address is allocated automatically from a pool of addresses.) DHCP (The IP address is obtained from a DHCP service.) MANUAL (The IP address is assigned manually in the IpAddress element.) NONE (No IP addressing mode specified.)
NetworkAdapterType string `xml:"NetworkAdapterType,omitempty"`
Network string `xml:"network,attr"` // Name of the network to which this NIC is connected.
NeedsCustomization bool `xml:"needsCustomization,attr,omitempty"` // True if this NIC needs customization.
NetworkConnectionIndex int `xml:"NetworkConnectionIndex"` // Virtual slot number associated with this NIC. First slot number is 0.
IPAddress string `xml:"IpAddress,omitempty"` // IP address assigned to this NIC.
IpType string `xml:"IpType,omitempty"` // IPv4
SecondaryIpAddress string `xml:"SecondaryIpAddress,omitempty"`
SecondaryIpType string `xml:"SecondaryIpType,omitempty"` // IPv6
IsConnected bool `xml:"IsConnected"` // If the virtual machine is undeployed, this value specifies whether the NIC should be connected upon deployment. If the virtual machine is deployed, this value reports the current status of this NIC's connection, and can be updated to change that connection status.
MACAddress string `xml:"MACAddress,omitempty"` // MAC address associated with the NIC.
IPAddressAllocationMode string `xml:"IpAddressAllocationMode"` // IP address allocation mode for this connection. One of: POOL (A static IP address is allocated automatically from a pool of addresses.) DHCP (The IP address is obtained from a DHCP service.) MANUAL (The IP address is assigned manually in the IpAddress element.) NONE (No IP addressing mode specified.)
SecondaryIpAddressAllocationMode string `xml:"SecondaryIpAddressAllocationMode,omitempty"`
NetworkAdapterType string `xml:"NetworkAdapterType,omitempty"`
ExternalIPAddress string `xml:"ExternalIpAddress,omitempty"` // If the network to which this NIC connects provides NAT services, the external address assigned to this NIC appears here.
}

// NetworkConnectionSection the container for the network connections of this virtual machine.
Expand Down
Loading