-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve xo get all objects struct parsing (#74)
* Pif, Template and storage repository data source panics when there are multiple matches (#66) * Unify the pattern of retrieving XoObjects from the XO api (#52) * Resolve PV driver issues with the terraform acceptance test VM template (#57) * Test suite improvements to make it easy to run the tests against any XO deployment
- Loading branch information
Showing
33 changed files
with
756 additions
and
477 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,4 @@ apply: | |
terraform apply | ||
|
||
testacc: | ||
TF_ACC=1 go test $(TEST) -v | ||
TF_ACC=1 go test $(TEST) -v -timeout 20m |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,60 @@ | ||
package client | ||
|
||
import ( | ||
"errors" | ||
) | ||
|
||
type PIF struct { | ||
Device string | ||
Host string | ||
Network string | ||
Id string | ||
Uuid string | ||
PoolId string | ||
Attached bool | ||
Vlan int | ||
Device string `json:"device"` | ||
Host string `json:"$host"` | ||
Network string `json:"$network"` | ||
Id string `json:"id"` | ||
Uuid string `json:"uuid"` | ||
PoolId string `json:"$poolId"` | ||
Attached bool `json:"attached"` | ||
Vlan int `json:"vlan"` | ||
} | ||
|
||
func (p PIF) Compare(obj map[string]interface{}) bool { | ||
device := obj["device"].(string) | ||
vlan := int(obj["vlan"].(float64)) | ||
if p.Vlan == vlan && p.Device == device { | ||
func (p PIF) Compare(obj interface{}) bool { | ||
otherPif := obj.(PIF) | ||
|
||
hostIdExists := p.Host != "" | ||
if hostIdExists && p.Host != otherPif.Host { | ||
return false | ||
} | ||
|
||
if p.Vlan == otherPif.Vlan && p.Device == otherPif.Device { | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
func (p PIF) New(obj map[string]interface{}) XoObject { | ||
id := obj["id"].(string) | ||
device := obj["device"].(string) | ||
attached := obj["attached"].(bool) | ||
network := obj["$network"].(string) | ||
uuid := obj["uuid"].(string) | ||
poolId := obj["$poolId"].(string) | ||
host := obj["$host"].(string) | ||
vlan := int(obj["vlan"].(float64)) | ||
return PIF{ | ||
Device: device, | ||
Host: host, | ||
Network: network, | ||
Id: id, | ||
Uuid: uuid, | ||
PoolId: poolId, | ||
Attached: attached, | ||
Vlan: vlan, | ||
func (c *Client) GetPIFByDevice(dev string, vlan int) ([]PIF, error) { | ||
obj, err := c.FindFromGetAllObjects(PIF{Device: dev, Vlan: vlan}) | ||
|
||
if err != nil { | ||
return []PIF{}, err | ||
} | ||
pifs, ok := obj.([]PIF) | ||
|
||
if !ok { | ||
return pifs, errors.New("failed to coerce response into PIF slice") | ||
} | ||
|
||
return pifs, nil | ||
} | ||
|
||
func (c *Client) GetPIFByDevice(dev string, vlan int) (PIF, error) { | ||
obj, err := c.FindFromGetAllObjects(PIF{Device: dev, Vlan: vlan}) | ||
pif := obj.(PIF) | ||
func (c *Client) GetPIF(pifReq PIF) (pifs []PIF, err error) { | ||
obj, err := c.FindFromGetAllObjects(pifReq) | ||
|
||
if err != nil { | ||
return pif, err | ||
return | ||
} | ||
pifs, ok := obj.([]PIF) | ||
|
||
if !ok { | ||
return pifs, errors.New("failed to coerce response into PIF slice") | ||
} | ||
|
||
return pif, nil | ||
return pifs, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.