Skip to content

Commit

Permalink
Use more appropriate interface for detecting when XO api changes are …
Browse files Browse the repository at this point in the history
…complete
  • Loading branch information
ddelnano committed Jul 26, 2023
1 parent 3a41744 commit 6d78163
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ func (c *Client) Call(method string, params, result interface{}, opt ...jsonrpc2
return nil
}

type RefreshComparison interface {
Propagated(obj interface{}) bool
}

type XoObject interface {
Compare(obj interface{}) bool
}
Expand Down
8 changes: 4 additions & 4 deletions client/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type CreateNetworkRequest struct {

// Nbd and Automatic are eventually consistent. This ensures that waitForModifyNetwork will
// poll until the values are correct.
func (c CreateNetworkRequest) Compare(obj interface{}) bool {
func (c CreateNetworkRequest) Propagated(obj interface{}) bool {
otherNet := obj.(Network)

if otherNet.Automatic == c.Automatic &&
Expand All @@ -81,7 +81,7 @@ type UpdateNetworkRequest struct {

// Nbd and Automatic are eventually consistent. This ensures that waitForModifyNetwork will
// poll until the values are correct.
func (c UpdateNetworkRequest) Compare(obj interface{}) bool {
func (c UpdateNetworkRequest) Propagated(obj interface{}) bool {
otherNet := obj.(Network)

if otherNet.Automatic == c.Automatic &&
Expand Down Expand Up @@ -119,15 +119,15 @@ func (c *Client) CreateNetwork(netReq CreateNetworkRequest) (*Network, error) {
return c.waitForModifyNetwork(id, netReq, 10*time.Second)
}

func (c *Client) waitForModifyNetwork(id string, target XoObject, timeout time.Duration) (*Network, error) {
func (c *Client) waitForModifyNetwork(id string, target RefreshComparison, timeout time.Duration) (*Network, error) {
refreshFn := func() (result interface{}, state string, err error) {
network, err := c.GetNetwork(Network{Id: id})

if err != nil {
return network, "", err
}

equal := strconv.FormatBool(target.Compare(*network))
equal := strconv.FormatBool(target.Propagated(*network))

return network, equal, nil
}
Expand Down

0 comments on commit 6d78163

Please sign in to comment.