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

Add support for IP reporting when NIC uses DHCP #283

Merged
merged 42 commits into from
Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
f09d91f
WIP
Didainius Dec 18, 2019
174c4e0
wip2-not-works
Didainius Dec 23, 2019
577494e
WIP - works
Didainius Jan 7, 2020
7992d54
Use ticker for timed waiting
Didainius Jan 7, 2020
731a1c0
Merge branch 'master' into dhcp_lease_lookup_ip
Didainius Jan 13, 2020
21348e2
Before rewrite to struct
Didainius Jan 14, 2020
0d6bb62
POC works
Didainius Jan 14, 2020
97b1ac7
More tests, including timeout
Didainius Jan 14, 2020
c6c43cb
WIP
Didainius Jan 14, 2020
c400abc
Up
Didainius Jan 14, 2020
de45660
Show timeout explicitly
Didainius Jan 15, 2020
134105f
Remove comments
Didainius Jan 17, 2020
b9f13a6
Cleanup, docs, public functions
Didainius Jan 17, 2020
58930b3
add docs to functions
Didainius Jan 17, 2020
8dbad99
Docs
Didainius Jan 17, 2020
f640947
more docs
Didainius Jan 17, 2020
c49497b
Extend default timeout
Didainius Jan 17, 2020
a7b43db
Force customization to avoid impact of other tests
Didainius Jan 18, 2020
bfa6dea
Undeploy before power off
Didainius Jan 18, 2020
5ea28ae
Fix tests, beautify output
Didainius Jan 19, 2020
2dc62c7
Increase timeouts
Didainius Jan 20, 2020
ef66399
Fix test
Didainius Jan 20, 2020
f5701ac
Spawn a VM for this test
Didainius Jan 21, 2020
07a474c
Cleanup test
Didainius Jan 21, 2020
2b97df5
Merge master
Didainius Jan 21, 2020
a6e2645
merge master
Didainius Jan 21, 2020
b2a8b7e
Improve comment
Didainius Jan 21, 2020
120f924
Merge and update changelog
Didainius Jan 22, 2020
ac1e37b
Add extra check, fix comment
Didainius Jan 22, 2020
1351ce0
Fix new Travis error
Didainius Jan 22, 2020
1d70eb3
Merge master
Didainius Jan 23, 2020
3fc7f94
Address comments
Didainius Jan 23, 2020
cbd9483
Address comments
Didainius Jan 23, 2020
3870209
Remove unused testing function var
Didainius Jan 23, 2020
67f899f
Change comment
Didainius Jan 23, 2020
7764172
Improve comment
Didainius Feb 5, 2020
4df540f
Merge master
Didainius Feb 14, 2020
0475942
Revert "Merge master"
Didainius Feb 14, 2020
11f7cb3
merge master
Didainius Feb 14, 2020
135da1d
Cleanup travis
Didainius Feb 14, 2020
dc6109b
Add 'DHCP IP Lookup' keyword to all log messages for easier filtering
Didainius Feb 18, 2020
3d6be75
Change log format for DHCP lookup
Didainius Feb 18, 2020
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: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go:
- "1.12.x"

sudo: false
install: false

script:
- env GO111MODULE=on make
Expand Down
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
* Added methods `VM.AddInternalDisk`, `VM.GetInternalDiskById`, `VM.DeleteInternalDisk`, `VM.UpdateInternalDisks` and `VM.UpdateInternalDisksAsync` [#272](https://github.com/vmware/go-vcloud-director/pull/272)
* Added methods `vdc.GetEdgeGatewayReferenceList` and `catalog.GetVappTemplateByHref` [#278](https://github.com/vmware/go-vcloud-director/pull/278)
* Improved functions to not expect XML namespaces provided in argument structure [#284](https://github.com/vmware/go-vcloud-director/pull/284)
* Change `int` and `bool` fields from types.VAppTemplateLeaseSettings and VAppLeaseSettings into pointers
* Added method `catalog.GetVappTemplateByHref`, and expose methods `vdc.GetEdgeGatewayByHref` and `vdc.GetEdgeGatewayRecordsType`
* Change `int` and `bool` fields from types.VAppTemplateLeaseSettings and VAppLeaseSettings into
pointers [#281](https://github.com/vmware/go-vcloud-director/pull/281)
* Added method `catalog.GetVappTemplateByHref`, and expose methods `vdc.GetEdgeGatewayByHref` and
`vdc.GetEdgeGatewayRecordsType` [#278](https://github.com/vmware/go-vcloud-director/pull/278)
* Added methods `EdgeGateway.GetAllNsxvDhcpLeases()`, `EdgeGateway.GetNsxvActiveDhcpLeaseByMac()`
`VM.WaitForDhcpIpByNicIndexes()`, `VM.GetParentVApp()`, `VM.GetParentVdc()`
[#283](https://github.com/vmware/go-vcloud-director/pull/283)

## 2.5.1 (December 12, 2019)

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ default: fmtcheck vet static build
# test runs the test suite and vets the code
test: testunit
@echo "==> Running Functional Tests"
cd govcd && go test -tags "functional" -timeout=90m -check.vv .
cd govcd && go test -tags "functional" -timeout=200m -check.vv .

# testunit runs the unit tests
testunit: fmtcheck
Expand Down
7 changes: 7 additions & 0 deletions govcd/api_vcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const (
TestCreateOrgVdc = "TestCreateOrgVdc"
TestRefreshOrgVdc = "TestRefreshOrgVdc"
TestCreateOrgVdcNetworkRouted = "TestCreateOrgVdcNetworkRouted"
TestCreateOrgVdcNetworkDhcp = "TestCreateOrgVdcNetworkDhcp"
TestCreateOrgVdcNetworkIso = "TestCreateOrgVdcNetworkIso"
TestCreateOrgVdcNetworkDirect = "TestCreateOrgVdcNetworkDirect"
TestUploadMedia = "TestUploadMedia"
Expand Down Expand Up @@ -589,7 +590,13 @@ func (vcd *TestVCD) removeLeftoverEntities(entity CleanupEntity) {
}
task, _ := vapp.Undeploy()
_ = task.WaitTaskCompletion()
// Detach all Org networks during vApp removal because network removal errors if it happens
// very quickly (as the next task) after vApp removal
task, _ = vapp.RemoveAllNetworks()
_ = task.WaitTaskCompletion()
task, err = vapp.Delete()
_ = task.WaitTaskCompletion()

if err != nil {
vcd.infoCleanup(notDeletedMsg, entity.EntityType, entity.Name, err)
return
Expand Down
69 changes: 69 additions & 0 deletions govcd/nsxv_dhcplease.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright 2020 VMware, Inc. All rights reserved. Licensed under the Apache v2 License.
*/

package govcd

import (
"encoding/xml"
"fmt"
"net/http"

"github.com/vmware/go-vcloud-director/v2/types/v56"
"github.com/vmware/go-vcloud-director/v2/util"
)

type responseEdgeDhcpLeases struct {
XMLName xml.Name `xml:"dhcpLeases"`
TimeStamp string `xml:"timeStamp"`
DhcpLease types.EdgeDhcpLease `xml:"dhcpLeaseInfo"`
}

// GetNsxvActiveDhcpLeaseByMac finds active DHCP lease for a given hardware address (MAC)
func (egw *EdgeGateway) GetNsxvActiveDhcpLeaseByMac(mac string) (*types.EdgeDhcpLeaseInfo, error) {
if mac == "" {
return nil, fmt.Errorf("MAC address must be provided to lookup DHCP lease")
}
dhcpLeases, err := egw.GetAllNsxvDhcpLeases()
if err != nil {
return nil, err
}

util.Logger.Printf("[DEBUG] Looking up active DHCP lease for MAC: %s", mac)
for _, lease := range dhcpLeases {
util.Logger.Printf("[DEBUG] Checking DHCP lease: %#+v", lease)
if lease.BindingState == "active" && lease.MacAddress == mac {
return lease, nil
}
}

return nil, ErrorEntityNotFound
}

// GetAllNsxvDhcpLeases retrieves all DHCP leases defined in NSX-V edge gateway
func (egw *EdgeGateway) GetAllNsxvDhcpLeases() ([]*types.EdgeDhcpLeaseInfo, error) {
if !egw.HasAdvancedNetworking() {
return nil, fmt.Errorf("only advanced edge gateways support DHCP")
}

httpPath, err := egw.buildProxiedEdgeEndpointURL(types.EdgeDhcpLeasePath)
if err != nil {
return nil, fmt.Errorf("could not get Edge Gateway API endpoint: %s", err)
}

dhcpLeases := &responseEdgeDhcpLeases{}

// This query returns all DHCP leases
_, err = egw.client.ExecuteRequest(httpPath, http.MethodGet, types.AnyXMLMime,
"unable to read DHCP leases: %s", nil, dhcpLeases)
if err != nil {
return nil, err
}

if dhcpLeases != nil && len(dhcpLeases.DhcpLease.DhcpLeaseInfos) == 0 {
util.Logger.Printf("[DEBUG] GetAllNsxvDhcpLeases found 0 leases available")
return nil, ErrorEntityNotFound
}

return dhcpLeases.DhcpLease.DhcpLeaseInfos, nil
}
2 changes: 1 addition & 1 deletion govcd/orgvdcnetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,5 +234,5 @@ func (vdc *Vdc) FindEdgeGatewayNameByNetwork(networkName string) (string, error)
}
}
}
return "", fmt.Errorf("no edge gateway connection found")
return "", ErrorEntityNotFound
}
Loading