~jameinel/juju-core/api-facade-registry

« back to all changes in this revision

Viewing changes to provider/azure/environ.go

  • Committer: John Arbash Meinel
  • Date: 2014-05-14 12:29:15 UTC
  • mfrom: (2715.2.15 juju-core)
  • Revision ID: john@arbash-meinel.com-20140514122915-lf70e9bkkxx9m11q
Merge trunk r2730

Show diffs side-by-side

added added

removed removed

Lines of Context:
475
475
        var inst instance.Instance
476
476
        defer func() {
477
477
                if inst != nil && resultErr != nil {
478
 
                        if err := env.StopInstances([]instance.Instance{inst}); err != nil {
 
478
                        if err := env.StopInstances(inst.Id()); err != nil {
479
479
                                // Failure upon failure. Log it, but return the original error.
480
480
                                logger.Errorf("error releasing failed instance: %v", err)
481
481
                        }
760
760
}
761
761
 
762
762
// StopInstances is specified in the InstanceBroker interface.
763
 
func (env *azureEnviron) StopInstances(instances []instance.Instance) error {
 
763
func (env *azureEnviron) StopInstances(ids ...instance.Id) error {
764
764
        context, err := env.getManagementAPI()
765
765
        if err != nil {
766
766
                return err
769
769
 
770
770
        // Map services to role names we want to delete.
771
771
        serviceInstances := make(map[string]map[string]bool)
772
 
        for _, instance := range instances {
773
 
                instance, ok := instance.(*azureInstance)
774
 
                if !ok {
775
 
                        continue
776
 
                }
777
 
                serviceName := instance.hostedService.ServiceName
778
 
                deleteRoleNames, ok := serviceInstances[serviceName]
779
 
                if !ok {
780
 
                        deleteRoleNames = make(map[string]bool)
781
 
                        serviceInstances[serviceName] = deleteRoleNames
782
 
                }
783
 
                deleteRoleNames[instance.roleName] = true
 
772
        for _, id := range ids {
 
773
                serviceName, roleName := env.splitInstanceId(id)
 
774
                if roleName == "" {
 
775
                        serviceInstances[serviceName] = nil
 
776
                } else {
 
777
                        deleteRoleNames, ok := serviceInstances[serviceName]
 
778
                        if !ok {
 
779
                                deleteRoleNames = make(map[string]bool)
 
780
                                serviceInstances[serviceName] = deleteRoleNames
 
781
                        }
 
782
                        deleteRoleNames[roleName] = true
 
783
                }
784
784
        }
785
785
 
786
786
        // Load the properties of each service, so we know whether to
806
806
                        }
807
807
                }
808
808
                // If we're deleting all the roles, we need to delete the
809
 
                // entire cloud service or we'll get an error.
810
 
                if len(deleteRoleNames) == roleNames.Size() {
 
809
                // entire cloud service or we'll get an error. deleteRoleNames
 
810
                // is nil if we're dealing with a legacy deployment.
 
811
                if deleteRoleNames == nil || len(deleteRoleNames) == roleNames.Size() {
811
812
                        if err := context.DeleteHostedService(serviceName); err != nil {
812
813
                                return err
813
814
                        }