ChangePackage.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**********************************************************************
  3. * ProxmoxVPS developed. (26.03.19)
  4. * *
  5. *
  6. * CREATED BY MODULESGARDEN -> http://modulesgarden.com
  7. * CONTACT -> contact@modulesgarden.com
  8. *
  9. *
  10. * This software is furnished under a license and may be used and copied
  11. * only in accordance with the terms of such license and with the
  12. * inclusion of the above copyright notice. This software or any other
  13. * copies thereof may not be provided or otherwise made available to any
  14. * other person. No title to and ownership of the software is hereby
  15. * transferred.
  16. *
  17. *
  18. **********************************************************************/
  19. namespace ModulesGarden\Servers\ProxmoxCloudVps\App\Http\Actions;
  20. use ModulesGarden\ProxmoxAddon\App\Models\ModuleSettings;
  21. use ModulesGarden\ProxmoxAddon\App\Services\ApiService;
  22. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\HostingService;
  23. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\NetworkService;
  24. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\ProductService;
  25. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\UserService;
  26. use ModulesGarden\ProxmoxAddon\App\Services\Utility;
  27. use ModulesGarden\Servers\ProxmoxCloudVps\App\Helpers\AppParams;
  28. use ModulesGarden\Servers\ProxmoxCloudVps\App\Helpers\ProxmoxAddonValidator;
  29. use ModulesGarden\Servers\ProxmoxCloudVps\Core\App\Controllers\Instances\AddonController;
  30. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Traits\WhmcsParams;
  31. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\ResourceManager;
  32. class ChangePackage extends AddonController
  33. {
  34. use ApiService;
  35. use UserService;
  36. use ProductService;
  37. use WhmcsParams;
  38. use HostingService;
  39. /**
  40. * @param null $params
  41. * @return bool|string
  42. * @todo Resources validation
  43. */
  44. public function execute($params = null)
  45. {
  46. try {
  47. if(!ProxmoxAddonValidator::isInstalled()){
  48. return ProxmoxAddonValidator::failAsString();
  49. }
  50. (new AppParams())->initFromWhmcsParams();
  51. $this->networkService = new NetworkService();
  52. $this->ressource = new ResourceManager();
  53. if($this->ressource->vcpus()->getUsed() > $params['configoptions']['vcpus']){
  54. throw new \Exception('vCPUs wurden unterbucht');
  55. }
  56. if(($this->ressource->memory()->getUsed() / 1024) > $params['configoptions']['Memory Limit']){
  57. throw new \Exception('Memory wurde unterbucht');
  58. }
  59. if($this->ressource->disk()->getUsed() > $params['configoptions']['Storage Limit']){
  60. throw new \Exception('Storage wurde unterbucht');
  61. }
  62. if($this->ressource->ipv4()->getUsed() > $params['configoptions']['IP Addresses Limit']){
  63. throw new \Exception('IPv4 wurden unterbucht');
  64. }
  65. $this->resourceGuard()->backupLimit();
  66. //Bandwith limit
  67. $this->saveUsageLimit();
  68. //Assing ip
  69. if (!Utility::isIpManagerProxmoxCloudIntegration())
  70. {
  71. if($this->configuration()->isOrderPublicIp()){
  72. list($ip4, $ip6) = $this->networkService->getIpAddressesRequest();
  73. $bridge = $this->configuration()->getBridge();
  74. $this->networkService->addIp($ip4, $ip6, $this->getDefaultNodeIfSet(),$bridge);
  75. }
  76. }
  77. return "success";
  78. }catch (\Exception $ex)
  79. {
  80. if (ModuleSettings::isDebug())
  81. {
  82. logModuleCall(
  83. 'ProxmoxCloudVps',
  84. __CLASS__,
  85. [],
  86. null,
  87. $ex->getMessage() . " " . $ex->getTraceAsString()
  88. );
  89. }
  90. return $ex->getMessage();
  91. }
  92. }
  93. }