Exemple #1
0
// UpdateAutoScaleGroups updates existing AutoScale Groups that match the given search term to the provided version of Launch Configuration
func UpdateAutoScaleGroups(name, version string, double, dryRun bool) (err error) {

	// --dry-run flag
	if dryRun {
		terminal.Information("--dry-run flag is set, not making any actual changes!")
	}

	asgList, _ := GetAutoScaleGroups(name)

	if len(*asgList) > 0 {
		// Print the table
		asgList.PrintTable()
	} else {
		return errors.New("No AutoScaling Groups found, Aborting!")
	}

	// Confirm
	if !terminal.PromptBool("Are you sure you want to update these AutoScaling Groups?") {
		return errors.New("Aborting!")
	}

	// Delete 'Em
	err = updateAutoScaleGroups(asgList, version, double, dryRun)
	if err == nil {
		terminal.Information("Done!")
	}

	return
}
Exemple #2
0
// DeleteSimpleDBDomains deletes one or more SimpleDB Domains
func DeleteSimpleDBDomains(search, region string) (err error) {

	domainList := new(SimpleDBDomains)

	// Check if we were given a region or not
	if region != "" {
		err = GetRegionSimpleDBDomains(aws.String(region), domainList, search)
	} else {
		domainList, _ = GetSimpleDBDomains(search)
	}

	if err != nil {
		terminal.ErrorLine("Error gathering SimpleDB domains list")
		return
	}

	if len(*domainList) > 0 {
		// Print the table
		domainList.PrintTable()
	} else {
		terminal.ErrorLine("No SimpleDB Domains found, Aborting!")
		return
	}

	// Confirm
	if !terminal.PromptBool("Are you sure you want to delete these SimpleDB Domains?") {
		terminal.ErrorLine("Aborting!")
		return
	}

	// Delete 'Em
	for _, domain := range *domainList {
		svc := simpledb.New(session.New(&aws.Config{Region: aws.String(domain.Region)}))

		params := &simpledb.DeleteDomainInput{
			DomainName: aws.String(domain.Name),
		}
		_, err = svc.DeleteDomain(params)
		if err != nil {
			terminal.ErrorLine("Error while deleting SimpleDB Domain [" + domain.Name + "] in [" + domain.Region + "], Aborting!")
			return
		}
		terminal.Information("Deleted SimpleDB Domain [" + domain.Name + "] in [" + domain.Region + "]!")
	}

	terminal.Information("Done!")

	return
}
Exemple #3
0
// ResumeProcesses resumes AutoScaling actions on AutoScaling Groups that match the provided search term and (optional) region
func ResumeProcesses(search, region string, dryRun bool) (err error) {

	// --dry-run flag
	if dryRun {
		terminal.Information("--dry-run flag is set, not making any actual changes!")
	}

	asgList := new(AutoScaleGroups)

	// Check if we were given a region or not
	if region != "" {
		err = GetRegionAutoScaleGroups(region, asgList, search)
	} else {
		asgList, _ = GetAutoScaleGroups(search)
	}

	if err != nil {
		return errors.New("Error gathering Autoscale Group list")
	}

	if len(*asgList) > 0 {
		// Print the table
		asgList.PrintTable()
	} else {
		return errors.New("No Autoscale Groups found!")
	}

	// Confirm
	if !terminal.PromptBool("Are you sure you want to resume these Autoscale Groups?") {
		return errors.New("Aborting!")
	}

	// Resume 'Em
	if !dryRun {
		err = resumeProcesses(asgList)
		if err != nil {
			if awsErr, ok := err.(awserr.Error); ok {
				return errors.New(awsErr.Message())
			}
			return err
		}

		terminal.Information("Done!")
	}

	return
}
Exemple #4
0
// DeleteKeyPairs deletes an existing KeyPair from AWS
func DeleteKeyPairs(name string, dryRun bool) error {

	if dryRun {
		terminal.Information("--dry-run flag is set, not making any actual changes!")
	}

	keyList, err := GetKeyPairs(name)
	if err != nil {
		terminal.ErrorLine("Error gathering KeyPair list")
		return nil
	}

	if len(*keyList) > 0 {
		// Print the table
		keyList.PrintTable()
	} else {
		terminal.ErrorLine("No KeyPairs found, Aborting!")
		return nil
	}

	// Confirm
	if !terminal.PromptBool("Are you sure you want to delete these KeyPairs?") {
		terminal.ErrorLine("Aborting!")
		return nil
	}

	// Delete 'Em
	for _, key := range *keyList {
		svc := ec2.New(session.New(&aws.Config{Region: aws.String(key.Region)}))

		params := &ec2.DeleteKeyPairInput{
			KeyName: aws.String(key.KeyName),
			DryRun:  aws.Bool(dryRun),
		}

		_, err := svc.DeleteKeyPair(params)

		if err != nil {
			terminal.ErrorLine(err.Error())
		} else {
			terminal.Information("Deleted KeyPair [" + key.KeyName + "] in region [" + key.Region + "]!")
		}

	}

	return nil
}
Exemple #5
0
// DeleteSnapshots deletes one or more EBS Snapshots based on the given search term an optional region input.
func DeleteSnapshots(search, region string, dryRun bool) (err error) {

	// --dry-run flag
	if dryRun {
		terminal.Information("--dry-run flag is set, not making any actual changes!")
	}

	snapList := new(Snapshots)

	// Check if we were given a region or not
	if region != "" {
		err = GetRegionSnapshots(region, snapList, search, false)
	} else {
		snapList, _ = GetSnapshots(search, false)
	}

	if err != nil {
		return errors.New("Error gathering Snapshots list")
	}

	if len(*snapList) > 0 {
		// Print the table
		snapList.PrintTable()
	} else {
		return errors.New("No available Snapshots found, Aborting!")
	}

	// Confirm
	if !terminal.PromptBool("Are you sure you want to delete these Snapshots?") {
		return errors.New("Aborting!")
	}

	// Delete 'Em
	err = deleteSnapshots(snapList, dryRun)
	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok {
			return errors.New(awsErr.Message())
		}
		return err
	}

	terminal.Information("Done!")

	return nil
}
Exemple #6
0
// UpdateSecurityGroups updates one or more Security Groups that match the provided search term and optional region
func UpdateSecurityGroups(search, region string, dryRun bool) (err error) {

	// --dry-run flag
	if dryRun {
		terminal.Information("--dry-run flag is set, not making any actual changes!")
	}

	secGrpList := new(SecurityGroups)

	// Check if we were given a region or not
	if region != "" {
		err = GetRegionSecurityGroups(region, secGrpList, search)
	} else {
		secGrpList, _ = GetSecurityGroups(search)
	}

	if err != nil {
		return errors.New("Error gathering Security Groups list")
	}

	if len(*secGrpList) > 0 {
		// Print the table
		secGrpList.PrintTable()
	} else {
		return errors.New("No Security Groups found, Aborting!")
	}

	// Confirm
	if !terminal.PromptBool("Are you sure you want to update these Security Groups?") {
		return errors.New("Aborting!")
	}

	// Update 'Em
	err = updateSecurityGroups(secGrpList, dryRun)
	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok {
			return errors.New(awsErr.Message())
		}
		return err
	}

	terminal.Information("Done!")

	return nil
}
Exemple #7
0
// DeleteLaunchConfigurations deletes one or more Launch Configurations that match the provided search term and optional region
func DeleteLaunchConfigurations(search, region string, dryRun bool) (err error) {

	// --dry-run flag
	if dryRun {
		terminal.Information("--dry-run flag is set, not making any actual changes!")
	}

	lcList := new(LaunchConfigs)

	// Check if we were given a region or not
	if region != "" {
		err = GetRegionLaunchConfigurations(region, lcList, search)
	} else {
		lcList, _ = GetLaunchConfigurations(search)
	}

	if err != nil {
		return errors.New("Error gathering Launch Configuration list")
	}

	if len(*lcList) > 0 {
		// Print the table
		lcList.PrintTable()
	} else {
		return errors.New("No Launch Configurations found!")
	}

	// Confirm
	if !terminal.PromptBool("Are you sure you want to delete these Launch Configurations?") {
		return errors.New("Aborting!")
	}

	// Delete 'Em
	err = deleteLaunchConfigurations(lcList, dryRun)
	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok {
			return errors.New(awsErr.Message())
		}
		return err
	}

	terminal.Information("Done!")

	return nil
}
Exemple #8
0
// DeleteAutoScaleGroups deletes one or more AutoScale Groups that match the provided name and optionally the provided region
func DeleteAutoScaleGroups(name, region string, force, dryRun bool) (err error) {

	// --dry-run flag
	if dryRun {
		terminal.Information("--dry-run flag is set, not making any actual changes!")
	}

	asgList := new(AutoScaleGroups)

	// Check if we were given a region or not
	if region != "" {
		err = GetRegionAutoScaleGroups(region, asgList, name)
	} else {
		asgList, _ = GetAutoScaleGroups(name)
	}

	if err != nil {
		return errors.New("Error gathering AutoScaling Groups list")
	}

	if len(*asgList) > 0 {
		// Print the table
		asgList.PrintTable()
	} else {
		return errors.New("No AutoScaling Groups found, Aborting!")
	}

	// Confirm
	if !terminal.PromptBool("Are you sure you want to delete these AutoScaling Groups?") {
		return errors.New("Aborting!")
	}

	// Delete 'Em

	err = deleteAutoScaleGroups(asgList, force, dryRun)
	if err != nil {
		return err
	}

	terminal.Information("Done!")

	return nil
}
Exemple #9
0
// DeleteSubnets deletes one or more VPC Subnets based on the given name and optional region input.
func DeleteSubnets(name, region string, dryRun bool) (err error) {

	// --dry-run flag
	if dryRun {
		terminal.Information("--dry-run flag is set, not making any actual changes!")
	}

	subnetList := new(Subnets)

	// Check if we were given a region or not
	if region != "" {
		err = GetRegionSubnets(region, subnetList, name)
	} else {
		subnetList, _ = GetSubnets(name)
	}

	if err != nil {
		return errors.New("Error gathering Subnet list")
	}

	if len(*subnetList) > 0 {
		// Print the table
		subnetList.PrintTable()
	} else {
		return errors.New("No Subnets found, Aborting!")
	}

	// Confirm
	if !terminal.PromptBool("Are you sure you want to delete these Subnets?") {
		return errors.New("Aborting!")
	}

	// Delete 'Em
	err = deleteSubnets(subnetList, dryRun)
	if err != nil {
		return err
	}

	terminal.Information("Done!")

	return nil
}
Exemple #10
0
// RebootInstances reboots one or more instances based on the given search term an optional region input
func RebootInstances(search, region string, dryRun bool) (err error) {

	// --dry-run flag
	if dryRun {
		terminal.Information("--dry-run flag is set, not making any actual changes!")
	}

	instList := new(Instances)

	// Check if we were given a region or not
	if region != "" {
		err = GetRegionInstances(region, instList, search, true)
	} else {
		instList, _ = GetInstances(search, true)
	}

	if err != nil {
		return errors.New("Error gathering Instance list")
	}

	if len(*instList) > 0 {
		// Print the table
		instList.PrintTable()
	} else {
		return errors.New("No Instances found, Aborting!")
	}

	// Confirm
	if !terminal.PromptBool("Are you sure you want to reboot these Instances?") {
		return errors.New("Aborting!")
	}

	// Reboot 'Em
	err = rebootInstances(instList, dryRun)
	if err != nil {
		return err
	}

	terminal.Information("Done!")

	return nil
}
Exemple #11
0
// DeleteIAMUsers deletes one or more IAM Users that match the provided username
func DeleteIAMUsers(username string) (err error) {

	userList, err := GetIAMUsers(username)
	if err != nil {
		terminal.ErrorLine("Error gathering SimpleDB domains list")
		return
	}

	if len(*userList) > 0 {
		// Print the table
		userList.PrintTable()
	} else {
		terminal.ErrorLine("No IAM Users found, Aborting!")
		return
	}

	// Confirm
	if !terminal.PromptBool("Are you sure you want to delete these IAM Users?") {
		terminal.ErrorLine("Aborting!")
		return
	}

	// Delete 'Em
	for _, user := range *userList {
		svc := iam.New(session.New())

		params := &iam.DeleteUserInput{
			UserName: aws.String(user.UserName),
		}
		_, err := svc.DeleteUser(params)
		if err != nil {
			terminal.ErrorLine("Error while deleting IAM User [" + user.UserName + "], Aborting!")
			return err
		}
		terminal.Information("Deleted IAM User [" + user.UserName + "]!")
	}

	terminal.Information("Done!")

	return
}