github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/alicloud/service_alicloud_ess.go (about)

     1  package alicloud
     2  
     3  import (
     4  	"github.com/denverdino/aliyungo/ess"
     5  )
     6  
     7  func (client *AliyunClient) DescribeScalingGroupById(sgId string) (*ess.ScalingGroupItemType, error) {
     8  	args := ess.DescribeScalingGroupsArgs{
     9  		RegionId:       client.Region,
    10  		ScalingGroupId: []string{sgId},
    11  	}
    12  
    13  	sgs, _, err := client.essconn.DescribeScalingGroups(&args)
    14  	if err != nil {
    15  		return nil, err
    16  	}
    17  
    18  	if len(sgs) == 0 {
    19  		return nil, GetNotFoundErrorFromString("Scaling group not found")
    20  	}
    21  
    22  	return &sgs[0], nil
    23  }
    24  
    25  func (client *AliyunClient) DeleteScalingGroupById(sgId string) error {
    26  	args := ess.DeleteScalingGroupArgs{
    27  		ScalingGroupId: sgId,
    28  		ForceDelete:    true,
    29  	}
    30  
    31  	_, err := client.essconn.DeleteScalingGroup(&args)
    32  	return err
    33  }
    34  
    35  func (client *AliyunClient) DescribeScalingConfigurationById(sgId, configId string) (*ess.ScalingConfigurationItemType, error) {
    36  	args := ess.DescribeScalingConfigurationsArgs{
    37  		RegionId:               client.Region,
    38  		ScalingGroupId:         sgId,
    39  		ScalingConfigurationId: []string{configId},
    40  	}
    41  
    42  	cs, _, err := client.essconn.DescribeScalingConfigurations(&args)
    43  	if err != nil {
    44  		return nil, err
    45  	}
    46  
    47  	if len(cs) == 0 {
    48  		return nil, GetNotFoundErrorFromString("Scaling configuration not found")
    49  	}
    50  
    51  	return &cs[0], nil
    52  }
    53  
    54  func (client *AliyunClient) ActiveScalingConfigurationById(sgId, configId string) error {
    55  	args := ess.ModifyScalingGroupArgs{
    56  		ScalingGroupId:               sgId,
    57  		ActiveScalingConfigurationId: configId,
    58  	}
    59  
    60  	_, err := client.essconn.ModifyScalingGroup(&args)
    61  	return err
    62  }
    63  
    64  func (client *AliyunClient) EnableScalingConfigurationById(sgId, configId string, ids []string) error {
    65  	args := ess.EnableScalingGroupArgs{
    66  		ScalingGroupId:               sgId,
    67  		ActiveScalingConfigurationId: configId,
    68  	}
    69  
    70  	if len(ids) > 0 {
    71  		args.InstanceId = ids
    72  	}
    73  
    74  	_, err := client.essconn.EnableScalingGroup(&args)
    75  	return err
    76  }
    77  
    78  func (client *AliyunClient) DisableScalingConfigurationById(sgId string) error {
    79  	args := ess.DisableScalingGroupArgs{
    80  		ScalingGroupId: sgId,
    81  	}
    82  
    83  	_, err := client.essconn.DisableScalingGroup(&args)
    84  	return err
    85  }
    86  
    87  func (client *AliyunClient) DeleteScalingConfigurationById(sgId, configId string) error {
    88  	args := ess.DeleteScalingConfigurationArgs{
    89  		ScalingGroupId:         sgId,
    90  		ScalingConfigurationId: configId,
    91  	}
    92  
    93  	_, err := client.essconn.DeleteScalingConfiguration(&args)
    94  	return err
    95  }
    96  
    97  // Flattens an array of datadisk into a []map[string]interface{}
    98  func flattenDataDiskMappings(list []ess.DataDiskItemType) []map[string]interface{} {
    99  	result := make([]map[string]interface{}, 0, len(list))
   100  	for _, i := range list {
   101  		l := map[string]interface{}{
   102  			"size":        i.Size,
   103  			"category":    i.Category,
   104  			"snapshot_id": i.SnapshotId,
   105  			"device":      i.Device,
   106  		}
   107  		result = append(result, l)
   108  	}
   109  	return result
   110  }
   111  
   112  func (client *AliyunClient) DescribeScalingRuleById(sgId, ruleId string) (*ess.ScalingRuleItemType, error) {
   113  	args := ess.DescribeScalingRulesArgs{
   114  		RegionId:       client.Region,
   115  		ScalingGroupId: sgId,
   116  		ScalingRuleId:  []string{ruleId},
   117  	}
   118  
   119  	cs, _, err := client.essconn.DescribeScalingRules(&args)
   120  	if err != nil {
   121  		return nil, err
   122  	}
   123  
   124  	if len(cs) == 0 {
   125  		return nil, GetNotFoundErrorFromString("Scaling rule not found")
   126  	}
   127  
   128  	return &cs[0], nil
   129  }
   130  
   131  func (client *AliyunClient) DeleteScalingRuleById(ruleId string) error {
   132  	args := ess.DeleteScalingRuleArgs{
   133  		RegionId:      client.Region,
   134  		ScalingRuleId: ruleId,
   135  	}
   136  
   137  	_, err := client.essconn.DeleteScalingRule(&args)
   138  	return err
   139  }
   140  
   141  func (client *AliyunClient) DescribeScheduleById(scheduleId string) (*ess.ScheduledTaskItemType, error) {
   142  	args := ess.DescribeScheduledTasksArgs{
   143  		RegionId:        client.Region,
   144  		ScheduledTaskId: []string{scheduleId},
   145  	}
   146  
   147  	cs, _, err := client.essconn.DescribeScheduledTasks(&args)
   148  	if err != nil {
   149  		return nil, err
   150  	}
   151  
   152  	if len(cs) == 0 {
   153  		return nil, GetNotFoundErrorFromString("Schedule not found")
   154  	}
   155  
   156  	return &cs[0], nil
   157  }
   158  
   159  func (client *AliyunClient) DeleteScheduleById(scheduleId string) error {
   160  	args := ess.DeleteScheduledTaskArgs{
   161  		RegionId:        client.Region,
   162  		ScheduledTaskId: scheduleId,
   163  	}
   164  
   165  	_, err := client.essconn.DeleteScheduledTask(&args)
   166  	return err
   167  }