Skip to main content

Reference

The \WHMCS\Module\Server\Katapult\WHMCS\Service\VirtualMachine class ultimately extends from the WHMCS service model, WHMCS\Service\Service, which is a Laravel model, which references tblhosting in the WHMCS database.

This module uses the Salmon datastore to persist data to WHMCS, outside the default tables, using mod_salmon_data_store_items. Data such as VM ID, build ID, organization ID and the encrypted API key are stored in this table.

Because of its parentage, you can instantiate a Katapult service like this:

use \WHMCS\Module\Server\Katapult\WHMCS\Service\VirtualMachine as VirtualMachineService;
use Krystal\Katapult\API\RestfulKatapultApiV1\Resources\Organization\VirtualMachine as KatapultVirtualMachine;

/** @var VirtualMachineService $katapultService */
$katapultService = VirtualMachineService::findOrFail(1337); // 1337 being the ID of the service in tblhosting

// You can then access various details about the service and even the virtual machine itself
$katapultService->vm_build_id; // string|null - The build ID Katapult created for the VM
$katapultService->vm_build_started_at; // \Carbon\Carbon|null - When WHMCS requested the VM build
$katapultService->vm_id; // string|null - The VM ID. This is only available once the VM has been built.
$katapultService->vm; // KatapultVirtualMachine|null - the live VM instance from Katapult. It is cached per request lifecycle.
$katapultService->vm_state; // string - note, this will be 'unknown' if the VM does not exist

/** @var KatapultVirtualMachine|null $virtualMachine */
$virtualMachine = $katapultService->vm;

// Assuming we have a VM, we can perform actions against it
$virtualMachine->start();
$virtualMachine->stop();
$virtualMachine->shutdown();
$virtualMachine->reset();
$virtualMachine->createConsoleSession();

More details about interacting with the Katapult VM instance can be found in the Katault PHP library.