Debian Codegraph @

vapptemplate.go

raw symbols SCIP
1 /*
2 * Copyright 2014 VMware, Inc. All rights reserved. Licensed under the Apache v2 License.
3 */
4
5 package govcd
6
7 import (
8 "bytes"
9 "encoding/xml"
10 "fmt"
11 types "github.com/hmrc/vmware-govcd/types/v56"
12 )
13
14 type VAppTemplate struct {
15 VAppTemplate *types.VAppTemplate
16 c *Client
17 }
18
19 func NewVAppTemplate(c *Client) *VAppTemplate {
20 return &VAppTemplate{
21 VAppTemplate: new(types.VAppTemplate),
22 c: c,
23 }
24 }
25
26 func (v *Vdc) InstantiateVAppTemplate(template *types.InstantiateVAppTemplateParams) error {
27 output, err := xml.MarshalIndent(template, "", " ")
28 if err != nil {
29 return fmt.Errorf("Error finding VAppTemplate: %#v", err)
30 }
31 b := bytes.NewBufferString(xml.Header + string(output))
32
33 s := v.c.VCDVDCHREF
34 s.Path += "/action/instantiateVAppTemplate"
35
36 req := v.c.NewRequest(map[string]string{}, "POST", s, b)
37 req.Header.Add("Content-Type", "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml")
38
39 resp, err := checkResp(v.c.Http.Do(req))
40 if err != nil {
41 return fmt.Errorf("error instantiating a new template: %s", err)
42 }
43
44 vapptemplate := NewVAppTemplate(v.c)
45 if err = decodeBody(resp, vapptemplate.VAppTemplate); err != nil {
46 return fmt.Errorf("error decoding orgvdcnetwork response: %s", err)
47 }
48 task := NewTask(v.c)
49 for _, t := range vapptemplate.VAppTemplate.Tasks.Task {
50 task.Task = t
51 err = task.WaitTaskCompletion()
52 if err != nil {
53 return fmt.Errorf("Error performing task: %#v", err)
54 }
55 }
56 return nil
57 }