From e82819862655878dba99afbb6c19ff3098030112 Mon Sep 17 00:00:00 2001 From: floriankammermann Date: Sun, 3 Dec 2017 23:57:21 +0100 Subject: [PATCH] added Vdcorg, use httpclient for all requests --- vcdapi/httpclient.go | 4 ++++ vcdapi/vcdapiclient.go | 25 +++++++++++++------------ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/vcdapi/httpclient.go b/vcdapi/httpclient.go index 44f6f92..c25b2da 100755 --- a/vcdapi/httpclient.go +++ b/vcdapi/httpclient.go @@ -67,6 +67,10 @@ func decodeBody(resp *http.Response, out interface{}) error { fmt.Println("response Body:", string(body)) } + if out == nil { + return nil + } + // Unmarshal the XML. if err = xml.Unmarshal(body, &out); err != nil { return err diff --git a/vcdapi/vcdapiclient.go b/vcdapi/vcdapiclient.go index cf06089..24dc1b5 100755 --- a/vcdapi/vcdapiclient.go +++ b/vcdapi/vcdapiclient.go @@ -1,27 +1,28 @@ package vcdapi import ( - "net/http" "fmt" "github.com/floriankammermann/vcloud-cli/types" "errors" ) -func GetAllVApp(url string) { - req, err := http.NewRequest("GET", url+"/api/query?type=vApp&fields=name&pageSize=512", nil) - req.Header.Set("x-vcloud-authorization", vcdClient.VAToken) - req.Header.Set("Accept", "application/*+xml;version=5.5") - - client := &http.Client{} - resp, err := client.Do(req) - if err != nil { - panic(err) +func GetAllVdcorg(url string) { + + path := "/api/query?type=orgVdc&fields=name&pageSize=512" + queryRes := new(types.QueryResultRecordsType) + ExecRequest(url, path, queryRes) + + for _, vapp := range queryRes.OrgVdcRecord { + fmt.Printf("orgVdc Name [%s]\n", vapp.Name) } - defer resp.Body.Close() +} + +func GetAllVApp(url string) { + path := "/api/query?type=vApp&fields=name&pageSize=512" queryRes := new(types.QueryResultRecordsType) - decodeBody(resp, queryRes) + ExecRequest(url, path, queryRes) for _, vapp := range queryRes.VAppRecord { fmt.Printf("vApp Name [%s]\n", vapp.Name)