VmidSelect.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /* * ********************************************************************
  3. * ProxmoxAddon product developed. (Sep 10, 2018)
  4. * *
  5. *
  6. * CREATED BY MODULESGARDEN -> http://modulesgarden.com
  7. * CONTACT -> contact@modulesgarden.com
  8. *
  9. *
  10. * This software is furnished under a license and may be used and copied
  11. * only in accordance with the terms of such license and with the
  12. * inclusion of the above copyright notice. This software or any other
  13. * copies thereof may not be provided or otherwise made available to any
  14. * other person. No title to and ownership of the software is hereby
  15. * transferred.
  16. *
  17. *
  18. * ******************************************************************** */
  19. namespace ModulesGarden\ProxmoxAddon\App\UI\Templates\Fields;
  20. use MGProvision\Proxmox\v2 as proxmox;
  21. use ModulesGarden\ProxmoxAddon as main;
  22. use ModulesGarden\ProxmoxAddon\Core\UI\Interfaces\AdminArea;
  23. use ModulesGarden\ProxmoxAddon\Core\UI\Widget\Forms\AjaxFields\Select;
  24. /**
  25. * Description of NodeSelect
  26. *
  27. * @author Pawel Kopec <pawelk@modulesgardne.com>
  28. */
  29. class VmidSelect extends Select implements AdminArea
  30. {
  31. use main\App\Services\BaseService;
  32. public function prepareAjaxData()
  33. {
  34. $this->setServerId($this->getRequestValue('id'))->getApi()->setInstance();
  35. $this->getApi()->debug(true);
  36. $clusterResurce = new proxmox\repository\ClusterResourcesRepository;
  37. $clusterResurce->findVm();
  38. $clusterResurce->addfilter(['type' => 'qemu']);
  39. foreach ($clusterResurce->fetch() as $resurce)
  40. {
  41. /* @var $server proxmox\models\ClusterResource */
  42. if ($resurce->getTemplate() == "1" || $resurce->getStatus() == "unknown")
  43. {
  44. continue;
  45. }
  46. $name = "{$resurce->getVmid()} ";
  47. if ($resurce->getName())
  48. {
  49. $name .= "- {$resurce->getName()}";
  50. }
  51. $this->availableValues[] = [
  52. 'key' => $resurce->getVmid(),
  53. 'value' => $name
  54. ];
  55. }
  56. }
  57. }