-
Notifications
You must be signed in to change notification settings - Fork 0
/
catalogitem.go
81 lines (66 loc) · 2.25 KB
/
catalogitem.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package vcd
import (
"fmt"
"log"
"github.com/hashicorp/terraform/helper/schema"
"github.com/vmware/go-vcloud-director/govcd"
)
// Deletes catalog item which can be vapp template OVA or media ISO file
func deleteCatalogItem(d *schema.ResourceData, vcdClient *VCDClient) error {
log.Printf("[TRACE] Catalog item delete started")
adminOrg, err := vcdClient.GetAdminOrgFromResource(d)
if err != nil {
return fmt.Errorf(errorRetrievingOrg, err)
}
catalog, err := adminOrg.FindCatalog(d.Get("catalog").(string))
if err != nil || catalog == (govcd.Catalog{}) {
log.Printf("[DEBUG] Unable to find catalog. Removing from tfstate")
d.SetId("")
return nil
}
catalogItem, err := catalog.FindCatalogItem(d.Get("name").(string))
if err != nil || catalogItem == (govcd.CatalogItem{}) {
log.Printf("[DEBUG] Unable to find catalog item. Removing from tfstate")
d.SetId("")
return nil
}
err = catalogItem.Delete()
if err != nil {
log.Printf("Error removing catalog item %#v", err)
return fmt.Errorf("error removing catalog item %#v", err)
}
log.Printf("[TRACE] Catalog item delete completed: %#v", catalogItem.CatalogItem)
return nil
}
// Finds catalog item which can be vapp template OVA or media ISO file
func findCatalogItem(d *schema.ResourceData, vcdClient *VCDClient) error {
log.Printf("[TRACE] Catalog item read initiated")
adminOrg, err := vcdClient.GetAdminOrgFromResource(d)
if err != nil {
return fmt.Errorf(errorRetrievingOrg, err)
}
catalog, err := adminOrg.FindCatalog(d.Get("catalog").(string))
if err != nil || catalog == (govcd.Catalog{}) {
log.Printf("[DEBUG] Unable to find catalog. Removing from tfstate")
d.SetId("")
return nil
}
catalogItem, err := catalog.FindCatalogItem(d.Get("name").(string))
if err != nil || catalogItem == (govcd.CatalogItem{}) {
log.Printf("[DEBUG] Unable to find catalog item. Removing from tfstate")
d.SetId("")
return nil
}
log.Printf("[TRACE] Catalog item read completed: %#v", catalogItem.CatalogItem)
return nil
}
func getError(task govcd.UploadTask) error {
if task.GetUploadError() != nil {
err := task.CancelTask()
if err != nil {
log.Printf("error cancelling media upload task: %#v", err)
}
return fmt.Errorf("error uploading media: %#v", task.GetUploadError())
}
return nil
}