forked from vmware/go-vcloud-director
/
productsection.go
53 lines (40 loc) · 1.5 KB
/
productsection.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* Copyright 2019 VMware, Inc. All rights reserved. Licensed under the Apache v2 License.
*/
package govcd
import (
"fmt"
"net/http"
"github.com/reski-rukmantiyo/go-vcloud-director/v2/types/v56"
)
// setProductSectionList is a shared function for both vApp and VM
func setProductSectionList(client *Client, href string, productSection *types.ProductSectionList) error {
if href == "" {
return fmt.Errorf("href cannot be empty to set product section")
}
productSection.Xmlns = types.XMLNamespaceVCloud
productSection.Ovf = types.XMLNamespaceOVF
task, err := client.ExecuteTaskRequest(href+"/productSections", http.MethodPut,
types.MimeProductSection, "error setting product section: %s", productSection)
if err != nil {
return fmt.Errorf("unable to set product section: %s", err)
}
err = task.WaitTaskCompletion()
if err != nil {
return fmt.Errorf("task for setting product section failed: %s", err)
}
return nil
}
// getProductSectionList is a shared function for both vApp and VM
func getProductSectionList(client *Client, href string) (*types.ProductSectionList, error) {
if href == "" {
return nil, fmt.Errorf("href cannot be empty to get product section")
}
productSection := &types.ProductSectionList{}
_, err := client.ExecuteRequest(href+"/productSections", http.MethodGet,
types.MimeProductSection, "error retrieving product section : %s", nil, productSection)
if err != nil {
return nil, fmt.Errorf("unable to retrieve product section: %s", err)
}
return productSection, nil
}