コード例 #1
0
ファイル: simpledbs.go プロジェクト: murdinc/awsm
// GetSimpleDBDomains returns a slice of SimpleDB Domains that match the provided search term
func GetSimpleDBDomains(search string) (*SimpleDBDomains, []error) {
	var wg sync.WaitGroup
	var errs []error

	domainList := new(SimpleDBDomains)
	regions := regions.GetRegionList()

	for _, region := range regions {
		wg.Add(1)

		go func(region *ec2.Region) {
			defer wg.Done()
			err := GetRegionSimpleDBDomains(region.RegionName, domainList, search)
			if err != nil {
				// TODO handle regions without service endpoints that work
				terminal.ShowErrorMessage(fmt.Sprintf("Error gathering simpledb domain list for region [%s]", *region.RegionName), err.Error())
				errs = append(errs, err)
			}
		}(region)
	}

	wg.Wait()

	return domainList, errs
}
コード例 #2
0
ファイル: snapshots.go プロジェクト: murdinc/awsm
// rotateSnapshots rotates out older Snapshots
func rotateSnapshots(class string, cfg config.SnapshotClass, dryRun bool) error {
	var wg sync.WaitGroup
	var errs []error

	launchConfigs, err := GetLaunchConfigurations("")
	if err != nil {
		return errors.New("Error while retrieving the list of assets to exclude from rotation!")
	}
	excludedSnaps := launchConfigs.LockedSnapshotIds()

	regions := regions.GetRegionList()

	for _, region := range regions {
		wg.Add(1)

		go func(region *ec2.Region) {
			defer wg.Done()

			// Get all the snapshots of this class in this region
			snapshots, err := GetSnapshotsByTag(*region.RegionName, "Class", class)
			if err != nil {
				terminal.ShowErrorMessage(fmt.Sprintf("Error gathering snapshot list for region [%s]", *region.RegionName), err.Error())
				errs = append(errs, err)
			}

			// Exclude the snapshots being used in Launch Configurations
			for i, snap := range snapshots {
				if excludedSnaps[snap.SnapshotID] {
					terminal.Information("Snapshot [" + snap.Name + " (" + snap.SnapshotID + ") ] is being used in a launch configuration, skipping!")
					snapshots = append(snapshots[:i], snapshots[i+1:]...)
				}
			}

			// Delete the oldest ones if we have more than the retention number
			if len(snapshots) > cfg.Retain {
				sort.Sort(snapshots) // important!
				ds := snapshots[cfg.Retain:]
				deleteSnapshots(&ds, dryRun)
			}

		}(region)
	}
	wg.Wait()

	if errs != nil {
		return errors.New("Error rotating snapshots for [" + class + "]!")
	}

	return nil
}
コード例 #3
0
ファイル: launchconfigurations.go プロジェクト: murdinc/awsm
// RotateLaunchConfigurations rotates out older Launch Configurations
func RotateLaunchConfigurations(class string, cfg config.LaunchConfigurationClass, dryRun bool) error {
	var wg sync.WaitGroup
	var errs []error

	autoScaleGroups, err := GetAutoScaleGroups("")
	if err != nil {
		return errors.New("Error while retrieving the list of launch configurations to exclude from rotation!")
	}
	excludedConfigs := autoScaleGroups.LockedLaunchConfigurations()

	regions := regions.GetRegionList()

	for _, region := range regions {
		wg.Add(1)

		go func(region *ec2.Region) {
			defer wg.Done()

			// Get all the launch configs of this class in this region
			launchConfigs, err := GetLaunchConfigurationsByName(*region.RegionName, class)
			if err != nil {
				terminal.ShowErrorMessage(fmt.Sprintf("Error gathering launch configuration list for region [%s]", *region.RegionName), err.Error())
				errs = append(errs, err)
			}

			// Exclude the launch configs being used in Autoscale Groups
			for i, lc := range launchConfigs {
				if excludedConfigs[lc.Name] {
					terminal.Information("Launch Configuration [" + lc.Name + ") ] is being used in an autoscale group, skipping!")
					launchConfigs = append(launchConfigs[:i], launchConfigs[i+1:]...)
				}
			}

			// Delete the oldest ones if we have more than the retention number
			if len(launchConfigs) > cfg.Retain {
				sort.Sort(launchConfigs) // important!
				ds := launchConfigs[cfg.Retain:]
				deleteLaunchConfigurations(&ds, dryRun)
			}

		}(region)
	}
	wg.Wait()

	if errs != nil {
		return errors.New("Error rotating snapshots for [" + class + "]!")
	}

	return nil
}
コード例 #4
0
ファイル: snapshots.go プロジェクト: murdinc/awsm
// GetSnapshots returns a slice of EBS Snapshots that match the provided search term and optional completed flag
func GetSnapshots(search string, completed bool) (*Snapshots, []error) {
	var wg sync.WaitGroup
	var errs []error

	snapList := new(Snapshots)
	regions := regions.GetRegionList()

	for _, region := range regions {
		wg.Add(1)

		go func(region *ec2.Region) {
			defer wg.Done()
			err := GetRegionSnapshots(*region.RegionName, snapList, search, completed)
			if err != nil {
				terminal.ShowErrorMessage(fmt.Sprintf("Error gathering snapshot list for region [%s]", *region.RegionName), err.Error())
				errs = append(errs, err)
			}
		}(region)
	}
	wg.Wait()

	return snapList, errs
}
コード例 #5
0
ファイル: volumes.go プロジェクト: murdinc/awsm
// GetVolumes returns a slice of Volumes that match the provided search term and optional available flag
func GetVolumes(search string, available bool) (*Volumes, []error) {
	var wg sync.WaitGroup
	var errs []error

	volList := new(Volumes)
	regions := regions.GetRegionList()

	for _, region := range regions {
		wg.Add(1)

		go func(region *ec2.Region) {
			defer wg.Done()
			err := GetRegionVolumes(*region.RegionName, volList, search, available)
			if err != nil {
				terminal.ShowErrorMessage(fmt.Sprintf("Error gathering volume list for region [%s]", *region.RegionName), err.Error())
				errs = append(errs, err)
			}
		}(region)
	}
	wg.Wait()

	return volList, errs
}
コード例 #6
0
ファイル: autoscalegroups.go プロジェクト: murdinc/awsm
// GetAutoScaleGroups returns a slice of AutoScale Groups based on the given search term
func GetAutoScaleGroups(search string) (*AutoScaleGroups, []error) {
	var wg sync.WaitGroup
	var errs []error

	asgList := new(AutoScaleGroups)
	regions := regions.GetRegionList()

	for _, region := range regions {
		wg.Add(1)

		go func(region *ec2.Region) {
			defer wg.Done()
			err := GetRegionAutoScaleGroups(*region.RegionName, asgList, search)
			if err != nil {
				terminal.ShowErrorMessage(fmt.Sprintf("Error gathering autoscale group list for region [%s]", *region.RegionName), err.Error())
				errs = append(errs, err)
			}
		}(region)
	}
	wg.Wait()

	return asgList, errs
}
コード例 #7
0
ファイル: alarms.go プロジェクト: murdinc/awsm
// GetAlarms returns a slice of CloudWatch Alarms
func GetAlarms() (*Alarms, []error) {
	var wg sync.WaitGroup
	var errs []error

	alList := new(Alarms)
	regions := regions.GetRegionList()

	for _, region := range regions {
		wg.Add(1)

		go func(region *ec2.Region) {
			defer wg.Done()
			err := GetRegionAlarms(*region.RegionName, alList)
			if err != nil {
				terminal.ShowErrorMessage(fmt.Sprintf("Error gathering alarm list for region [%s]", *region.RegionName), err.Error())
				errs = append(errs, err)
			}
		}(region)
	}
	wg.Wait()

	return alList, errs
}
コード例 #8
0
ファイル: launchconfigurations.go プロジェクト: murdinc/awsm
// GetLaunchConfigurations returns a slice of Launch Configurations that match the provided search term
func GetLaunchConfigurations(search string) (*LaunchConfigs, []error) {
	var wg sync.WaitGroup
	var errs []error

	lcList := new(LaunchConfigs)
	regions := regions.GetRegionList()

	for _, region := range regions {
		wg.Add(1)

		go func(region *ec2.Region) {
			defer wg.Done()
			err := GetRegionLaunchConfigurations(*region.RegionName, lcList, search)
			if err != nil {
				terminal.ShowErrorMessage(fmt.Sprintf("Error gathering launch config list for region [%s]", *region.RegionName), err.Error())
				errs = append(errs, err)
			}
		}(region)
	}
	wg.Wait()

	return lcList, errs
}
コード例 #9
0
ファイル: scalingpolicies.go プロジェクト: murdinc/awsm
// GetScalingPolicies returns a slice of Scaling Policies
func GetScalingPolicies() (*ScalingPolicies, []error) {
	var wg sync.WaitGroup
	var errs []error

	spList := new(ScalingPolicies)
	regions := regions.GetRegionList()

	for _, region := range regions {
		wg.Add(1)

		go func(region *ec2.Region) {
			defer wg.Done()
			err := GetRegionScalingPolicies(*region.RegionName, spList)
			if err != nil {
				terminal.ShowErrorMessage(fmt.Sprintf("Error gathering scaling policy list for region [%s]", *region.RegionName), err.Error())
				errs = append(errs, err)
			}
		}(region)
	}
	wg.Wait()

	return spList, errs
}
コード例 #10
0
ファイル: loadbalancersV2.go プロジェクト: murdinc/awsm
// GetLoadBalancersV2 returns a slice of Application Load Balancers
func GetLoadBalancersV2() (*LoadBalancersV2, []error) {
	var wg sync.WaitGroup
	var errs []error

	lbList := new(LoadBalancersV2)
	regions := regions.GetRegionList()

	for _, region := range regions {
		wg.Add(1)

		go func(region *ec2.Region) {
			defer wg.Done()
			err := GetRegionLoadBalancersV2(*region.RegionName, lbList)
			if err != nil {
				terminal.ShowErrorMessage(fmt.Sprintf("Error gathering loadbalancer list for region [%s]", *region.RegionName), err.Error())
				errs = append(errs, err)
			}
		}(region)
	}
	wg.Wait()

	return lbList, errs
}
コード例 #11
0
ファイル: keypairs.go プロジェクト: murdinc/awsm
// GetKeyPairs returns a slice of KeyPairs that match the provided search term
func GetKeyPairs(search string) (*KeyPairs, []error) {
	var wg sync.WaitGroup
	var errs []error

	keyList := new(KeyPairs)
	regions := regions.GetRegionList()

	for _, region := range regions {
		wg.Add(1)

		go func(region *ec2.Region) {
			defer wg.Done()
			err := GetRegionKeyPairs(*region.RegionName, keyList, search)
			if err != nil {
				terminal.ShowErrorMessage(fmt.Sprintf("Error gathering key pair list for region [%s]", *region.RegionName), err.Error())
				errs = append(errs, err)
			}
		}(region)
	}

	wg.Wait()

	return keyList, errs
}
コード例 #12
0
ファイル: instances.go プロジェクト: murdinc/awsm
// GetInstances returns a list of EC2 Instances that match the provided search term and optional running flag
func GetInstances(search string, running bool) (*Instances, []error) {
	var wg sync.WaitGroup
	var errs []error

	instList := new(Instances)
	regions := regions.GetRegionList()

	for _, region := range regions {
		wg.Add(1)

		go func(region *ec2.Region) {
			defer wg.Done()
			err := GetRegionInstances(*region.RegionName, instList, search, running)
			if err != nil {
				terminal.ShowErrorMessage(fmt.Sprintf("Error gathering instance list for region [%s]", *region.RegionName), err.Error())
				errs = append(errs, err)
			}
		}(region)
	}

	wg.Wait()

	return instList, errs
}