diff --git a/README.md b/README.md index 8cb3b1e..475ec6f 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ 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) @@ -61,7 +61,7 @@ Create a configurable option named `Location`. Add options with the following co #### 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) @@ -69,7 +69,7 @@ Create a configurable option named `Operating System`. Add options with the foll #### 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) @@ -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`. diff --git a/docs/option-extra-ips.png b/docs/option-extra-ips.png new file mode 100644 index 0000000..224a83a Binary files /dev/null and b/docs/option-extra-ips.png differ diff --git a/modules/servers/solusiovps/lib/Database/Models/ProductConfigOption.php b/modules/servers/solusiovps/lib/Database/Models/ProductConfigOption.php index cd74083..d3e4a7f 100644 --- a/modules/servers/solusiovps/lib/Database/Models/ProductConfigOption.php +++ b/modules/servers/solusiovps/lib/Database/Models/ProductConfigOption.php @@ -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 { diff --git a/modules/servers/solusiovps/lib/SolusAPI/Requests/ServerCreateRequestBuilder.php b/modules/servers/solusiovps/lib/SolusAPI/Requests/ServerCreateRequestBuilder.php index 321457f..78ef2b9 100644 --- a/modules/servers/solusiovps/lib/SolusAPI/Requests/ServerCreateRequestBuilder.php +++ b/modules/servers/solusiovps/lib/SolusAPI/Requests/ServerCreateRequestBuilder.php @@ -73,6 +73,11 @@ final class ServerCreateRequestBuilder */ private $userId; + /** + * @var ?int + */ + private $additionalIpCount; + /** * @var ?array */ @@ -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); @@ -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; @@ -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; } diff --git a/tests/lib/SolusAPI/Requests/ServerCreateRequestBuilderTest.php b/tests/lib/SolusAPI/Requests/ServerCreateRequestBuilderTest.php index e6f8418..8edde34 100644 --- a/tests/lib/SolusAPI/Requests/ServerCreateRequestBuilderTest.php +++ b/tests/lib/SolusAPI/Requests/ServerCreateRequestBuilderTest.php @@ -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); @@ -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', ]); } @@ -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); @@ -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], + ]); + } }