Skip to content

Commit

Permalink
Add fix for vapp.RemoveNetwork() and vapp.RemoveNetworkAsync() (#299)
Browse files Browse the repository at this point in the history
* Use HTTP DELETE call instead of vApp network update to remove vApp networks
  • Loading branch information
Didainius authored Apr 10, 2020
1 parent 8bea87b commit 901273c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
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
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

0 comments on commit 901273c

Please sign in to comment.