GeneralSection.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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\UserValidator;
  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. $cpuPrioryty = false;
  39. //name
  40. $field = new Text('name');
  41. $field->addValidator(new HostnameValidator());
  42. $field->setDescription('description');
  43. $this->addField($field);
  44. //description
  45. $field = new Textarea('description');
  46. $field->setDescription('description');
  47. $this->addField($field);
  48. if(isAdmin() || $this->configuration()->isPermissionIsoImage() && $vm->getCdRom()->count()){
  49. $field = new Select("iso");
  50. $field->notEmpty();
  51. $this->addField($field);
  52. }
  53. //user
  54. if($this->configuration()->isPermissionUsername()){
  55. $field = new Text('ciuser');
  56. $field->addValidator(new UserValidator());
  57. $field->setDescription('description');
  58. $this->addField($field);
  59. }
  60. //password
  61. if($this->configuration()->isPermissionPassword()){
  62. $field = new Text('cipassword');
  63. $field->addValidator( new PasswordValidator());
  64. $field->setDescription('description');
  65. $this->addField($field);
  66. }
  67. //sshkeys
  68. if($this->configuration()->isPermissionSshkeys()){
  69. $field = new Textarea("sshkeys");
  70. $field->addValidator(new SshPublicKeyValidator(false));
  71. $this->addField($field);
  72. }
  73. //sockets
  74. if($this->configuration()->isPermissionSockets() && !$this->configuration()->isCalculateSocketsAndCores()){
  75. $field = new Text('sockets');
  76. $field->addValidator(new NumberValidator($this->resourceManager->sockets()->getMin(), $this->resourceManager->sockets()->free(),true));
  77. $field->setDescription('description');
  78. $this->addField($field);
  79. }
  80. //cores
  81. if($this->configuration()->isPermissionCores() && !$this->configuration()->isCalculateSocketsAndCores()){
  82. $field = new Text('cores');
  83. $field->addValidator(new NumberValidator($this->resourceManager->cores()->getMin(), $this->resourceManager->cores()->free(),true));
  84. $field->setDescription('description');
  85. $this->addField($field);
  86. }
  87. //vcpus
  88. if($this->configuration()->isPermissionVcpus() || $this->configuration()->isCalculateSocketsAndCores()){
  89. if(!$vm->isRunning()) {
  90. $field = new Range('vcpus',$this->resourceManager->vcpus()->getMin(), $this->resourceManager->vcpus()->free());
  91. $field->addValidator(new NumberValidator($this->resourceManager->vcpus()->getMin(), $this->resourceManager->vcpus()->free(),true));
  92. $field->setDescription('description');
  93. } else {
  94. $field = new Range('vcpus',$vm->config()['vcpus'], $this->resourceManager->vcpus()->free());
  95. $field->addValidator(new NumberValidator($vm->config()['vcpus'], $this->resourceManager->vcpus()->free(),true));
  96. $field->setDescription('Zur Reduzierung der CPUs muß die VM heruntergefahren sein!');
  97. }
  98. $field->setDefaultValue($vm->config()['vcpus']);
  99. $this->addField($field);
  100. }
  101. //cpu priority
  102. if($cpuPrioryty){
  103. $field = new Range('cpuPriority', $this->resourceManager->cpuPriority()->getMin(), $this->resourceManager->cpuPriority()->free());
  104. $field->addValidator(new NumberValidator($this->resourceManager->cpuPriority()->getMin(), $this->resourceManager->cpuPriority()->free(),true));
  105. $field->setDescription('description');
  106. $field->addHtmlAttribute('data-label1', sl('lang')->abtr("Very Low"));
  107. $field->addHtmlAttribute('data-label2', sl('lang')->abtr("Low"));
  108. $field->addHtmlAttribute('data-label3', sl('lang')->abtr("Normal"));
  109. $field->addHtmlAttribute('data-label4', sl('lang')->abtr("High"));
  110. $field->addHtmlAttribute('data-label5', sl('lang')->abtr("Medium"));
  111. $this->addField($field);
  112. }
  113. //cpulimit
  114. if($this->configuration()->isPermissionCpuLimit() && !$cpuPrioryty){
  115. $field = new Text('cpulimit');
  116. $field->addValidator(new CpulimitValidator($this->resourceManager->cpulimit()->getMin(), $this->resourceManager->cpulimit()->free(),true));
  117. $field->setDescription('description');
  118. $this->addField($field);
  119. }
  120. //cpuunits
  121. if($this->configuration()->isPermissionCpuunits( ) && !$cpuPrioryty){
  122. $field = new Text('cpuunits');
  123. $field->addValidator(new NumberValidator($this->resourceManager->cpuunits()->getMin(), $this->resourceManager->cpuunits()->free(),true));
  124. $field->setDescription('description');
  125. $this->addField($field);
  126. }
  127. //memory
  128. if(!$vm->isRunning()) {
  129. $field = new Range('memory', $this->resourceManager->memory()->getMin(), $this->resourceManager->memory()->free());
  130. $field->addValidator(new NumberValidator($this->resourceManager->memory()->getMin(), $this->resourceManager->memory()->free(),true));
  131. $field->setDescription('description');
  132. } else {
  133. $field = new Range('memory', $vm->config()['memory'], $this->resourceManager->memory()->free());
  134. $field->addValidator(new NumberValidator($vm->config()['memory'], $this->resourceManager->memory()->free(),true));
  135. $field->setDescription('Zur Speicherreduzierung muß die VM heruntergefahren sein!');
  136. }
  137. $field->setDefaultValue($vm->config()['memory']);
  138. $this->addField($field);
  139. /**
  140. * @deprecated
  141. //ipv4
  142. if(!$this->configuration()->isOrderPublicIp() && $this->configuration()->isPermissionIpv4()){
  143. $field = new Text('ipv4');
  144. $field->addValidator(new NumberValidator($this->resourceManager->ipv4()->getMin(), $this->resourceManager->ipv4()->free(),$this->resourceManager->ipv4()->getMin() > 0));
  145. $field->setDescription('description');
  146. $this->addField($field);
  147. }
  148. //ipv6
  149. if(!$this->configuration()->isOrderPublicIp() && $this->configuration()->isPermissionIpv6()){
  150. $field = new Text('ipv6');
  151. $field->addValidator(new NumberValidator($this->resourceManager->ipv6()->getMin(), $this->resourceManager->ipv6()->free(),$this->resourceManager->ipv6()->getMin() > 0));
  152. $field->setDescription('description');
  153. $this->addField($field);
  154. }
  155. *
  156. */
  157. //dnsdomain
  158. if($this->configuration()->isPermissionSearchdomain()){
  159. $field = new Text('searchdomain');
  160. $field->addValidator(new HostnameValidator(false));
  161. $field->setDescription('description');
  162. $this->addField($field);
  163. }
  164. if($this->configuration()->isPermissionNameservers()){
  165. //ns1
  166. $field = new Text('nameserver[0]');
  167. $field->addValidator(new IpAddressValidator());
  168. $field->setDescription('description');
  169. $this->addField($field);
  170. //ns2
  171. $field = new Text('nameserver[1]');
  172. $field->addValidator(new IpAddressValidator());
  173. $field->setDescription('description');
  174. $this->addField($field);
  175. }
  176. }
  177. }