-
Notifications
You must be signed in to change notification settings - Fork 77
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
Changes from 31 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
f09d91f
WIP
Didainius 174c4e0
wip2-not-works
Didainius 577494e
WIP - works
Didainius 7992d54
Use ticker for timed waiting
Didainius 731a1c0
Merge branch 'master' into dhcp_lease_lookup_ip
Didainius 21348e2
Before rewrite to struct
Didainius 0d6bb62
POC works
Didainius 97b1ac7
More tests, including timeout
Didainius c6c43cb
WIP
Didainius c400abc
Up
Didainius de45660
Show timeout explicitly
Didainius 134105f
Remove comments
Didainius b9f13a6
Cleanup, docs, public functions
Didainius 58930b3
add docs to functions
Didainius 8dbad99
Docs
Didainius f640947
more docs
Didainius c49497b
Extend default timeout
Didainius a7b43db
Force customization to avoid impact of other tests
Didainius bfa6dea
Undeploy before power off
Didainius 5ea28ae
Fix tests, beautify output
Didainius 2dc62c7
Increase timeouts
Didainius ef66399
Fix test
Didainius f5701ac
Spawn a VM for this test
Didainius 07a474c
Cleanup test
Didainius 2b97df5
Merge master
Didainius a6e2645
merge master
Didainius b2a8b7e
Improve comment
Didainius 120f924
Merge and update changelog
Didainius ac1e37b
Add extra check, fix comment
Didainius 1351ce0
Fix new Travis error
Didainius 1d70eb3
Merge master
Didainius 3fc7f94
Address comments
Didainius cbd9483
Address comments
Didainius 3870209
Remove unused testing function var
Didainius 67f899f
Change comment
Didainius 7764172
Improve comment
Didainius 4df540f
Merge master
Didainius 0475942
Revert "Merge master"
Didainius 11f7cb3
merge master
Didainius 135da1d
Cleanup travis
Didainius dc6109b
Add 'DHCP IP Lookup' keyword to all log messages for easier filtering
Didainius 3d6be75
Change log format for DHCP lookup
Didainius File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ go: | |
- "1.12.x" | ||
|
||
sudo: false | ||
install: false | ||
|
||
script: | ||
- env GO111MODULE=on make | ||
|
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
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,69 @@ | ||
/* | ||
* Copyright 2019 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 | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.