GeneralSection.php 9.1 KB

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