DataSift\Storyplayer\HostLib\Ec2Vm::destroyHost PHP Method

destroyHost() public method

public destroyHost ( Ec2VmDetails $vmDetails ) : void
$vmDetails Ec2VmDetails
return void
    public function destroyHost($vmDetails)
    {
        // what are we doing?
        $log = usingLog()->startAction("destroy VM");
        // get our Ec2 client from the SDK
        $client = fromAws()->getEc2Client();
        // what is our instanceId?
        $instanceId = $vmDetails->ec2Instance['InstanceId'];
        // let's destroy the VM
        try {
            $log->addStep("destroy EC2 VM instance '{$instanceId}'", function () use($client, &$response, $instanceId) {
                $response = $client->terminateInstances(array("InstanceIds" => array($instanceId)));
            });
            // now, we need to wait until this instance has been terminated
            $log->addStep("wait for EC2 VM '{$instanceId}' to finish terminating", function () use($client, $vmDetails, $response, $instanceId) {
                $client->waitUntilInstanceTerminated(array('InstanceIds' => array($instanceId), 'waiter.interval' => 10, 'waiter.max_attempts' => 10));
            });
        } catch (Exception $e) {
            // something went wrong
            $log->endAction("VM failed to terminate :(");
            throw new E5xx_ActionFailed(__METHOD__, $e->getMessage());
        }
        // if we get here, we need to forget about this VM
        usingHostsTable()->removeHost($vmDetails->hostId);
        // all done
        $log->endAction();
    }