...
1
2
3 package vmutils
4
5
6
7
8 import (
9 "time"
10
11 "github.com/Azure/azure-sdk-for-go/services/classic/management"
12 vm "github.com/Azure/azure-sdk-for-go/services/classic/management/virtualmachine"
13 )
14
15
16
17 func WaitForDeploymentPowerState(client management.Client, cloudServiceName, deploymentName string, desiredPowerstate vm.PowerState) error {
18 for {
19 deployment, err := vm.NewClient(client).GetDeployment(cloudServiceName, deploymentName)
20 if err != nil {
21 return err
22 }
23 if allInstancesInPowerState(deployment.RoleInstanceList, desiredPowerstate) {
24 return nil
25 }
26 time.Sleep(2 * time.Second)
27 }
28 }
29
30 func allInstancesInPowerState(instances []vm.RoleInstance, desiredPowerstate vm.PowerState) bool {
31 for _, r := range instances {
32 if r.PowerState != desiredPowerstate {
33 return false
34 }
35 }
36
37 return true
38 }
39
40
41
42 func WaitForDeploymentInstanceStatus(client management.Client, cloudServiceName, deploymentName string, desiredInstanceStatus vm.InstanceStatus) error {
43 for {
44 deployment, err := vm.NewClient(client).GetDeployment(cloudServiceName, deploymentName)
45 if err != nil {
46 return err
47 }
48 if allInstancesInInstanceStatus(deployment.RoleInstanceList, desiredInstanceStatus) {
49 return nil
50 }
51 time.Sleep(2 * time.Second)
52 }
53 }
54
55 func allInstancesInInstanceStatus(instances []vm.RoleInstance, desiredInstancestatus vm.InstanceStatus) bool {
56 for _, r := range instances {
57 if r.InstanceStatus != desiredInstancestatus {
58 return false
59 }
60 }
61
62 return true
63 }
64
View as plain text