Skip to content

Commit

Permalink
Merge pull request #75 from solusio/task-dromashov-support-additional…
Browse files Browse the repository at this point in the history
…-ips-SIO-4292

TASK SIO-4292 Support additional IPs
  • Loading branch information
rincler authored Jun 7, 2022
2 parents 0846208 + d0a601d commit 8b08e02
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 22 deletions.
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,23 @@ Select the `Plan`, `Default Location` and `Default Operating System` or `Applica

#### Locations

The module gives the ability to select a specific location on ordering of a product. You can manage the list of available locations in the Configurable Options.
The module gives the ability to select a specific location while ordering a product. You can manage the list of available locations in the Configurable Options.

![Location](./docs/option-location.png)

Create a configurable option named `Location`. Add options with the following convention: `locationId|locationName`. The option will have higher priority over the selected location in the Module Settings of a product.

#### Operating Systems

The module gives the ability to select a specific operating system on ordering of a product. You can manage the list of available operating systems in the Configurable Options.
The module gives the ability to select a specific operating system while ordering a product. You can manage the list of available operating systems in the Configurable Options.

![Operating System](./docs/option-os.png)

Create a configurable option named `Operating System`. Add options with the following convention: `osId|osName`. The option will have higher priority over the selected operating system in the Module Settings of a product.

#### Plan parameters

The module gives the ability to select specific plan parameters such as `VCPU`, `Memory`, `Disk Space`, `Total traffic limit monthly` (for KVM and VZ), `VCPU Units`, `VCPU Limit`, `IO Priority`, and `Swap` (for VZ).
The module gives the ability to select specific plan parameters such as `VCPU`, `Memory`, `Disk Space`, `Total traffic limit monthly` (for KVM and VZ), `VCPU Units`, `VCPU Limit`, `IO Priority`, and `Swap` (for VZ) while ordering a product.
You can manage the list of available plan parameters in the Configurable Options.

![VCPU](./docs/option-vcpu.png)
Expand All @@ -85,9 +85,18 @@ Create a configurable option with one of the following names: `VCPU`, `Memory`,

![Plan traffic limit required options](./docs/plan-traffic-limit-required-options.png)

#### Extra IPs

The module gives the ability to select the count of additional IPs while ordering a product. You can manage the list of allowed values in the Configurable Options.

![Extra IPs](./docs/option-extra-ips.png)

Create a configurable option named `Extra IP Address`. Add options with the following convention: `ip count|title`.
`Extra IP Address` option can only be used if the plan selected in Module Settings of a product has the `Offer additional IP addresses` option enabled in SolusIO.

#### SSH Key

The module gives the ability to specify an SSH key on ordering of a product. This is done in the form a product custom field.
The module gives the ability to specify an SSH key while ordering a product. This is done in the form a product custom field.

Create a custom field named `SSH Key` and type `Text Area`.

Expand Down
Binary file added docs/option-extra-ips.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ProductConfigOption
const IO_PRIORITY = 'IO Priority';
const SWAP = 'Swap';
const TOTAL_TRAFFIC_LIMIT_MONTHLY = 'Total traffic limit monthly';
const EXTRA_IP_ADDRESS = 'Extra IP Address';

public static function getProductOptions(int $productId, string $optionName): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ final class ServerCreateRequestBuilder
*/
private $userId;

/**
* @var ?int
*/
private $additionalIpCount;

/**
* @var ?array
*/
Expand Down Expand Up @@ -134,6 +139,10 @@ public static function fromWHMCSCreateAccountParams(array $params): self
$builder->withOperatingSystem($osId, $userData);
}

if ($additionalIpCount = self::getConfigOption($params, ProductConfigOption::EXTRA_IP_ADDRESS)) {
$builder->withAdditionalIps($additionalIpCount);
}

$customPlanData = self::extractCustomPlanData($params);
if ($customPlanData) {
$builder->withCustomPlan($customPlanData);
Expand Down Expand Up @@ -172,6 +181,13 @@ public function withUser(int $userId): self
return $this;
}

public function withAdditionalIps(int $additionalIpCount): self
{
$this->additionalIpCount = $additionalIpCount;

return $this;
}

public function withCustomPlan(array $customPlanData): self
{
$this->customPlanData = $customPlanData;
Expand Down Expand Up @@ -231,6 +247,10 @@ public function get(): array
$request['user'] = $this->userId;
}

if ($this->additionalIpCount) {
$request['additional_ip_count'] = $this->additionalIpCount;
}

if ($this->customPlanData) {
$request['custom_plan'] = $this->customPlanData;
}
Expand Down
54 changes: 36 additions & 18 deletions tests/lib/SolusAPI/Requests/ServerCreateRequestBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public function testBuildFromCreateAccountParamsWithOperatingSystemInConfigOpts(
{
$params = Arr::except($this->params, [ 'configoption4']);
$params['configoption5'] = 'user_data';
$params['configoptions']['Operating System'] = 1;
$params['configoptions'][ProductConfigOption::OPERATING_SYSTEM] = 1;

$builder = ServerCreateRequestBuilder::fromWHMCSCreateAccountParams($params);

Expand All @@ -162,7 +162,7 @@ public function testBuildFromCreateAccountParamsWithOperatingSystemInConfigOpts(
'location' => 1,
'password' => 'test_pass',
'fqdns' => [ 'test.domain.ltd' ],
'os' => 1,
'os' => $params['configoptions'][ProductConfigOption::OPERATING_SYSTEM] ,
'user_data' => 'user_data',
]);
}
Expand All @@ -186,14 +186,14 @@ public function testBuildFromCreateAccountParamsWithUser(): void

public function testBuildFromCreateAccountParamsWithCustomPlanConfigOptions(): void
{
$this->params['configoptions']['VCPU'] = 1;
$this->params['configoptions']['Memory'] = 2;
$this->params['configoptions']['Disk Space'] = 2;
$this->params['configoptions']['VCPU Units'] = 8;
$this->params['configoptions']['VCPU Limit'] = 10;
$this->params['configoptions']['IO Priority'] = 6;
$this->params['configoptions']['Swap'] = 4;
$this->params['configoptions']['Total traffic limit monthly'] = 5;
$this->params['configoptions'][ProductConfigOption::VCPU] = 1;
$this->params['configoptions'][ProductConfigOption::MEMORY] = 2;
$this->params['configoptions'][ProductConfigOption::DISK_SPACE] = 2;
$this->params['configoptions'][ProductConfigOption::VCPU_UNITS] = 8;
$this->params['configoptions'][ProductConfigOption::VCPU_LIMIT] = 10;
$this->params['configoptions'][ProductConfigOption::IO_PRIORITY] = 6;
$this->params['configoptions'][ProductConfigOption::SWAP] = 4;
$this->params['configoptions'][ProductConfigOption::TOTAL_TRAFFIC_LIMIT_MONTHLY] = 5;

$builder = ServerCreateRequestBuilder::fromWHMCSCreateAccountParams($this->params);

Expand All @@ -207,20 +207,38 @@ public function testBuildFromCreateAccountParamsWithCustomPlanConfigOptions(): v
'application_data' => [''],
'custom_plan' => [
'params' => [
'vcpu' => $this->params['configoptions']['VCPU'],
'ram' => $this->params['configoptions']['Memory'] * 1024 * 1024,
'disk' => $this->params['configoptions']['Disk Space'],
'vcpu_units' => $this->params['configoptions']['VCPU Units'],
'vcpu_limit' => $this->params['configoptions']['VCPU Limit'],
'io_priority' => $this->params['configoptions']['IO Priority'],
'swap' => $this->params['configoptions']['Swap'] * 1024 * 1024,
'vcpu' => $this->params['configoptions'][ProductConfigOption::VCPU],
'ram' => $this->params['configoptions'][ProductConfigOption::MEMORY] * 1024 * 1024,
'disk' => $this->params['configoptions'][ProductConfigOption::DISK_SPACE],
'vcpu_units' => $this->params['configoptions'][ProductConfigOption::VCPU_UNITS],
'vcpu_limit' => $this->params['configoptions'][ProductConfigOption::VCPU_LIMIT],
'io_priority' => $this->params['configoptions'][ProductConfigOption::IO_PRIORITY],
'swap' => $this->params['configoptions'][ProductConfigOption::SWAP] * 1024 * 1024,
],
'limits' => [
'network_total_traffic' => [
'limit' => $this->params['configoptions']['Total traffic limit monthly'],
'limit' => $this->params['configoptions'][ProductConfigOption::TOTAL_TRAFFIC_LIMIT_MONTHLY],
],
],
],
]);
}

public function testBuildFromCreateAccountParamsWithExtraIpAddressConfigOptions(): void
{
$this->params['configoptions'][ProductConfigOption::EXTRA_IP_ADDRESS] = 3;

$builder = ServerCreateRequestBuilder::fromWHMCSCreateAccountParams($this->params);

self::assertEquals($builder->get(), [
'name' => 'test.domain.ltd',
'plan' => 1,
'location' => 1,
'password' => 'test_pass',
'fqdns' => [ 'test.domain.ltd' ],
'application' => 1,
'application_data' => [''],
'additional_ip_count' => $this->params['configoptions'][ProductConfigOption::EXTRA_IP_ADDRESS],
]);
}
}

0 comments on commit 8b08e02

Please sign in to comment.