ChangePackage.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. logModuleCall(
  54. 'proxmoxCloud',
  55. __FUNCTION__,
  56. $this->ressource->vcpus(),
  57. 'Debug',
  58. $params
  59. );
  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. }