Exemplo n.º 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
}
Exemplo n.º 2
0
func (c *AWSCluster) Delete() {
	c.cf = cloudformation.New(c.creds, c.Region, nil)
	stackEventsSince := time.Now()
	c.base.setState("deleting")
	if err := c.fetchStack(); err != StackNotFoundError {
		if err := c.wrapRequest(func() error {
			return c.cf.DeleteStack(&cloudformation.DeleteStackInput{
				StackName: aws.String(c.StackName),
			})
		}); err != nil {
			err = fmt.Errorf("Unable to delete stack %s: %s", c.StackName, err)
			c.base.SendError(err)
			if !c.base.YesNoPrompt(fmt.Sprintf("%s\nWould you like to remove it from the installer?", err.Error())) {
				c.base.setState("error")
				return
			}
		} else if err := c.waitForStackCompletion("DELETE", stackEventsSince); err != nil {
			c.base.SendError(err)
		}
	}
	if err := c.base.MarkDeleted(); err != nil {
		c.base.SendError(err)
	}
	c.base.sendEvent(&Event{
		ClusterID:   c.base.ID,
		Type:        "cluster_state",
		Description: "deleted",
	})
}
Exemplo n.º 3
0
func (c *AWSCluster) Delete() {
	c.cf = cloudformation.New(c.creds, c.Region, nil)
	stackEventsSince := time.Now()
	c.base.setState("deleting")
	if err := c.fetchStack(); err != StackNotFoundError {
		if err := c.wrapRequest(func() error {
			return c.cf.DeleteStack(&cloudformation.DeleteStackInput{
				StackName: aws.String(c.StackName),
			})
		}); err != nil {
			c.base.setState("error")
			c.base.SendError(fmt.Errorf("Unable to delete stack %s: %s", c.StackName, err))
		} else {
			if err := c.waitForStackCompletion("DELETE", stackEventsSince); err != nil {
				c.base.SendError(err)
			}
		}
	}
	if err := c.base.MarkDeleted(); err != nil {
		c.base.SendError(err)
	}
	c.base.sendEvent(&Event{
		ClusterID:   c.base.ID,
		Type:        "cluster_state",
		Description: "deleted",
	})
}
Exemplo n.º 4
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
}