| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- <?php
- namespace ModulesGarden\Servers\ProxmoxCloudVps\App\UI\VmUpdate\Sections\Qemu;
- use ModulesGarden\ProxmoxAddon\App\Services\Cloud\ProductService;
- use ModulesGarden\ProxmoxAddon\App\Services\Cloud\ResourceManager;
- use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Validators\CpulimitValidator;
- use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Validators\HostnameValidator;
- use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Validators\IpAddressValidator;
- use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Validators\NumberValidator;
- use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Validators\SshPublicKeyValidator;
- use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\VmCreate\Validators\UserValidator;
- use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\VmCreate\Validators\PasswordValidator;
- use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Fields\Range;
- use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Fields\Select;
- use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Fields\Text;
- use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Fields\Textarea;
- use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Sections\BaseSection;
- use function ModulesGarden\Servers\ProxmoxCloudVps\Core\Helper\isAdmin;
- use function ModulesGarden\Servers\ProxmoxCloudVps\Core\Helper\sl;
- class GeneralSection extends BaseSection
- {
- use ProductService;
- /**
- * @var ResourceManager
- */
- protected $resourceManager;
- public function initContent()
- {
- $this->initIds('generalSection');
- $this->unsetShowTitle();
- $this->resourceManager = new ResourceManager();
- $this->resourceManager->notVmIds([\ModulesGarden\ProxmoxAddon\Core\Helper\sl('Vm')->getVmModel()->id]);
- $this->initFields();
- }
- public function initFields()
- {
- $vm = \ModulesGarden\ProxmoxAddon\Core\Helper\sl('Vm')->getVm();
- $cpuPrioryty = $this->configuration()->hasCpuPriority();
- //name
- $field = new Text('name');
- $field->addValidator(new HostnameValidator());
- $field->setDescription('description');
- $this->addField($field);
- //description
- $field = new Textarea('description');
- $field->setDescription('description');
- $this->addField($field);
- if(isAdmin() || $this->configuration()->isPermissionIsoImage() && $vm->getCdRom()->count()){
- $field = new Select("iso");
- $field->notEmpty();
- $this->addField($field);
- }
- //user
- if($this->configuration()->isPermissionUsername()){
- $field = new Text('ciuser');
- $field->addValidator(new UserValidator());
- $field->setDescription('description');
- $this->addField($field);
- }
- //password
- if($this->configuration()->isPermissionPassword()){
- $field = new Text('cipassword');
- $field->addValidator( new PasswordValidator());
- $field->setDescription('description');
- $this->addField($field);
- }
- //sshkeys
- if($this->configuration()->isPermissionSshkeys()){
- $field = new Textarea("sshkeys");
- $field->addValidator(new SshPublicKeyValidator(false));
- $this->addField($field);
- }
- //sockets
- if($this->configuration()->isPermissionSockets() && !$this->configuration()->isCalculateSocketsAndCores()){
- $field = new Text('sockets');
- $field->addValidator(new NumberValidator($this->resourceManager->sockets()->getMin(), $this->resourceManager->sockets()->free(),true));
- $field->setDescription('description');
- $this->addField($field);
- }
- //cores
- if($this->configuration()->isPermissionCores() && !$this->configuration()->isCalculateSocketsAndCores()){
- $field = new Text('cores');
- $field->addValidator(new NumberValidator($this->resourceManager->cores()->getMin(), $this->resourceManager->cores()->free(),true));
- $field->setDescription('description');
- $this->addField($field);
- }
- //vcpus
- if($this->configuration()->isPermissionVcpus() || $this->configuration()->isCalculateSocketsAndCores()){
- if(!$vm->isRunning()) {
- $field = new Range('vcpus',$this->resourceManager->vcpus()->getMin(), $this->resourceManager->vcpus()->free());
- $field->addValidator(new NumberValidator($this->resourceManager->vcpus()->getMin(), $this->resourceManager->vcpus()->free(),true));
- $field->setDescription('description');
- } else {
- $field = new Range('vcpus',$vm->config()['vcpus'], $this->resourceManager->vcpus()->free());
- $field->addValidator(new NumberValidator($vm->config()['vcpus'], $this->resourceManager->vcpus()->free(),true));
- $field->setDescription('Zur Reduzierung der CPUs muß die VM heruntergefahren sein!');
- }
- $field->setDefaultValue($vm->config()['vcpus']);
- $this->addField($field);
- }
- //cpu priority
- if($cpuPrioryty){
- $field = new Range('cpuPriority', $this->resourceManager->cpuPriority()->getMin(), $this->resourceManager->cpuPriority()->free());
- $field->addValidator(new NumberValidator($this->resourceManager->cpuPriority()->getMin(), $this->resourceManager->cpuPriority()->free(),true));
- $field->setDescription('description');
- $field->addHtmlAttribute('data-label1', sl('lang')->abtr("Very Low"));
- $field->addHtmlAttribute('data-label2', sl('lang')->abtr("Low"));
- $field->addHtmlAttribute('data-label3', sl('lang')->abtr("Normal"));
- $field->addHtmlAttribute('data-label4', sl('lang')->abtr("High"));
- $field->addHtmlAttribute('data-label5', sl('lang')->abtr("Medium"));
- $this->addField($field);
- }
- //cpulimit
- if($this->configuration()->isPermissionCpuLimit() && !$cpuPrioryty){
- $field = new Text('cpulimit');
- $field->addValidator(new CpulimitValidator($this->resourceManager->cpulimit()->getMin(), $this->resourceManager->cpulimit()->free(),true));
- $field->setDescription('description');
- $this->addField($field);
- }
- //cpuunits
- if($this->configuration()->isPermissionCpuunits( ) && !$cpuPrioryty){
- $field = new Text('cpuunits');
- $field->addValidator(new NumberValidator($this->resourceManager->cpuunits()->getMin(), $this->resourceManager->cpuunits()->free(),true));
- $field->setDescription('description');
- $this->addField($field);
- }
- //memory
- if(!$vm->isRunning()) {
- $field = new Range('memory', $this->resourceManager->memory()->getMin(), $this->resourceManager->memory()->free());
- $field->addValidator(new NumberValidator($this->resourceManager->memory()->getMin(), $this->resourceManager->memory()->free(),true));
- $field->setDescription('description');
- } else {
- $field = new Range('memory', $vm->config()['memory'], $this->resourceManager->memory()->free());
- $field->addValidator(new NumberValidator($vm->config()['memory'], $this->resourceManager->memory()->free(),true));
- $field->setDescription('Zur Speicherreduzierung muß die VM heruntergefahren sein!');
- }
- $field->setDefaultValue($vm->config()['memory']);
- $this->addField($field);
- /**
- * @deprecated
- //ipv4
- if(!$this->configuration()->isOrderPublicIp() && $this->configuration()->isPermissionIpv4()){
- $field = new Text('ipv4');
- $field->addValidator(new NumberValidator($this->resourceManager->ipv4()->getMin(), $this->resourceManager->ipv4()->free(),$this->resourceManager->ipv4()->getMin() > 0));
- $field->setDescription('description');
- $this->addField($field);
- }
- //ipv6
- if(!$this->configuration()->isOrderPublicIp() && $this->configuration()->isPermissionIpv6()){
- $field = new Text('ipv6');
- $field->addValidator(new NumberValidator($this->resourceManager->ipv6()->getMin(), $this->resourceManager->ipv6()->free(),$this->resourceManager->ipv6()->getMin() > 0));
- $field->setDescription('description');
- $this->addField($field);
- }
- *
- */
- //dnsdomain
- if($this->configuration()->isPermissionSearchdomain()){
- $field = new Text('searchdomain');
- $field->addValidator(new HostnameValidator(false));
- $field->setDescription('description');
- $this->addField($field);
- }
- if($this->configuration()->isPermissionNameservers()){
- //ns1
- $field = new Text('nameserver[0]');
- $field->addValidator(new IpAddressValidator());
- $field->setDescription('description');
- $this->addField($field);
- //ns2
- $field = new Text('nameserver[1]');
- $field->addValidator(new IpAddressValidator());
- $field->setDescription('description');
- $this->addField($field);
- }
- }
- }
|