Skip to content

Commit

Permalink
Rename func to waitUntilVxcIsConfigured
Browse files Browse the repository at this point in the history
It is not specific to AWS VXCs and can be used for other types as well.

Signed-off-by: Dimitrios Karagiannis <[email protected]>
  • Loading branch information
alkar committed Jan 28, 2020
1 parent 4b1bef8 commit 07b63b2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
24 changes: 24 additions & 0 deletions megaport/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,27 @@ func compareNillableStrings(a *string, b string) bool {
func compareNillableUints(a *uint64, b uint64) bool {
return a == nil || *a == b
}

func waitUntilVxcIsConfigured(client *api.Client, productUid string, timeout time.Duration) error {
scc := &resource.StateChangeConf{
Pending: []string{api.ProductStatusDeployable},
Target: []string{api.ProductStatusConfigured, api.ProductStatusLive},
Refresh: func() (interface{}, string, error) {
v, err := client.GetVxc(productUid)
if err != nil {
log.Printf("[ERROR] Could not retrieve VXC while waiting for setup to finish: %v", err)
return nil, "", err
}
if v == nil {
return nil, "", nil
}
return v, v.ProvisioningStatus, nil
},
Timeout: timeout,
MinTimeout: 10 * time.Second,
Delay: 5 * time.Second,
}
log.Printf("[INFO] Waiting for VXC (%s) to be configured", productUid)
_, err := scc.WaitForState()
return err
}
28 changes: 2 additions & 26 deletions megaport/resource_megaport_aws_vxc.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func resourceMegaportAwsVxcCreate(d *schema.ResourceData, m interface{}) error {
return err
}
d.SetId(*uid)
if err := waitUntilAwsVxcIsConfigured(cfg.Client, *uid, 5*time.Minute); err != nil {
if err := waitUntilVxcIsConfigured(cfg.Client, *uid, 5*time.Minute); err != nil {
return err
}
return resourceMegaportAwsVxcRead(d, m)
Expand All @@ -208,7 +208,7 @@ func resourceMegaportAwsVxcUpdate(d *schema.ResourceData, m interface{}) error {
if err := cfg.Client.UpdateCloudVxc(input); err != nil {
return err
}
if err := waitUntilAwsVxcIsConfigured(cfg.Client, d.Id(), 5*time.Minute); err != nil {
if err := waitUntilVxcIsConfigured(cfg.Client, d.Id(), 5*time.Minute); err != nil {
return err
}
if err := waitUntilAwsVxcIsUpdated(cfg.Client, input, 5*time.Minute); err != nil {
Expand Down Expand Up @@ -274,30 +274,6 @@ func waitUntilAwsVxcIsDeleted(client *api.Client, productUid string, timeout tim
return err
}

func waitUntilAwsVxcIsConfigured(client *api.Client, productUid string, timeout time.Duration) error {
scc := &resource.StateChangeConf{
Pending: []string{api.ProductStatusDeployable},
Target: []string{api.ProductStatusConfigured, api.ProductStatusLive},
Refresh: func() (interface{}, string, error) {
v, err := client.GetVxc(productUid) // TODO we can probably use this for any kind of VXC
if err != nil {
log.Printf("[ERROR] Could not retrieve VXC while waiting for setup to finish: %v", err)
return nil, "", err
}
if v == nil {
return nil, "", nil
}
return v, v.ProvisioningStatus, nil
},
Timeout: timeout,
MinTimeout: 10 * time.Second,
Delay: 5 * time.Second,
}
log.Printf("[INFO] Waiting for VXC (%s) to be configured", productUid)
_, err := scc.WaitForState()
return err
}

func waitUntilAwsVxcIsUpdated(client *api.Client, input *api.CloudVxcUpdateInput, timeout time.Duration) error {
scc := &resource.StateChangeConf{
Target: []string{api.ProductStatusConfigured, api.ProductStatusLive},
Expand Down

0 comments on commit 07b63b2

Please sign in to comment.