GeneralSection.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 Range('memory', $this->resourceManager->memory()->getMin(), $this->resourceManager->memory()->free());
  113. $field->addValidator(new NumberValidator($this->resourceManager->memory()->getMin(), $this->resourceManager->memory()->free(),true));
  114. $field->setDefaultValue($this->configuration()->serverMemory->min);
  115. $field->setDescription('description');
  116. $this->addField($field);
  117. /**
  118. * @deprecated
  119. //ipv4
  120. if($this->configuration()->isPermissionIpv4()){
  121. $field = new Text('ipv4');
  122. $field->addValidator(new NumberValidator($this->resourceManager->ipv4()->getMin(), $this->resourceManager->ipv4()->free(),false));
  123. $field->setDescription('description');
  124. $this->addField($field);
  125. }
  126. //ipv6
  127. if($this->configuration()->isPermissionIpv6()){
  128. $field = new Text('ipv6');
  129. $field->addValidator(new NumberValidator($this->resourceManager->ipv6()->getMin(), $this->resourceManager->ipv6()->free(),false));
  130. $field->setDescription('description');
  131. $this->addField($field);
  132. }
  133. *
  134. */
  135. //dnsdomain
  136. if($this->configuration()->isPermissionSearchdomain()){
  137. $field = new Text('searchdomain');
  138. $field->addValidator(new HostnameValidator(false));
  139. $field->setDescription('description');
  140. $this->addField($field);
  141. }
  142. if($this->configuration()->isPermissionNameservers()){
  143. //ns1
  144. $field = new Text('nameserver[0]');
  145. $field->addValidator(new IpAddressValidator());
  146. $field->setDescription('description');
  147. $this->addField($field);
  148. //ns2
  149. $field = new Text('nameserver[1]');
  150. $field->addValidator(new IpAddressValidator());
  151. $field->setDescription('description');
  152. $this->addField($field);
  153. }
  154. //boot device
  155. $field = new Select("bootOrder0");
  156. $field->notEmpty();
  157. $this->addField($field);
  158. }
  159. }