HostFact - VPS
VPS dienst
Op deze pagina worden alle functies besproken om VPS diensten te kunnen aanmaken, beheren en te beƫindigen.
createVPS()
Maakt een VPS dienst aan op het platform.
Beschikbare variabelen | Beschrijving |
---|---|
$this->VPSName | VPS (host)naam |
$this->Password | Wachtwoord |
$this->MemoryMB | Geheugen in MBs |
$this->CPUCores | Aantal CPU cores |
$this->DiskSpaceGB | Webruimte in MBs |
$this->TemplateID | ID van de template op het platform |
$this->Image | ID van de image op het platform |
Voorbeeld implementatie
public function createVPS() { // available variables: $this->VPSName; $this->Password; $this->MemoryMB; $this->CPUCores; $this->DiskSpaceGB; $this->TemplateID; $this->Image; /** * Step 1) send create command * */ $response = TRUE; /** * Step 2) provide feedback to HostFact */ if($response && isset($response->server->id) && $response->server->id) { $vps = array(); $vps['id'] = $response->server->id; return $vps; } else { return FALSE; } }
delete()
Verwijdert een VPS.
Beschikbare variabelen | Beschrijving |
---|---|
$vps_id | ID van de VPS op het platform |
Voorbeeld implementatie
public function delete($vps_id) { /** * Step 1) send delete command * */ $response = TRUE; /** * Step 2) provide feedback to HostFact */ if($response) { return TRUE; } else { return FALSE; } }
doPending()
Wanneer een VPS is aangemaakt, wordt deze functie regelmatig aangeroepen om de status van de VPS op te vragen.
Beschikbare variabelen | Beschrijving |
---|---|
$vps_id | ID van de VPS op het platform |
Voorbeeld implementatie
public function doPending($vps_id) { /** * Step 1) send get VPS command (we need the VPS status) * */ $response = TRUE; /** * Step 2) provide feedback to HostFact * based on the VPS status you get from the response, return either active, building or error */ if($response) { switch($this->__convertStatus($response->server->status)) { case 'active': return 'active'; break; case 'building': return 'building'; break; default: return 'error'; break; } } return 'error'; }
doServerAction()
Voert een actie uit op de VPS (bijvoorbeeld starten, stoppen, pauzeren).
Beschikbare variabelen | Beschrijving |
---|---|
$vps_id | ID van de VPS op het platform |
$action | De uit te voeren actie, pause|start|restart |
Voorbeeld implementatie
public function doServerAction($vps_id, $action) { switch($action) { case 'pause': /** * Step 1) send pause command */ $response = TRUE; break; case 'start': /** * Step 1) send start command */ $response = TRUE; break; case 'restart': /** * Step 1) send restart command */ $response = TRUE; break; } /** * Step 2) provide feedback to HostFact */ if($response) { return TRUE; } else { return FALSE; } }
getVPSByHostname()
Haal de informatie op van een VPS op basis van hostnaam.
Beschikbare variabelen | Beschrijving |
---|---|
$hostname | Hostnaam |
Voorbeeld implementatie
public function getVPSByHostname($hostname) { /** * Step 1) send get VPS command, if there ain't a specific command to get VPS by hostname, retrieve all VPS and loop through them * */ $response = TRUE; /** * Step 2) provide feedback to HostFact */ $vps = array(); if($response && is_array($response->servers) && count($response->servers) > 0) { // loop through servers foreach($response->servers as $server) { if($hostname == $server->name) { $vps['id'] = $server->id; $vps['status'] = $this->__convertStatus($server->status); } } } if(isset($vps['id'])) { return $vps; } return FALSE; }
getVPSDetails()
Haal de informatie op van een VPS op basis van ID.
Beschikbare variabelen | Beschrijving |
---|---|
$vps_id | ID van de VPS op het platform |
Voorbeeld implementatie
public function getVPSDetails($vps_id) { /** * Step 1) send get VPS command * */ $response = TRUE; /** * Step 2) provide feedback to HostFact */ if($response) { $vps_details = array(); $vps_details['status'] = $this->__convertStatus($response->server->status); $vps_details['hostname'] = $response->server->name; $vps_details['ipaddress'] = $response->server->address; // not required return $vps_details; } return FALSE; }
suspend()
Blokkeer/deblokkeer een VPS.
Beschikbare variabelen | Beschrijving |
---|---|
$vps_id | ID van de VPS op het platform |
$action | De uit te voeren actie, suspend|unsuspend |
Voorbeeld implementatie
public function suspend($vps_id, $action) { if(!$this->__login()) { return FALSE; } switch($action) { case 'suspend': /** * Step 1) send suspend command * */ $response = TRUE; break; case 'unsuspend': /** * Step 1) send unsuspend command * */ $response = TRUE; break; } /** * Step 2) provide feedback to HostFact */ if($response) { return TRUE; } else { return FALSE; } }