github.phpd.cn/hashicorp/packer@v1.3.2/builder/ncloud/waiter_block_storage_instance.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 waiterBlockStorageInstanceStatus(conn *ncloud.Conn, blockStorageInstanceNo string, status string, timeout time.Duration) error { 12 reqParams := new(ncloud.RequestBlockStorageInstanceList) 13 reqParams.BlockStorageInstanceNoList = []string{blockStorageInstanceNo} 14 15 c1 := make(chan error, 1) 16 17 go func() { 18 for { 19 blockStorageInstanceList, err := conn.GetBlockStorageInstance(reqParams) 20 if err != nil { 21 c1 <- err 22 return 23 } 24 25 if status == "DETAC" && len(blockStorageInstanceList.BlockStorageInstance) == 0 { 26 c1 <- nil 27 return 28 } 29 30 code := blockStorageInstanceList.BlockStorageInstance[0].BlockStorageInstanceStatus.Code 31 operationCode := blockStorageInstanceList.BlockStorageInstance[0].BlockStorageInstanceOperation.Code 32 33 if code == status && operationCode == "NULL" { 34 c1 <- nil 35 return 36 } 37 38 log.Println(blockStorageInstanceList.BlockStorageInstance[0]) 39 time.Sleep(time.Second * 5) 40 } 41 }() 42 43 select { 44 case res := <-c1: 45 return res 46 case <-time.After(timeout): 47 return fmt.Errorf("TIMEOUT : block storage instance status is not changed into status %s", status) 48 } 49 } 50 51 func waiterDetachedBlockStorageInstance(conn *ncloud.Conn, serverInstanceNo string, timeout time.Duration) error { 52 reqParams := new(ncloud.RequestBlockStorageInstanceList) 53 reqParams.ServerInstanceNo = serverInstanceNo 54 55 c1 := make(chan error, 1) 56 57 go func() { 58 for { 59 blockStorageInstanceList, err := conn.GetBlockStorageInstance(reqParams) 60 if err != nil { 61 c1 <- err 62 return 63 } 64 65 if blockStorageInstanceList.TotalRows == 1 { 66 c1 <- nil 67 return 68 } 69 70 time.Sleep(time.Second * 5) 71 } 72 }() 73 74 select { 75 case res := <-c1: 76 return res 77 case <-time.After(timeout): 78 return fmt.Errorf("TIMEOUT : attached block storage instance is not detached") 79 } 80 }