2018-01-11 04:57:53 -05:00
|
|
|
package ncloud
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"time"
|
|
|
|
|
2020-02-03 08:55:01 -05:00
|
|
|
"github.com/NaverCloudPlatform/ncloud-sdk-go-v2/services/server"
|
2018-01-11 04:57:53 -05:00
|
|
|
)
|
|
|
|
|
2020-02-03 08:55:01 -05:00
|
|
|
func waiterBlockStorageInstanceStatus(conn *NcloudAPIClient, blockStorageInstanceNo *string, status string, timeout time.Duration) error {
|
|
|
|
reqParams := new(server.GetBlockStorageInstanceListRequest)
|
|
|
|
reqParams.BlockStorageInstanceNoList = []*string{blockStorageInstanceNo}
|
2018-01-11 04:57:53 -05:00
|
|
|
|
|
|
|
c1 := make(chan error, 1)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
for {
|
2020-02-03 08:55:01 -05:00
|
|
|
blockStorageInstanceList, err := conn.server.V2Api.GetBlockStorageInstanceList(reqParams)
|
2018-01-11 04:57:53 -05:00
|
|
|
if err != nil {
|
|
|
|
c1 <- err
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-02-03 08:55:01 -05:00
|
|
|
if status == "DETAC" && len(blockStorageInstanceList.BlockStorageInstanceList) == 0 {
|
2018-01-11 04:57:53 -05:00
|
|
|
c1 <- nil
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-02-03 08:55:01 -05:00
|
|
|
blockStorageInstance := blockStorageInstanceList.BlockStorageInstanceList[0]
|
|
|
|
code := blockStorageInstance.BlockStorageInstanceStatus.Code
|
|
|
|
operationCode := blockStorageInstance.BlockStorageInstanceOperation.Code
|
2018-01-11 04:57:53 -05:00
|
|
|
|
2020-02-03 08:55:01 -05:00
|
|
|
if *code == status && *operationCode == "NULL" {
|
2018-01-11 04:57:53 -05:00
|
|
|
c1 <- nil
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-02-03 08:55:01 -05:00
|
|
|
log.Println(blockStorageInstance)
|
2018-01-11 04:57:53 -05:00
|
|
|
time.Sleep(time.Second * 5)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
select {
|
|
|
|
case res := <-c1:
|
|
|
|
return res
|
|
|
|
case <-time.After(timeout):
|
|
|
|
return fmt.Errorf("TIMEOUT : block storage instance status is not changed into status %s", status)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-03 08:55:01 -05:00
|
|
|
func waiterDetachedBlockStorageInstance(conn *NcloudAPIClient, serverInstanceNo string, timeout time.Duration) error {
|
|
|
|
reqParams := new(server.GetBlockStorageInstanceListRequest)
|
|
|
|
reqParams.ServerInstanceNo = &serverInstanceNo
|
2018-01-11 04:57:53 -05:00
|
|
|
|
|
|
|
c1 := make(chan error, 1)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
for {
|
2020-02-03 08:55:01 -05:00
|
|
|
blockStorageInstanceList, err := conn.server.V2Api.GetBlockStorageInstanceList(reqParams)
|
2018-01-11 04:57:53 -05:00
|
|
|
if err != nil {
|
|
|
|
c1 <- err
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-02-03 08:55:01 -05:00
|
|
|
if *blockStorageInstanceList.TotalRows == 1 {
|
2018-01-11 04:57:53 -05:00
|
|
|
c1 <- nil
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
time.Sleep(time.Second * 5)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
select {
|
|
|
|
case res := <-c1:
|
|
|
|
return res
|
|
|
|
case <-time.After(timeout):
|
|
|
|
return fmt.Errorf("TIMEOUT : attached block storage instance is not detached")
|
|
|
|
}
|
|
|
|
}
|