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

Refactor metadata CRUD functions to simplify code #473

Merged
merged 23 commits into from
Jun 3, 2022
8 changes: 8 additions & 0 deletions .changes/v2.16.0/473-features.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
* Added metadata interface `MetadataCompatible` to manage uniformly all metadata-compatible resources [GH-473]
* Added `AdminCatalog.MergeMetadata`,`AdminCatalog.MergeMetadataAsync`, `AdminOrg.MergeMetadata`, `AdminOrg.MergeMetadataAsync`,
`CatalogItem.MergeMetadata`, `CatalogItem.MergeMetadataAsync`, `Disk.MergeMetadata`, `Disk.MergeMetadataAsync`, `Media.MergeMetadata`,
`Media.MergeMetadataAsync`, `MediaRecord.MergeMetadata`, `MediaRecord.MergeMetadataAsync`, `OpenAPIOrgVdcNetwork.MergeMetadata`,
`OpenAPIOrgVdcNetwork.MergeMetadataAsync`, `OrgVDCNetwork.MergeMetadata`, `OrgVDCNetwork.MergeMetadataAsync`,
`VApp.MergeMetadata`, `VApp.MergeMetadataAsync`, `VAppTemplate.MergeMetadata`, `VAppTemplate.MergeMetadataAsync`,
`VM.MergeMetadata`, `VM.MergeMetadataAsync`, `Vdc.MergeMetadata`, `Vdc.MergeMetadataAsync` to merge metadata,
which both updates existing metadata with same key and adds new entries for the non-existent ones [GH-473]
5 changes: 5 additions & 0 deletions govcd/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,11 @@ func (client *Client) RemoveProvidedCustomHeaders(values map[string]string) {
}
}

// Retrieves the administrator URL of a given HREF
func getAdminURL(href string) string {
return strings.ReplaceAll(href, "/api/", "/api/admin/")
}

// ---------------------------------------------------------------------
// The following functions are needed to avoid strict Coverity warnings
// ---------------------------------------------------------------------
Expand Down
21 changes: 7 additions & 14 deletions govcd/api_vcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1702,28 +1702,21 @@ func (vcd *TestVCD) findFirstVapp() VApp {
return VApp{}
}
wantedVapp := vcd.vapp.VApp.Name
vappName := ""
for _, res := range vdc.Vdc.ResourceEntities {
for _, item := range res.ResourceEntity {
// Finding a named vApp, if it was defined in config
if wantedVapp != "" {
if item.Name == wantedVapp {
vappName = item.Name
break
}
} else {
// Otherwise, we get the first vApp from the vDC list
if wantedVapp == "" {
// As no vApp is defined in config, we search for one randomly
for _, res := range vdc.Vdc.ResourceEntities {
for _, item := range res.ResourceEntity {
if item.Type == "application/vnd.vmware.vcloud.vApp+xml" {
vappName = item.Name
wantedVapp = item.Name
break
}
}
}
}
if wantedVapp == "" {
vapp, err := vdc.GetVAppByName(wantedVapp, false)
if err != nil {
return VApp{}
}
vapp, _ := vdc.GetVAppByName(vappName, false)
return *vapp
}

Expand Down
Loading