Skip to content

Commit

Permalink
Ensure that the XO client does not reuse an already unmarshalled stru…
Browse files Browse the repository at this point in the history
…ct (#78)

(cherry picked from commit 48a7294)
  • Loading branch information
ddelnano authored Oct 15, 2020
1 parent d4d9316 commit 89f7129
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ func (c *Client) FindFromGetAllObjects(obj XoObject) (interface{}, error) {

found := false
t := reflect.TypeOf(obj)
value := reflect.New(t)
objs := reflect.MakeSlice(reflect.SliceOf(t), 0, 0)
for _, resObj := range objsRes.Objects {
v, ok := resObj.(map[string]interface{})
Expand All @@ -173,6 +172,7 @@ func (c *Client) FindFromGetAllObjects(obj XoObject) (interface{}, error) {
if err != nil {
return objs, err
}
value := reflect.New(t)
err = json.Unmarshal(b, value.Interface())
if err != nil {
return objs, err
Expand All @@ -186,7 +186,7 @@ func (c *Client) FindFromGetAllObjects(obj XoObject) (interface{}, error) {
return objs, NotFound{Query: obj}
}

log.Printf("[TRACE] Found the following objects from xo.getAllObjects: %+v\n", objs)
log.Printf("[DEBUG] Found the following objects from xo.getAllObjects: %+v\n", objs)

return objs.Interface(), nil
}
Expand Down
10 changes: 5 additions & 5 deletions client/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ func (c *Client) CreateVm(name_label, name_description, template, cloudConfig, r
return nil, err
}

vm := Vm{
Id: vmId,
}

return &vm, nil
return c.GetVm(
Vm{
Id: vmId,
},
)
}

func (c *Client) UpdateVm(id string, cpus int, nameLabel, nameDescription, ha, rs string, autoPowerOn bool) (*Vm, error) {
Expand Down

0 comments on commit 89f7129

Please sign in to comment.