Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Additional Allocations #2

Closed
wants to merge 22 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
36d9832
Added the base code multi-port allocations.
snags141 Dec 9, 2021
8109275
Updated readme FAQ for multiple port allocations
snags141 Dec 9, 2021
d2faa67
Added the patch call to add additional allocations
snags141 Dec 9, 2021
07b08a8
Fixed missing ; and added additional call to get server ID
snags141 Dec 9, 2021
4663e7a
Mostly finished general implementation and tested in dev
snags141 Dec 12, 2021
8632739
Updated to new method - assigns additional allocs at server create
snags141 Jan 3, 2022
490b7cb
Updated readme FAQ section for multi-allocations, updated permissions…
snags141 Jan 3, 2022
fd5f942
Removed unecessary log and comments
snags141 Jan 4, 2022
fd8447b
Final readme update
snags141 Jan 4, 2022
f5622b0
Fixed a logic issue when multiple nodes are present at a location. Mi…
snags141 Jan 4, 2022
e5bb7b4
Minor wording change to reduce confusion
snags141 Jan 4, 2022
98cde61
initial
snags141 Jan 5, 2022
f98eec8
changed logActivity calls to module log and added port array
snags141 Jan 5, 2022
21e4c52
Updated logic to use new json method of additional port assignments. …
snags141 Jan 5, 2022
16a79b3
Merge pull request #2 from snags141/feature/allocationsInStartParams
snags141 Jan 5, 2022
e167824
Updated the description for additional_ports config option
snags141 Jan 5, 2022
45e32d6
Merge pull request #3 from snags141/feature/allocationsInStartParams
snags141 Jan 5, 2022
1a42e04
Updated json format and added links to readme in whmcs config options…
snags141 Jan 5, 2022
7750750
Moved new whmcs config options to the bottom of the list to maintain …
snags141 Jan 5, 2022
e039d02
Removed two duplicate lines of API error handling
snags141 Jan 5, 2022
ef75fb2
Removed redundant test from getNodes()
snags141 Jan 5, 2022
58bdf25
Updated readme with new json format.
snags141 Jan 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Updated to new method - assigns additional allocs at server create
snags141 committed Jan 3, 2022
commit 8632739725944ddbce255b7cae9de60ff1f32a6a
26 changes: 18 additions & 8 deletions wisp/wisp.php
Original file line number Diff line number Diff line change
@@ -385,6 +385,10 @@ function wisp_CreateAccount(array $params) {
'allocations' => (int) $allocations,
'backup_megabytes_limit' => (int) $backup_megabytes_limit,
],
/*'allocation' => [
'default' => $final_allocations['main_allocation_id'],
'additional' => $final_allocations['additional_allocation_ids'],
],*/
'deploy' => [
'locations' => [(int) $location_id],
'dedicated_ip' => $dedicated_ip,
@@ -414,7 +418,12 @@ function wisp_CreateAccount(array $params) {

if($final_allocations['status'] == true) {
logActivity("Successfully found an allocation. Setting primary allocation to ID " . $final_allocations['main_allocation_id']);
logActivity("Successfully found additional allocations: " . $final_allocations['additional_allocation_ids']);
foreach($final_allocations['additional_allocation_ids'] as $alloc_key => $alloc_id) {
logActivity("Got additional alloc: " . $alloc_id);
}
$serverData['allocation']['default'] = intval($final_allocations['main_allocation_id']);
$serverData['allocation']['additional'] = $final_allocations['additional_allocation_ids'];
} else {
logActivity("Failed to find an available allocation.");
}
@@ -428,6 +437,7 @@ function wisp_CreateAccount(array $params) {
}

// Create the game server
logActivity("Creating the server ");
$server = wisp_API($params, 'servers', $serverData, 'POST');
if($server['status_code'] === 400) throw new Exception('Couldn\'t find any nodes satisfying the request.');
if($server['status_code'] !== 201) throw new Exception('Failed to create the server, received the error code: ' . $server['status_code'] . '. Enable module debug log for more info.');
@@ -436,18 +446,18 @@ function wisp_CreateAccount(array $params) {
$serverId = wisp_GetServerID($params);
logActivity("Server ID is " . $serverId);
// Check the server status
$serverIsInstalled = false;
$timeoutCounter = 0;
//$serverIsInstalled = false;
//$timeoutCounter = 0;
logActivity('Logging install status next');
logActivity($serverStatus['attributes']['container']['installed']);
while($serverIsInstalled != true && $timeoutCounter <= 30) { // Hard coded timeout, can be tweaked here if more time is required due to slow internet connection etc..
/*while($serverIsInstalled != true && $timeoutCounter <= 30) { // Hard coded timeout, can be tweaked here if more time is required due to slow internet connection etc..
logActivity('Container isn\'t installed yet. Waiting... x'.strval($timeoutCounter));
sleep(3);
$serverStatus = wisp_API($params, 'servers/' . $serverId);
$serverIsInstalled = $serverStatus['attributes']['container']['installed'];
$timeoutCounter ++;
}
$timeoutCounter = 0;
$timeoutCounter = 0;*/

if($final_allocations['status'] == true) {

@@ -466,15 +476,15 @@ function wisp_CreateAccount(array $params) {
]

];
logActivity("Adding additional allocations to server. ");
$server = wisp_API($params, 'servers/' . $serverId . "/build", $patchData, 'PATCH');
//logActivity("Adding additional allocations to server. ");
//$server = wisp_API($params, 'servers/' . $serverId . "/build", $patchData, 'PATCH');
}
// Due to some edge cases where the container dies immediately after creation and is re-started,
// may need to try again a couple of times before the daemon will finally accept the request.
while(($server['status_code'] !== 201 && $server['status_code'] !== 200) && $timeoutCounter < 5 ) {
/*while(($server['status_code'] !== 201 && $server['status_code'] !== 200) && $timeoutCounter < 5 ) {
$server = wisp_API($params, 'servers/' . $serverId . "/build", $patchData, 'PATCH');
$timeoutCounter ++;
}
}*/


if($server['status_code'] === 400) throw new Exception('Couldn\'t find any nodes satisfying the request.');