예제 #1
0
    $instanceType = $instanceSize;
}
// we only terminate instances at the top of the hour, but we can add instances at other times
$addOnly = true;
$minute = (int) gmdate('i');
if ($minute < 5 || $minute > 55) {
    $addOnly = false;
}
$now = time();
echo "Fetching list of running instances...\n";
$ec2 = new AmazonEC2($keyID, $secret);
if ($ec2) {
    foreach ($regions as $region => &$amiData) {
        $ec2->set_region($region);
        // clean up any orphaned volumes
        $volumes = $ec2->describe_volumes();
        if (isset($volumes)) {
            foreach ($volumes->body->volumeSet->item as $item) {
                if ($item->status == 'available') {
                    $id = strval($item->volumeId);
                    $ec2->delete_volume($id);
                }
            }
        }
        foreach ($amiData as $ami => &$regionData) {
            $location = $regionData['location'];
            echo "\n{$region} ({$location}):\n";
            // load the valid testers in this location
            $testers = array();
            $locations = explode(',', $location);
            $locCount = count($locations);
예제 #2
0
function EC2_DeleteOrphanedVolumes()
{
    $key = GetSetting('ec2_key');
    $secret = GetSetting('ec2_secret');
    if ($key && $secret && GetSetting('ec2_prune_volumes')) {
        $ec2 = new AmazonEC2($key, $secret);
        $regions = array();
        $response = $ec2->describe_regions();
        if (isset($response) && $response->isOK()) {
            foreach ($response->body->regionInfo->item as $region) {
                $regions[] = (string) $region->regionName;
            }
        }
        foreach ($regions as $region) {
            $ec2->set_region($region);
            $volumes = $ec2->describe_volumes();
            if (isset($volumes)) {
                foreach ($volumes->body->volumeSet->item as $item) {
                    if ($item->status == 'available') {
                        $id = strval($item->volumeId);
                        $ec2->delete_volume($id);
                    }
                }
            }
        }
    }
}