github.phpd.cn/hashicorp/packer@v1.3.2/builder/ncloud/waiter_server_instance_status.go (about) 1 package ncloud 2 3 import ( 4 "fmt" 5 "log" 6 "time" 7 8 ncloud "github.com/NaverCloudPlatform/ncloud-sdk-go/sdk" 9 ) 10 11 func waiterServerInstanceStatus(conn *ncloud.Conn, serverInstanceNo string, status string, timeout time.Duration) error { 12 reqParams := new(ncloud.RequestGetServerInstanceList) 13 reqParams.ServerInstanceNoList = []string{serverInstanceNo} 14 15 c1 := make(chan error, 1) 16 17 go func() { 18 for { 19 serverInstanceList, err := conn.GetServerInstanceList(reqParams) 20 if err != nil { 21 c1 <- err 22 return 23 } 24 25 code := serverInstanceList.ServerInstanceList[0].ServerInstanceStatus.Code 26 if code == status { 27 c1 <- nil 28 return 29 } 30 31 log.Printf("Status of serverInstanceNo [%s] is %s\n", serverInstanceNo, code) 32 log.Println(serverInstanceList.ServerInstanceList[0]) 33 time.Sleep(time.Second * 5) 34 } 35 }() 36 37 select { 38 case res := <-c1: 39 return res 40 case <-time.After(timeout): 41 return fmt.Errorf("TIMEOUT : server instance status is not changed into status %s", status) 42 } 43 }