GeneralSection.php 8.3 KB

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