ChangePackage.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. $ressource = new ResourceManager();
  47. logModuleCall(
  48. 'proxmoxCloud',
  49. __FUNCTION__,
  50. $ressource->vcpus(),
  51. 'Debug',
  52. $ressource->memory()
  53. );
  54. try {
  55. if(!ProxmoxAddonValidator::isInstalled()){
  56. return ProxmoxAddonValidator::failAsString();
  57. }
  58. (new AppParams())->initFromWhmcsParams();
  59. $this->networkService = new NetworkService();
  60. //Bandwith limit
  61. $this->saveUsageLimit();
  62. //Assing ip
  63. if (!Utility::isIpManagerProxmoxCloudIntegration())
  64. {
  65. list($ip4, $ip6) = $this->networkService->getIpAddressesRequest();
  66. $this->networkService->addIp($ip4, $ip6, $this->getDefaultNodeIfSet());
  67. }
  68. return "success";
  69. }catch (\Exception $ex)
  70. {
  71. if (ModuleSettings::isDebug())
  72. {
  73. logModuleCall(
  74. 'ProxmoxCloudVps',
  75. __CLASS__,
  76. [],
  77. null,
  78. $ex->getMessage() . " " . $ex->getTraceAsString()
  79. );
  80. }
  81. return $ex->getMessage();
  82. }
  83. }
  84. }