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 waiterMemberServerImageStatus(conn *NcloudAPIClient, memberServerImageNo string, status string, timeout time.Duration) error {
|
|
|
|
reqParams := new(server.GetMemberServerImageListRequest)
|
|
|
|
reqParams.MemberServerImageNoList = []*string{&memberServerImageNo}
|
2018-01-11 04:57:53 -05:00
|
|
|
|
|
|
|
c1 := make(chan error, 1)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
for {
|
2020-02-03 08:55:01 -05:00
|
|
|
memberServerImageList, err := conn.server.V2Api.GetMemberServerImageList(reqParams)
|
2018-01-11 04:57:53 -05:00
|
|
|
if err != nil {
|
|
|
|
c1 <- err
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
code := memberServerImageList.MemberServerImageList[0].MemberServerImageStatus.Code
|
2020-02-03 08:55:01 -05:00
|
|
|
if *code == status {
|
2018-01-11 04:57:53 -05:00
|
|
|
c1 <- nil
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-02-03 08:55:01 -05:00
|
|
|
log.Printf("Status of member server image [%s] is %s\n", memberServerImageNo, *code)
|
2018-01-11 04:57:53 -05:00
|
|
|
log.Println(memberServerImageList.MemberServerImageList[0])
|
|
|
|
time.Sleep(time.Second * 5)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
select {
|
|
|
|
case res := <-c1:
|
|
|
|
return res
|
|
|
|
case <-time.After(timeout):
|
|
|
|
return fmt.Errorf("TIMEOUT : member server image status is not changed into status %s", status)
|
|
|
|
}
|
|
|
|
}
|