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); foreach ($locations as $loc) { $loc_testers = json_decode(file_get_contents("./tmp/{$loc}.tm"), true); foreach ($loc_testers as $id => $info) { $elapsed = 0; if (array_key_exists('updated', $info) && $info['updated'] < $now) {
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); } } } } } }