File: waiter_server_instance_status.go

package info (click to toggle)
packer 1.3.4%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 8,324 kB
  • sloc: python: 619; sh: 557; makefile: 111
file content (43 lines) | stat: -rw-r--r-- 996 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package ncloud

import (
	"fmt"
	"log"
	"time"

	ncloud "github.com/NaverCloudPlatform/ncloud-sdk-go/sdk"
)

func waiterServerInstanceStatus(conn *ncloud.Conn, serverInstanceNo string, status string, timeout time.Duration) error {
	reqParams := new(ncloud.RequestGetServerInstanceList)
	reqParams.ServerInstanceNoList = []string{serverInstanceNo}

	c1 := make(chan error, 1)

	go func() {
		for {
			serverInstanceList, err := conn.GetServerInstanceList(reqParams)
			if err != nil {
				c1 <- err
				return
			}

			code := serverInstanceList.ServerInstanceList[0].ServerInstanceStatus.Code
			if code == status {
				c1 <- nil
				return
			}

			log.Printf("Status of serverInstanceNo [%s] is %s\n", serverInstanceNo, code)
			log.Println(serverInstanceList.ServerInstanceList[0])
			time.Sleep(time.Second * 5)
		}
	}()

	select {
	case res := <-c1:
		return res
	case <-time.After(timeout):
		return fmt.Errorf("TIMEOUT : server instance status is not changed into status %s", status)
	}
}