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

bugfix for vapp.RemoveNetwork() and vapp.RemoveNetworkAsync() when removing multiple network sequentially #299

Merged
merged 1 commit into from
Apr 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ NOTES:
BUGS FIXED:
* Fix issue in Queries with vCD 10 version, which do not return network pool or provider VDC[#293](https://github.com/vmware/go-vcloud-director/pull/293)
* Session timeout for media, catalog item upload [#294](https://github.com/vmware/go-vcloud-director/pull/294)
* Fix `vapp.RemoveNetwork`, `vapp.RemoveNetworkAsync` to use `DELETE` API call instead of update
Copy link
Collaborator

Choose a reason for hiding this comment

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

What about a comment that this is actual only for 10.1?

Copy link
Collaborator Author

@Didainius Didainius Apr 9, 2020

Choose a reason for hiding this comment

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

It causes problems not only in 10.1. At least 10.0 and 9.5 also has problems with Terraform's binary test vcd.TestAccVcdVAppVmMultiNIC.tf reendering error similar to https://github.com/terraform-providers/terraform-provider-vcd/issues/473 . I have also tested the example in the issue and it failed on vCD 9.5 with 2.7.0.

which can apply incorrect remaining vApp network configurations [#299](https://github.com/vmware/go-vcloud-director/pull/299)

## 2.6.0 (March 13, 2010)

Expand Down
19 changes: 10 additions & 9 deletions govcd/vapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -1194,24 +1194,25 @@ func (vapp *VApp) RemoveNetworkAsync(identifier string) (Task, error) {
}

networkConfigurations := vapp.VApp.NetworkConfigSection.NetworkConfig
isNetworkFound := false
for index, networkConfig := range networkConfigurations {
for _, networkConfig := range networkConfigurations {
networkId, err := GetUuidFromHref(networkConfig.Link.HREF, false)
if err != nil {
return Task{}, fmt.Errorf("unable to get network ID from HREF: %s", err)
}
if networkId == identifier || networkConfig.NetworkName == identifier {
isNetworkFound = true
networkConfigurations = append(networkConfigurations[:index], networkConfigurations[index+1:]...)
break
deleteUrl := vapp.client.VCDHREF.String() + "/network/" + networkId
errMessage := fmt.Sprintf("detaching vApp network %s (id '%s'): %%s", networkConfig.NetworkName, networkId)
task, err := vapp.client.ExecuteTaskRequest(deleteUrl, http.MethodDelete, types.AnyXMLMime, errMessage, nil)
if err != nil {
return Task{}, err
}

return task, nil
}
}

if !isNetworkFound {
return Task{}, fmt.Errorf("network to remove %s, wasn't found", identifier)
}
return Task{}, fmt.Errorf("network to remove %s, wasn't found", identifier)

return updateNetworkConfigurations(vapp, networkConfigurations)
}

// Removes vApp isolated network
Expand Down