GeneralSection.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. namespace ModulesGarden\Servers\ProxmoxCloudVps\App\UI\VmUpdate\Sections\Qemu;
  3. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\ProductService;
  4. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\ResourceManager;
  5. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Validators\CpulimitValidator;
  6. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Validators\HostnameValidator;
  7. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Validators\IpAddressValidator;
  8. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Validators\NumberValidator;
  9. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Validators\SshPublicKeyValidator;
  10. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\VmCreate\Validators\DiskSizeValidator;
  11. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\VmCreate\Validators\PasswordValidator;
  12. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Fields\Range;
  13. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Fields\Select;
  14. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Fields\Text;
  15. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Fields\Textarea;
  16. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Sections\BaseSection;
  17. use function ModulesGarden\Servers\ProxmoxCloudVps\Core\Helper\isAdmin;
  18. use function ModulesGarden\Servers\ProxmoxCloudVps\Core\Helper\sl;
  19. class GeneralSection extends BaseSection
  20. {
  21. use ProductService;
  22. /**
  23. * @var ResourceManager
  24. */
  25. protected $resourceManager;
  26. public function initContent()
  27. {
  28. $this->initIds('generalSection');
  29. $this->unsetShowTitle();
  30. $this->resourceManager = new ResourceManager();
  31. $this->resourceManager->notVmIds([\ModulesGarden\ProxmoxAddon\Core\Helper\sl('Vm')->getVmModel()->id]);
  32. $this->initFields();
  33. }
  34. public function initFields()
  35. {
  36. $vm = \ModulesGarden\ProxmoxAddon\Core\Helper\sl('Vm')->getVm();
  37. $cpuPrioryty = $this->configuration()->hasCpuPriority();
  38. //name
  39. $field = new Text('name');
  40. $field->addValidator(new HostnameValidator());
  41. $field->setDescription('description');
  42. $this->addField($field);
  43. //description
  44. $field = new Textarea('description');
  45. $field->setDescription('description');
  46. $this->addField($field);
  47. if(isAdmin() || $this->configuration()->isPermissionIsoImage() && $vm->getCdRom()->count()){
  48. $field = new Select("iso");
  49. $field->notEmpty();
  50. $this->addField($field);
  51. }
  52. //password
  53. if($this->configuration()->isPermissionPassword()){
  54. $field = new Text('password');
  55. $field->addValidator( new PasswordValidator());
  56. $field->setDescription('description');
  57. $this->addField($field);
  58. }
  59. //sshkeys
  60. if($this->configuration()->isPermissionSshkeys()){
  61. $field = new Textarea("sshkeys");
  62. $field->addValidator(new SshPublicKeyValidator(false));
  63. $this->addField($field);
  64. }
  65. //sockets
  66. if($this->configuration()->isPermissionSockets() && !$this->configuration()->isCalculateSocketsAndCores()){
  67. $field = new Text('sockets');
  68. $field->addValidator(new NumberValidator($this->resourceManager->sockets()->getMin(), $this->resourceManager->sockets()->free(),true));
  69. $field->setDescription('description');
  70. $this->addField($field);
  71. }
  72. //cores
  73. if($this->configuration()->isPermissionCores() && !$this->configuration()->isCalculateSocketsAndCores()){
  74. $field = new Text('cores');
  75. $field->addValidator(new NumberValidator($this->resourceManager->cores()->getMin(), $this->resourceManager->cores()->free(),true));
  76. $field->setDescription('description');
  77. $this->addField($field);
  78. }
  79. //vcpus
  80. if($this->configuration()->isPermissionVcpus() || $this->configuration()->isCalculateSocketsAndCores()){
  81. $field = new Range('vcpus',$this->resourceManager->vcpus()->getMin(), $this->resourceManager->vcpus()->free());
  82. $field->addValidator(new NumberValidator($this->resourceManager->vcpus()->getMin(), $this->resourceManager->vcpus()->free(),true));
  83. $field->setDescription('description');
  84. $this->addField($field);
  85. }
  86. //cpu priority
  87. if($cpuPrioryty){
  88. $field = new Range('cpuPriority', $this->resourceManager->cpuPriority()->getMin(), $this->resourceManager->cpuPriority()->free());
  89. $field->addValidator(new NumberValidator($this->resourceManager->cpuPriority()->getMin(), $this->resourceManager->cpuPriority()->free(),true));
  90. $field->setDescription('description');
  91. $field->addHtmlAttribute('data-label1', sl('lang')->abtr("Very Low"));
  92. $field->addHtmlAttribute('data-label2', sl('lang')->abtr("Low"));
  93. $field->addHtmlAttribute('data-label3', sl('lang')->abtr("Normal"));
  94. $field->addHtmlAttribute('data-label4', sl('lang')->abtr("High"));
  95. $field->addHtmlAttribute('data-label5', sl('lang')->abtr("Medium"));
  96. $this->addField($field);
  97. }
  98. //cpulimit
  99. if($this->configuration()->isPermissionCpuLimit() && !$cpuPrioryty){
  100. $field = new Text('cpulimit');
  101. $field->addValidator(new CpulimitValidator($this->resourceManager->cpulimit()->getMin(), $this->resourceManager->cpulimit()->free(),true));
  102. $field->setDescription('description');
  103. $this->addField($field);
  104. }
  105. //cpuunits
  106. if($this->configuration()->isPermissionCpuunits( ) && !$cpuPrioryty){
  107. $field = new Text('cpuunits');
  108. $field->addValidator(new NumberValidator($this->resourceManager->cpuunits()->getMin(), $this->resourceManager->cpuunits()->free(),true));
  109. $field->setDescription('description');
  110. $this->addField($field);
  111. }
  112. //memory
  113. $field = new Range('memory', $this->resourceManager->memory()->getMin(), $this->resourceManager->memory()->free());
  114. $field->addValidator(new NumberValidator($this->resourceManager->memory()->getMin(), $this->resourceManager->memory()->free(),true));
  115. $field->setDefaultValue($this->configuration()->serverMemory->min);
  116. $field->setDescription('description');
  117. $this->addField($field);
  118. if($this->configuration()->isDetailsCombinedView()){
  119. //disk
  120. $field = new Text('disk');
  121. $field->addValidator(new NumberValidator($this->resourceManager->disk()->getMin(), $this->resourceManager->disk()->free(),true));
  122. $field->setDescription('description');
  123. $this->addField($field);
  124. }
  125. /**
  126. * @deprecated
  127. //ipv4
  128. if($this->configuration()->isPermissionIpv4()){
  129. $field = new Text('ipv4');
  130. $field->addValidator(new NumberValidator($this->resourceManager->ipv4()->getMin(), $this->resourceManager->ipv4()->free(),false));
  131. $field->setDescription('description');
  132. $this->addField($field);
  133. }
  134. //ipv6
  135. if($this->configuration()->isPermissionIpv6()){
  136. $field = new Text('ipv6');
  137. $field->addValidator(new NumberValidator($this->resourceManager->ipv6()->getMin(), $this->resourceManager->ipv6()->free(),false));
  138. $field->setDescription('description');
  139. $this->addField($field);
  140. }
  141. *
  142. */
  143. //dnsdomain
  144. if($this->configuration()->isPermissionSearchdomain()){
  145. $field = new Text('searchdomain');
  146. $field->addValidator(new HostnameValidator(false));
  147. $field->setDescription('description');
  148. $this->addField($field);
  149. }
  150. if($this->configuration()->isPermissionNameservers()){
  151. //ns1
  152. $field = new Text('nameserver[0]');
  153. $field->addValidator(new IpAddressValidator());
  154. $field->setDescription('description');
  155. $this->addField($field);
  156. //ns2
  157. $field = new Text('nameserver[1]');
  158. $field->addValidator(new IpAddressValidator());
  159. $field->setDescription('description');
  160. $this->addField($field);
  161. }
  162. //boot device 1
  163. $field = new Select("bootOrder0");
  164. $field->notEmpty();
  165. $this->addField($field);
  166. }
  167. }