当前位置: 首页>>代码示例>>Golang>>正文


Golang autoscaling.AutoScaling类代码示例

本文整理汇总了Golang中github.com/aws/aws-sdk-go/service/autoscaling.AutoScaling的典型用法代码示例。如果您正苦于以下问题:Golang AutoScaling类的具体用法?Golang AutoScaling怎么用?Golang AutoScaling使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了AutoScaling类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: getAwsAutoscalingGroup

func getAwsAutoscalingGroup(
	asgName string,
	conn *autoscaling.AutoScaling) (*autoscaling.Group, error) {

	describeOpts := autoscaling.DescribeAutoScalingGroupsInput{
		AutoScalingGroupNames: []*string{aws.String(asgName)},
	}

	log.Printf("[DEBUG] AutoScaling Group describe configuration: %#v", describeOpts)
	describeGroups, err := conn.DescribeAutoScalingGroups(&describeOpts)
	if err != nil {
		autoscalingerr, ok := err.(awserr.Error)
		if ok && autoscalingerr.Code() == "InvalidGroup.NotFound" {
			return nil, nil
		}

		return nil, fmt.Errorf("Error retrieving AutoScaling groups: %s", err)
	}

	// Search for the autoscaling group
	for idx, asc := range describeGroups.AutoScalingGroups {
		if *asc.AutoScalingGroupName == asgName {
			return describeGroups.AutoScalingGroups[idx], nil
		}
	}

	return nil, nil
}
开发者ID:jkinred,项目名称:terraform,代码行数:28,代码来源:resource_aws_autoscaling_group.go

示例2: setAutoscalingTags

// setTags is a helper to set the tags for a resource. It expects the
// tags field to be named "tag"
func setAutoscalingTags(conn *autoscaling.AutoScaling, d *schema.ResourceData) error {
	if d.HasChange("tag") {
		oraw, nraw := d.GetChange("tag")
		o := setToMapByKey(oraw.(*schema.Set), "key")
		n := setToMapByKey(nraw.(*schema.Set), "key")

		resourceID := d.Get("name").(string)
		c, r := diffAutoscalingTags(
			autoscalingTagsFromMap(o, resourceID),
			autoscalingTagsFromMap(n, resourceID),
			resourceID)
		create := autoscaling.CreateOrUpdateTagsInput{
			Tags: c,
		}
		remove := autoscaling.DeleteTagsInput{
			Tags: r,
		}

		// Set tags
		if len(r) > 0 {
			log.Printf("[DEBUG] Removing autoscaling tags: %#v", r)
			if _, err := conn.DeleteTags(&remove); err != nil {
				return err
			}
		}
		if len(c) > 0 {
			log.Printf("[DEBUG] Creating autoscaling tags: %#v", c)
			if _, err := conn.CreateOrUpdateTags(&create); err != nil {
				return err
			}
		}
	}

	return nil
}
开发者ID:AssertSelenium,项目名称:terraform,代码行数:37,代码来源:autoscaling_tags.go

示例3: enableASGSuspendedProcesses

func enableASGSuspendedProcesses(d *schema.ResourceData, conn *autoscaling.AutoScaling) error {
	props := &autoscaling.ScalingProcessQuery{
		AutoScalingGroupName: aws.String(d.Id()),
		ScalingProcesses:     expandStringList(d.Get("suspended_processes").(*schema.Set).List()),
	}

	_, err := conn.SuspendProcesses(props)
	if err != nil {
		return err
	}

	return nil
}
开发者ID:hooklift,项目名称:terraform,代码行数:13,代码来源:resource_aws_autoscaling_group.go

示例4: removeNotificationConfigToGroupsWithTopic

func removeNotificationConfigToGroupsWithTopic(conn *autoscaling.AutoScaling, groups []*string, topic string) error {
	for _, r := range groups {
		opts := &autoscaling.DeleteNotificationConfigurationInput{
			AutoScalingGroupName: r,
			TopicARN:             aws.String(topic),
		}

		_, err := conn.DeleteNotificationConfiguration(opts)
		if err != nil {
			return fmt.Errorf("[WARN] Error deleting notification configuration for ASG \"%s\", Topic ARN \"%s\"", *r, topic)
		}
	}
	return nil
}
开发者ID:AssertSelenium,项目名称:terraform,代码行数:14,代码来源:resource_aws_autoscaling_notification.go

示例5: enableASGMetricsCollection

func enableASGMetricsCollection(d *schema.ResourceData, conn *autoscaling.AutoScaling) error {
	props := &autoscaling.EnableMetricsCollectionInput{
		AutoScalingGroupName: aws.String(d.Id()),
		Granularity:          aws.String(d.Get("metrics_granularity").(string)),
		Metrics:              expandStringList(d.Get("enabled_metrics").(*schema.Set).List()),
	}

	log.Printf("[INFO] Enabling metrics collection for the ASG: %s", d.Id())
	_, metricsErr := conn.EnableMetricsCollection(props)
	if metricsErr != nil {
		return metricsErr
	}

	return nil
}
开发者ID:jkinred,项目名称:terraform,代码行数:15,代码来源:resource_aws_autoscaling_group.go

示例6: resourceAwsAutoscalingLifecycleHookPutOp

func resourceAwsAutoscalingLifecycleHookPutOp(conn *autoscaling.AutoScaling, params *autoscaling.PutLifecycleHookInput) error {
	log.Printf("[DEBUG] AutoScaling PutLifecyleHook: %s", params)
	return resource.Retry(5*time.Minute, func() *resource.RetryError {
		_, err := conn.PutLifecycleHook(params)

		if err != nil {
			if awsErr, ok := err.(awserr.Error); ok {
				if strings.Contains(awsErr.Message(), "Unable to publish test message to notification target") {
					return resource.RetryableError(fmt.Errorf("[DEBUG] Retrying AWS AutoScaling Lifecycle Hook: %s", params))
				}
			}
			return resource.NonRetryableError(fmt.Errorf("Error putting lifecycle hook: %s", err))
		}
		return nil
	})
}
开发者ID:partamonov,项目名称:terraform,代码行数:16,代码来源:resource_aws_autoscaling_lifecycle_hook.go

示例7: terminateASG

func terminateASG(api *autoscaling.AutoScaling, instance *autoscaling.Group, wg *sync.WaitGroup) error {
	defer wg.Done()

	// 1. set the number of instances to 0
	_, err := api.UpdateAutoScalingGroup(&autoscaling.UpdateAutoScalingGroupInput{
		AutoScalingGroupName: instance.AutoScalingGroupName,
		DesiredCapacity:      aws.Int64(0),
		MaxSize:              aws.Int64(0),
		MinSize:              aws.Int64(0),
	})
	if err != nil {
		return err
	}

	// 2. wait until the instance count is 0
	for {
		instances, err := api.DescribeAutoScalingGroups(&autoscaling.DescribeAutoScalingGroupsInput{
			AutoScalingGroupNames: []*string{instance.AutoScalingGroupName},
		})
		if err != nil {
			return err
		}

		// instance already deleted?  we're done
		if len(instances.AutoScalingGroups) == 0 {
			return nil
		}

		// no instances remaining in asg?  break
		if v := instances.AutoScalingGroups[0]; len(v.Instances) == 0 {
			break
		}

		time.Sleep(15 * time.Second)
	}

	// 3. terminate the asg
	log.Printf("deleting autoscaling group, %s\n", *instance.AutoScalingGroupName)
	_, err = api.DeleteAutoScalingGroup(&autoscaling.DeleteAutoScalingGroupInput{
		AutoScalingGroupName: instance.AutoScalingGroupName,
		ForceDelete:          aws.Bool(true),
	})
	if err != nil {
		return err
	}

	log.Printf("deleting launch configuration, %s\n", *instance.LaunchConfigurationName)
	_, err = api.DeleteLaunchConfiguration(&autoscaling.DeleteLaunchConfigurationInput{
		LaunchConfigurationName: instance.LaunchConfigurationName,
	})
	if err != nil {
		return err
	}

	return nil
}
开发者ID:savaki,项目名称:deploytool,代码行数:56,代码来源:asg.go

示例8: addNotificationConfigToGroupsWithTopic

func addNotificationConfigToGroupsWithTopic(conn *autoscaling.AutoScaling, groups []*string, nl []*string, topic string) error {
	for _, a := range groups {
		opts := &autoscaling.PutNotificationConfigurationInput{
			AutoScalingGroupName: a,
			NotificationTypes:    nl,
			TopicARN:             aws.String(topic),
		}

		_, err := conn.PutNotificationConfiguration(opts)
		if err != nil {
			if awsErr, ok := err.(awserr.Error); ok {
				return fmt.Errorf("[WARN] Error creating Autoscaling Group Notification for Group %s, error: \"%s\", code: \"%s\"", *a, awsErr.Message(), awsErr.Code())
			}
			return err
		}
	}
	return nil
}
开发者ID:AssertSelenium,项目名称:terraform,代码行数:18,代码来源:resource_aws_autoscaling_notification.go

示例9: updateASGMetricsCollection

func updateASGMetricsCollection(d *schema.ResourceData, conn *autoscaling.AutoScaling) error {

	o, n := d.GetChange("enabled_metrics")
	if o == nil {
		o = new(schema.Set)
	}
	if n == nil {
		n = new(schema.Set)
	}

	os := o.(*schema.Set)
	ns := n.(*schema.Set)

	disableMetrics := os.Difference(ns)
	if disableMetrics.Len() != 0 {
		props := &autoscaling.DisableMetricsCollectionInput{
			AutoScalingGroupName: aws.String(d.Id()),
			Metrics:              expandStringList(disableMetrics.List()),
		}

		_, err := conn.DisableMetricsCollection(props)
		if err != nil {
			return fmt.Errorf("Failure to Disable metrics collection types for ASG %s: %s", d.Id(), err)
		}
	}

	enabledMetrics := ns.Difference(os)
	if enabledMetrics.Len() != 0 {
		props := &autoscaling.EnableMetricsCollectionInput{
			AutoScalingGroupName: aws.String(d.Id()),
			Metrics:              expandStringList(enabledMetrics.List()),
			Granularity:          aws.String(d.Get("metrics_granularity").(string)),
		}

		_, err := conn.EnableMetricsCollection(props)
		if err != nil {
			return fmt.Errorf("Failure to Enable metrics collection types for ASG %s: %s", d.Id(), err)
		}
	}

	return nil
}
开发者ID:paultyng,项目名称:terraform,代码行数:42,代码来源:resource_aws_autoscaling_group.go

示例10: updateASGSuspendedProcesses

func updateASGSuspendedProcesses(d *schema.ResourceData, conn *autoscaling.AutoScaling) error {
	o, n := d.GetChange("suspended_processes")
	if o == nil {
		o = new(schema.Set)
	}
	if n == nil {
		n = new(schema.Set)
	}

	os := o.(*schema.Set)
	ns := n.(*schema.Set)

	resumeProcesses := os.Difference(ns)
	if resumeProcesses.Len() != 0 {
		props := &autoscaling.ScalingProcessQuery{
			AutoScalingGroupName: aws.String(d.Id()),
			ScalingProcesses:     expandStringList(resumeProcesses.List()),
		}

		_, err := conn.ResumeProcesses(props)
		if err != nil {
			return fmt.Errorf("Error Resuming Processes for ASG %q: %s", d.Id(), err)
		}
	}

	suspendedProcesses := ns.Difference(os)
	if suspendedProcesses.Len() != 0 {
		props := &autoscaling.ScalingProcessQuery{
			AutoScalingGroupName: aws.String(d.Id()),
			ScalingProcesses:     expandStringList(suspendedProcesses.List()),
		}

		_, err := conn.SuspendProcesses(props)
		if err != nil {
			return fmt.Errorf("Error Suspending Processes for ASG %q: %s", d.Id(), err)
		}
	}

	return nil

}
开发者ID:hooklift,项目名称:terraform,代码行数:41,代码来源:resource_aws_autoscaling_group.go

示例11: findASGInstancesToTerminate

func findASGInstancesToTerminate(api *autoscaling.AutoScaling, opts Options) ([]*autoscaling.Group, error) {
	groups, err := api.DescribeAutoScalingGroups(&autoscaling.DescribeAutoScalingGroupsInput{})
	if err != nil {
		return nil, err
	}

	instances := []*autoscaling.Group{}
	for _, asg := range groups.AutoScalingGroups {
		if !hasASGTags(asg, "app", opts.App) {
			continue
		}
		if !hasASGTags(asg, "env", opts.Env) {
			continue
		}
		if hasASGTags(asg, "version", opts.Exclude) {
			continue
		}

		instances = append(instances, asg)
	}

	return instances, nil
}
开发者ID:savaki,项目名称:deploytool,代码行数:23,代码来源:asg.go


注:本文中的github.com/aws/aws-sdk-go/service/autoscaling.AutoScaling类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。