Beispiel #1
0
func (c *AWSCluster) SetDefaultsAndValidate() error {
	c.ClusterID = c.base.ID

	if c.StackName == "" {
		c.StackName = c.base.ID
	}

	if c.InstanceType == "" {
		c.InstanceType = DefaultInstanceType
	}

	if c.VpcCIDR == "" {
		c.VpcCIDR = "10.0.0.0/16"
	}

	if c.SubnetCIDR == "" {
		c.SubnetCIDR = "10.0.0.0/21"
	}

	if err := c.validateInputs(); err != nil {
		return err
	}

	c.base.SSHUsername = "******"

	if err := c.base.SetDefaultsAndValidate(); err != nil {
		return err
	}

	c.ec2 = ec2.New(c.creds, c.Region, nil)
	c.cf = cloudformation.New(c.creds, c.Region, nil)
	return nil
}
Beispiel #2
0
func amis(args *docopt.Args) {
	auth, err := aws.EnvCreds()
	if err != nil {
		log.Fatal(err)
	}

	manifest := &release.EC2Manifest{}

	if err := json.NewDecoder(os.Stdin).Decode(manifest); err != nil {
		log.Fatal(err)
	}

	for _, s := range strings.Split(args.String["<ids>"], ",") {
		regionID := strings.SplitN(s, ":", 2)
		svc := ec2.New(auth, regionID[0], nil)
		resp, err := svc.DescribeImages(&ec2.DescribeImagesRequest{ImageIDs: []string{regionID[1]}})
		if err != nil {
			log.Fatal(err)
		}
		if len(resp.Images) < 1 {
			log.Fatalln("Could not find image", regionID[1])
		}
		image := resp.Images[0]

		var snapshotID string
		for _, mapping := range image.BlockDeviceMappings {
			if *mapping.DeviceName == *image.RootDeviceName {
				snapshotID = *mapping.EBS.SnapshotID
			}
		}
		if snapshotID == "" {
			log.Fatalln("Could not determine RootDeviceSnapshotID for", regionID[1])
		}

		manifest.Add(args.String["<version>"], &release.EC2Image{
			ID:                   *image.ImageID,
			Name:                 *image.Name,
			Region:               regionID[0],
			OwnerID:              *image.OwnerID,
			RootDeviceType:       *image.RootDeviceType,
			RootDeviceName:       *image.RootDeviceName,
			RootDeviceSnapshotID: snapshotID,
			VirtualizationType:   *image.VirtualizationType,
			Hypervisor:           *image.Hypervisor,
		})

	}

	if err := json.NewEncoder(os.Stdout).Encode(manifest); err != nil {
		log.Fatal(err)
	}
}
Beispiel #3
0
func (c *AWSCluster) SetCreds(creds *Credential) error {
	if creds == nil || creds.ID == "aws_env" {
		c.base.CredentialID = "aws_env"
		awsCreds, err := aws.EnvCreds()
		if err != nil {
			return err
		}
		c.creds = awsCreds
	} else {
		c.base.credential = creds
		c.base.CredentialID = creds.ID
		c.creds = aws.Creds(creds.ID, creds.Secret, "")
	}
	c.ec2 = ec2.New(c.creds, c.Region, nil)
	c.cf = cloudformation.New(c.creds, c.Region, nil)
	return nil
}