Пример #1
0
func (self *ECSManager) RegisterTaskDefinition(taskName string, containers []*schema.ContainerDefinition) (*ecs.RegisterTaskDefinitionOutput, error) {

	svc := ecs.New(&aws.Config{
		Region:      self.Region,
		Credentials: self.Credentials,
	})

	conDefs := []*ecs.ContainerDefinition{}

	for _, con := range containers {

		var commands []*string
		if len(con.Command) > 0 {
			for _, token := range strings.Split(con.Command, " ") {
				commands = append(commands, aws.String(token))
			}
		} else {
			commands = nil
		}

		var entryPoints []*string
		if len(con.EntryPoint) > 0 {
			for _, token := range strings.Split(con.EntryPoint, " ") {
				entryPoints = append(entryPoints, aws.String(token))
			}
		} else {
			entryPoints = nil
		}

		conDef := &ecs.ContainerDefinition{
			CPU:         aws.Long(con.CpuUnits),
			Command:     commands,
			EntryPoint:  entryPoints,
			Environment: toKeyValuePairs(con.Environment),
			Essential:   aws.Boolean(con.Essential),
			Image:       aws.String(con.Image),
			Links:       util.ConvertPointerString(con.Links),
			Memory:      aws.Long(con.Memory),
			// MountPoints
			Name:         aws.String(con.Name),
			PortMappings: toPortMappings(con.Ports),
			// VolumesFrom
		}

		conDefs = append(conDefs, conDef)
	}

	params := &ecs.RegisterTaskDefinitionInput{
		ContainerDefinitions: conDefs,
		Family:               aws.String(taskName),
		Volumes:              []*ecs.Volume{},
	}

	return svc.RegisterTaskDefinition(params)
}
Пример #2
0
func (self *ElbApi) DescribeLoadBalancers(names []string) (*elb.DescribeLoadBalancersOutput, error) {

	svc := elb.New(&aws.Config{
		Region:      self.Region,
		Credentials: self.Credentials,
	})

	params := &elb.DescribeLoadBalancersInput{
		LoadBalancerNames: util.ConvertPointerString(names),
	}

	return svc.DescribeLoadBalancers(params)
}
Пример #3
0
func (self *AutoscalingApi) DetachLoadBalancers(group string, lb []string) (*autoscaling.DetachLoadBalancersOutput, error) {

	svc := autoscaling.New(&aws.Config{
		Region:      self.Region,
		Credentials: self.Credentials,
	})

	params := &autoscaling.DetachLoadBalancersInput{
		AutoScalingGroupName: aws.String(group),
		LoadBalancerNames:    util.ConvertPointerString(lb),
	}

	return svc.DetachLoadBalancers(params)
}
Пример #4
0
func (self *AutoscalingApi) DescribeAutoScalingGroups(groups []string) (map[string]*autoscaling.Group, error) {

	svc := autoscaling.New(&aws.Config{
		Region:      self.Region,
		Credentials: self.Credentials,
	})

	params := &autoscaling.DescribeAutoScalingGroupsInput{
		AutoScalingGroupNames: util.ConvertPointerString(groups),
	}

	asgmap := map[string]*autoscaling.Group{}
	result, err := svc.DescribeAutoScalingGroups(params)
	if err != nil {
		return asgmap, err
	}

	for _, asg := range result.AutoScalingGroups {
		asgmap[*asg.AutoScalingGroupName] = asg
	}

	return asgmap, nil
}
Пример #5
0
func (self *EcsTaskApi) RegisterTaskDefinition(taskName string, containers []*schema.ContainerDefinition) (*ecs.RegisterTaskDefinitionOutput, error) {

	svc := ecs.New(&aws.Config{
		Region:      self.Region,
		Credentials: self.Credentials,
	})

	conDefs := []*ecs.ContainerDefinition{}
	volumes := []*ecs.Volume{}

	for _, con := range containers {

		var commands []*string
		if len(con.Command) > 0 {
			for _, token := range strings.Split(con.Command, " ") {
				commands = append(commands, aws.String(token))
			}
		} else {
			commands = nil
		}

		var entryPoints []*string
		if len(con.EntryPoint) > 0 {
			for _, token := range strings.Split(con.EntryPoint, " ") {
				entryPoints = append(entryPoints, aws.String(token))
			}
		} else {
			entryPoints = nil
		}

		portMappings, err := toPortMappings(con.Ports)
		if err != nil {
			return &ecs.RegisterTaskDefinitionOutput{}, err
		}

		volumeItems, err := CreateVolumeInfoItems(con.Volumes)
		if err != nil {
			return &ecs.RegisterTaskDefinitionOutput{}, err
		}

		mountPoints := []*ecs.MountPoint{}
		for _, vp := range volumeItems {
			volumes = append(volumes, vp.Volume)

			mountPoints = append(mountPoints, vp.MountPoint)
		}

		volumesFrom, err := toVolumesFroms(con.VolumesFrom)
		if err != nil {
			return &ecs.RegisterTaskDefinitionOutput{}, err
		}

		conDef := &ecs.ContainerDefinition{
			CPU:          &con.CpuUnits,
			Command:      commands,
			EntryPoint:   entryPoints,
			Environment:  toKeyValuePairs(con.Environment),
			Essential:    &con.Essential,
			Image:        aws.String(con.Image),
			Links:        util.ConvertPointerString(con.Links),
			Memory:       &con.Memory,
			MountPoints:  mountPoints,
			Name:         aws.String(con.Name),
			PortMappings: portMappings,
			VolumesFrom:  volumesFrom,
		}

		conDefs = append(conDefs, conDef)
	}

	params := &ecs.RegisterTaskDefinitionInput{
		ContainerDefinitions: conDefs,
		Family:               aws.String(taskName),
		Volumes:              volumes,
	}

	return svc.RegisterTaskDefinition(params)
}