-
Notifications
You must be signed in to change notification settings - Fork 76
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
Conversation
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.
First scroll :)
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.
Some small changes needed. Running more tests in the meantime
govcd/vm.go
Outdated
func (vm *VM) GetParentVdc() (*Vdc, error) { | ||
vapp, err := vm.GetParentVApp() | ||
if err != nil { | ||
return nil, fmt.Errorf("could not find parent vApp: %s", err) |
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.
return nil, fmt.Errorf("could not find parent vApp: %s", err) | |
return nil, fmt.Errorf("could not find parent vApp for VM %s: %s", vm,VM.Name, err) |
The error would be more useful if it provides some context, especially if it is issued during operations in Terraform.
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.
govcd/vm.go
Outdated
|
||
vdc, err := vapp.getParentVDC() | ||
if err != nil { | ||
return nil, fmt.Errorf("could not find parent vDC: %s", err) |
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.
return nil, fmt.Errorf("could not find parent vDC: %s", err) | |
return nil, fmt.Errorf("could not find parent vDC for VM %s: %s", vm,VM.Name, err) |
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.
|
||
// getEdgeGatewaysForRoutedNics checks if any NICs are using routed networks and are attached to | ||
// edge gateway | ||
func (vm *VM) getEdgeGatewaysForRoutedNics(nicDhcpConfigs []nicDhcpConfig) ([]nicDhcpConfig, error) { |
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.
Just wondering if the approach using FindEdgeGatewayNameByNetwork
could be practicable here
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.
it is being used deeper inside (in the function getEdgeGatewayNameForNic
)
govcd/vm.go
Outdated
} | ||
|
||
// WaitForDhcpIpByNicIndexes accepts a slice of NIC indexes in VM, tries to get these IPs up to | ||
// maxWaitSeconds and the returns: |
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.
// maxWaitSeconds and the returns: | |
// maxWaitSeconds and then returns: |
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.
govcd/vm.go
Outdated
// partial result for IP addresses when the timeout is hit. | ||
// | ||
// Getting a DHCP address is complicated because vCD (in UI and in types.NetworkConnectionSection) | ||
// reports IP addresses when guest tools are present on a VM only. This function also attempts to |
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.
// reports IP addresses when guest tools are present on a VM only. This function also attempts to | |
// reports IP addresses only when guest tools are present on a VM. This function also attempts to |
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.
govcd/vm_dhcp_test.go
Outdated
// +build nsxv vm functional ALL | ||
|
||
/* | ||
* Copyright 2019 VMware, Inc. All rights reserved. Licensed under the Apache v2 License. |
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.
* Copyright 2019 VMware, Inc. All rights reserved. Licensed under the Apache v2 License. | |
* Copyright 2020 VMware, Inc. All rights reserved. Licensed under the Apache v2 License. |
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.
govcd/nsxv_dhcplease.go
Outdated
@@ -0,0 +1,69 @@ | |||
/* | |||
* Copyright 2019 VMware, Inc. All rights reserved. Licensed under the Apache v2 License. |
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.
* Copyright 2019 VMware, Inc. All rights reserved. Licensed under the Apache v2 License. | |
* Copyright 2020 VMware, Inc. All rights reserved. Licensed under the Apache v2 License. |
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.
govcd/vm_dhcp_test.go
Outdated
// getOrgVdcNetworkWithDhcp is a helper that creates a routed Org network and a DHCP pool with | ||
// single IP address to be assigned. Org vDC network and IP address assigned to DHCP pool are | ||
// returned | ||
func getOrgVdcNetworkWithDhcp(vcd *TestVCD, check *C, edgeGateway *EdgeGateway) (*types.OrgVDCNetwork, string) { |
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.
If this function creates something, it shouldn't be called get...
.
Perhaps makeOrgVdcNetworkWithDhcp
?
Moreover, the returned IP address is hard-coded. Should we pass it as a parameter instead?
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.
This is actually not needed at all currently (I ignore this output using _
assignment). This is a leftover from development phase and I think it is not worth building a more complicated function (at least at this time).
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.
Removed.
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.
LGTM
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.
LGTM!
Part of https://github.com/terraform-providers/terraform-provider-vcd/issues/316
This PR adds the following functions:
EdgeGateway.GetAllNsxvDhcpLeases()
EdgeGateway.GetNsxvActiveDhcpLeaseByMac()
VM.GetParentVApp()
VM.GetParentVdc()
VM.WaitForDhcpIpByNicIndexes()
The main goal was to get
VM.WaitForDhcpIpByNicIndexes()
function working and satisfy the needs of Terraform provider's capability to report IP addresses for NICs using DHCP mode. It is quite tricky to get the IP because vCD cannot know in advance if VM has guest tools or is using a DHCP addressing.For this function to work - at least one the following must be true:
Because vCD cannot know if the above requirements are fulfilled, this function requires a user definable timeout as the user must know how much time does it usually take for the VM to report IP addresses in his environment.
Full test suite passes on 9.5 and 10.0 with a caveat of
Test_UpdateInternalDisk
which is to be fixed in #282