...

Source file src/github.com/Azure/azure-sdk-for-go/services/classic/management/vmutils/rolestate.go

Documentation: github.com/Azure/azure-sdk-for-go/services/classic/management/vmutils

     1  // +build go1.7
     2  
     3  package vmutils
     4  
     5  // Copyright (c) Microsoft Corporation. All rights reserved.
     6  // Licensed under the MIT License. See License.txt in the project root for license information.
     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  // WaitForDeploymentPowerState blocks until all role instances in deployment
    16  // reach desired power state.
    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  // WaitForDeploymentInstanceStatus blocks until all role instances in deployment
    41  // reach desired InstanceStatus.
    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