Skip to content

Commit

Permalink
IP Space integration (#579)
Browse files Browse the repository at this point in the history
  • Loading branch information
Didainius authored Jul 13, 2023
1 parent e160052 commit 3b9ce5d
Show file tree
Hide file tree
Showing 18 changed files with 1,373 additions and 18 deletions.
13 changes: 13 additions & 0 deletions .changes/v2.21.0/579-features.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
* Added IP Space Uplink CRUD support via `IpSpaceUplink` and `types.IpSpaceUplink` and
`VCDClient.CreateIpSpaceUplink`, `VCDClient.GetAllIpSpaceUplinks`,
`VCDClient.GetIpSpaceUplinkById`, `VCDClient.GetIpSpaceUplinkByName`, `IpSpaceUplink.Update`,
`IpSpaceUplink.Delete` [GH-579]
* Added IP Space Allocation CRUD support via `IpSpaceIpAllocation`, `types.IpSpaceIpAllocation`,
`types.IpSpaceIpAllocationRequest`, `types.IpSpaceIpAllocationRequestResult`. Methods
`IpSpace.AllocateIp`, `Org.IpSpaceAllocateIp`, `Org.GetIpSpaceAllocationByTypeAndValue`,
`IpSpace.GetAllIpSpaceAllocations`, `Org.GetIpSpaceAllocationById`, `IpSpaceIpAllocation.Update`,
`IpSpaceIpAllocation.Delete` [GH-579]
* Added IP Space Org assignment to support Custom Quotas via `IpSpaceOrgAssignment`,
`types.IpSpaceOrgAssignment`, `IpSpace.GetAllOrgAssignments`, `IpSpace.GetOrgAssignmentById`,
`IpSpace.GetOrgAssignmentByOrgName`, `IpSpace.GetOrgAssignmentByOrgId`,
`IpSpaceOrgAssignment.Update` [GH-579]
2 changes: 2 additions & 0 deletions .changes/v2.21.0/579-improvements.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* `ExternalNetworkV2` now supports IP Spaces on VCD 10.4.1+ with new fields `UsingIpSpace` and
`DedicatedOrg` [GH-579]
57 changes: 49 additions & 8 deletions govcd/external_network_v2_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build extnetwork || network || functional || openapi || ALL
//go:build extnetwork || network || nsxt || functional || openapi || ALL

/*
* Copyright 2020 VMware, Inc. All rights reserved. Licensed under the Apache v2 License.
Expand All @@ -14,18 +14,21 @@ import (
)

func (vcd *TestVCD) Test_CreateExternalNetworkV2Nsxt(check *C) {
vcd.testCreateExternalNetworkV2Nsxt(check, vcd.config.VCD.Nsxt.Tier0router, types.ExternalNetworkBackingTypeNsxtTier0Router)
vcd.testCreateExternalNetworkV2Nsxt(check, vcd.config.VCD.Nsxt.Tier0router, types.ExternalNetworkBackingTypeNsxtTier0Router, false, "")
}

func (vcd *TestVCD) Test_CreateExternalNetworkV2NsxtVrf(check *C) {
vcd.testCreateExternalNetworkV2Nsxt(check, vcd.config.VCD.Nsxt.Tier0routerVrf, types.ExternalNetworkBackingTypeNsxtTier0Router)
vcd.testCreateExternalNetworkV2Nsxt(check, vcd.config.VCD.Nsxt.Tier0routerVrf, types.ExternalNetworkBackingTypeNsxtTier0Router, false, "")
}

func (vcd *TestVCD) Test_CreateExternalNetworkV2NsxtSegment(check *C) {
vcd.testCreateExternalNetworkV2Nsxt(check, vcd.config.VCD.Nsxt.NsxtImportSegment, types.ExternalNetworkBackingTypeNsxtSegment)
vcd.testCreateExternalNetworkV2Nsxt(check, vcd.config.VCD.Nsxt.NsxtImportSegment, types.ExternalNetworkBackingTypeNsxtSegment, false, "")
}

func (vcd *TestVCD) testCreateExternalNetworkV2Nsxt(check *C, backingName, backingType string) {
func (vcd *TestVCD) testCreateExternalNetworkV2Nsxt(check *C, backingName, backingType string, useIpSpace bool, ownerOrgId string) {
if vcd.skipAdminTests {
check.Skip(fmt.Sprintf(TestRequiresSysAdminPrivileges, check.TestName()))
}
endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointExternalNetworks
skipOpenApiEndpointTest(vcd, check, endpoint)
skipNoNsxtConfiguration(vcd, check)
Expand All @@ -41,7 +44,7 @@ func (vcd *TestVCD) testCreateExternalNetworkV2Nsxt(check *C, backingName, backi
backingId := getBackingIdByNameAndType(check, backingName, backingType, vcd, nsxtManagerId)

// Create network and test CRUD capabilities
netNsxt := testExternalNetworkV2(vcd, check.TestName(), backingType, backingId, nsxtManagerId)
netNsxt := testExternalNetworkV2(vcd, check.TestName(), backingType, backingId, nsxtManagerId, useIpSpace, ownerOrgId)
createdNet, err := CreateExternalNetworkV2(vcd.client, netNsxt)
check.Assert(err, IsNil)

Expand Down Expand Up @@ -128,7 +131,7 @@ func (vcd *TestVCD) Test_CreateExternalNetworkV2Nsxv(check *C) {
vcUrn, err := BuildUrnWithUuid("urn:vcloud:vimserver:", vcUuid)
check.Assert(err, IsNil)

net := testExternalNetworkV2(vcd, check.TestName(), vcd.config.VCD.ExternalNetworkPortGroupType, pgs[0].MoRef, vcUrn)
net := testExternalNetworkV2(vcd, check.TestName(), vcd.config.VCD.ExternalNetworkPortGroupType, pgs[0].MoRef, vcUrn, false, "")

r, err := CreateExternalNetworkV2(vcd.client, net)
check.Assert(err, IsNil)
Expand All @@ -146,7 +149,7 @@ func (vcd *TestVCD) Test_CreateExternalNetworkV2Nsxv(check *C) {
check.Assert(err, IsNil)
}

func testExternalNetworkV2(vcd *TestVCD, name, backingType, backingId, NetworkProviderId string) *types.ExternalNetworkV2 {
func testExternalNetworkV2(vcd *TestVCD, name, backingType, backingId, NetworkProviderId string, useIpSpace bool, ownerOrgId string) *types.ExternalNetworkV2 {
net := &types.ExternalNetworkV2{
ID: "",
Name: name,
Expand Down Expand Up @@ -180,9 +183,47 @@ func testExternalNetworkV2(vcd *TestVCD, name, backingType, backingId, NetworkPr
}},
}

if useIpSpace {
// removing subnet definition when using IP Spaces
net.Subnets = types.ExternalNetworkV2Subnets{}
net.UsingIpSpace = &useIpSpace
}

if ownerOrgId != "" {
net.DedicatedOrg = &types.OpenApiReference{ID: ownerOrgId}
}

return net
}

func (vcd *TestVCD) Test_CreateExternalNetworkV2NsxtIpSpaceT0(check *C) {
if vcd.client.Client.APIVCDMaxVersionIs("< 37.1") {
check.Skip("IP Spaces are supported in VCD 10.4.1+")
}
vcd.testCreateExternalNetworkV2Nsxt(check, vcd.config.VCD.Nsxt.Tier0router, types.ExternalNetworkBackingTypeNsxtTier0Router, true, "")
}

func (vcd *TestVCD) Test_CreateExternalNetworkV2NsxtIpSpaceVrf(check *C) {
if vcd.client.Client.APIVCDMaxVersionIs("< 37.1") {
check.Skip("IP Spaces are supported in VCD 10.4.1+")
}
vcd.testCreateExternalNetworkV2Nsxt(check, vcd.config.VCD.Nsxt.Tier0routerVrf, types.ExternalNetworkBackingTypeNsxtTier0Router, true, "")
}

func (vcd *TestVCD) Test_CreateExternalNetworkV2NsxtIpSpaceT0DedicatedOrg(check *C) {
if vcd.client.Client.APIVCDMaxVersionIs("< 37.1") {
check.Skip("IP Spaces are supported in VCD 10.4.1+")
}
vcd.testCreateExternalNetworkV2Nsxt(check, vcd.config.VCD.Nsxt.Tier0router, types.ExternalNetworkBackingTypeNsxtTier0Router, true, vcd.org.Org.ID)
}

func (vcd *TestVCD) Test_CreateExternalNetworkV2NsxtIpSpaceVrfDedicatedOrg(check *C) {
if vcd.client.Client.APIVCDMaxVersionIs("< 37.1") {
check.Skip("IP Spaces are supported in VCD 10.4.1+")
}
vcd.testCreateExternalNetworkV2Nsxt(check, vcd.config.VCD.Nsxt.Tier0routerVrf, types.ExternalNetworkBackingTypeNsxtTier0Router, true, vcd.org.Org.ID)
}

func getVcenterHref(vcdClient *VCDClient, name string) (string, error) {
virtualCenters, err := QueryVirtualCenters(vcdClient, fmt.Sprintf("(name==%s)", name))
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions govcd/ip_space.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (vcdClient *VCDClient) GetIpSpaceByNameAndOrgId(name, orgId string) (*IpSpa

singleIpSpace, err := oneOrError("name", name, filteredIpSpaces)
if err != nil {
return nil, fmt.Errorf("error ")
return nil, err
}

return vcdClient.GetIpSpaceById(singleIpSpace.IpSpace.ID)
Expand Down Expand Up @@ -193,7 +193,6 @@ func (ipSpace *IpSpace) Update(ipSpaceConfig *types.IpSpace) (*IpSpace, error) {
}

return returnIpSpace, nil

}

// Delete deletes IP Space
Expand Down
Loading

0 comments on commit 3b9ce5d

Please sign in to comment.