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

Conversation

Didainius
Copy link
Collaborator

@Didainius Didainius commented Jan 17, 2020

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:

  • VM has guest tools (vCD UI shows IP address). (Takes longer time)
  • VM DHCP interface is connected to routed Org network and is using Edge Gateway DHCP. (Takes less time, but is more constrained)

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

@Didainius Didainius self-assigned this Jan 17, 2020
@Didainius Didainius added the enhancement New feature or request label Jan 17, 2020
@Didainius Didainius marked this pull request as ready for review January 21, 2020 05:53
Copy link
Contributor

@vbauzys vbauzys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First scroll :)

Copy link
Contributor

@dataclouder dataclouder left a 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Collaborator Author

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)

Copy link
Collaborator Author

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) {
Copy link
Contributor

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

Copy link
Collaborator Author

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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// maxWaitSeconds and the returns:
// maxWaitSeconds and then returns:

Copy link
Collaborator Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

// +build nsxv vm functional ALL

/*
* Copyright 2019 VMware, Inc. All rights reserved. Licensed under the Apache v2 License.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* 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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@@ -0,0 +1,69 @@
/*
* Copyright 2019 VMware, Inc. All rights reserved. Licensed under the Apache v2 License.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* 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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

// 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) {
Copy link
Contributor

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?

Copy link
Collaborator Author

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).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

Copy link
Contributor

@dataclouder dataclouder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@lvirbalas lvirbalas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Didainius Didainius merged commit 4375d22 into vmware:master Feb 19, 2020
@Didainius Didainius deleted the dhcp_lease_lookup_ip branch February 19, 2020 06:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-not-required enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants