GeneralSection.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. logModuleCall(
  89. 'proxmoxCloud',
  90. __FUNCTION__,
  91. $vm->config(),
  92. 'Debug',
  93. $this->configuration()
  94. );
  95. if(!$vm->isRunning()) {
  96. $field = new Range('vcpus',$this->resourceManager->vcpus()->getMin(), $this->resourceManager->vcpus()->free());
  97. $field->addValidator(new NumberValidator($this->resourceManager->vcpus()->getMin(), $this->resourceManager->vcpus()->free(),true));
  98. $field->setDescription('description');
  99. } else {
  100. $field = new Range('vcpus',$vm->config(['vcpus']), $this->resourceManager->vcpus()->free());
  101. $field->addValidator(new NumberValidator($vm->config(['vcpus']), $this->resourceManager->vcpus()->free(),true));
  102. $field->setDescription('Zur Reduzierung der CPUs muß die VM heruntergefahren sein!');
  103. }
  104. $field->setDefaultValue($vm->config()['vcpus']);
  105. $this->addField($field);
  106. }
  107. //cpu priority
  108. if($cpuPrioryty){
  109. $field = new Range('cpuPriority', $this->resourceManager->cpuPriority()->getMin(), $this->resourceManager->cpuPriority()->free());
  110. $field->addValidator(new NumberValidator($this->resourceManager->cpuPriority()->getMin(), $this->resourceManager->cpuPriority()->free(),true));
  111. $field->setDescription('description');
  112. $field->addHtmlAttribute('data-label1', sl('lang')->abtr("Very Low"));
  113. $field->addHtmlAttribute('data-label2', sl('lang')->abtr("Low"));
  114. $field->addHtmlAttribute('data-label3', sl('lang')->abtr("Normal"));
  115. $field->addHtmlAttribute('data-label4', sl('lang')->abtr("High"));
  116. $field->addHtmlAttribute('data-label5', sl('lang')->abtr("Medium"));
  117. $this->addField($field);
  118. }
  119. //cpulimit
  120. if($this->configuration()->isPermissionCpuLimit() && !$cpuPrioryty){
  121. $field = new Text('cpulimit');
  122. $field->addValidator(new CpulimitValidator($this->resourceManager->cpulimit()->getMin(), $this->resourceManager->cpulimit()->free(),true));
  123. $field->setDescription('description');
  124. $this->addField($field);
  125. }
  126. //cpuunits
  127. if($this->configuration()->isPermissionCpuunits( ) && !$cpuPrioryty){
  128. $field = new Text('cpuunits');
  129. $field->addValidator(new NumberValidator($this->resourceManager->cpuunits()->getMin(), $this->resourceManager->cpuunits()->free(),true));
  130. $field->setDescription('description');
  131. $this->addField($field);
  132. }
  133. //memory
  134. if(!$vm->isRunning()) {
  135. $field = new Range('memory', $this->resourceManager->memory()->getMin(), $this->resourceManager->memory()->free());
  136. $field->addValidator(new NumberValidator($this->resourceManager->memory()->getMin(), $this->resourceManager->memory()->free(),true));
  137. $field->setDescription('description');
  138. } else {
  139. $field = new Range('memory', $vm->config()['memory'], $this->resourceManager->memory()->free());
  140. $field->addValidator(new NumberValidator($vm->config()['memory'], $this->resourceManager->memory()->free(),true));
  141. $field->setDescription('Zur Speicherreduzierung muß die VM heruntergefahren sein!');
  142. }
  143. $field->setDefaultValue($vm->config()['memory']);
  144. $this->addField($field);
  145. /**
  146. * @deprecated
  147. //ipv4
  148. if($this->configuration()->isPermissionIpv4()){
  149. $field = new Text('ipv4');
  150. $field->addValidator(new NumberValidator($this->resourceManager->ipv4()->getMin(), $this->resourceManager->ipv4()->free(),false));
  151. $field->setDescription('description');
  152. $this->addField($field);
  153. }
  154. //ipv6
  155. if($this->configuration()->isPermissionIpv6()){
  156. $field = new Text('ipv6');
  157. $field->addValidator(new NumberValidator($this->resourceManager->ipv6()->getMin(), $this->resourceManager->ipv6()->free(),false));
  158. $field->setDescription('description');
  159. $this->addField($field);
  160. }
  161. *
  162. */
  163. //dnsdomain
  164. if($this->configuration()->isPermissionSearchdomain()){
  165. $field = new Text('searchdomain');
  166. $field->addValidator(new HostnameValidator(false));
  167. $field->setDescription('description');
  168. $this->addField($field);
  169. }
  170. if($this->configuration()->isPermissionNameservers()){
  171. //ns1
  172. $field = new Text('nameserver[0]');
  173. $field->addValidator(new IpAddressValidator());
  174. $field->setDescription('description');
  175. $this->addField($field);
  176. //ns2
  177. $field = new Text('nameserver[1]');
  178. $field->addValidator(new IpAddressValidator());
  179. $field->setDescription('description');
  180. $this->addField($field);
  181. }
  182. }
  183. }