HaResourceRepository.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /* * ********************************************************************
  3. * ProxmoxVPS product developed. (2016-11-14)
  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 MGProvision\Proxmox\v2\repository;
  20. /**
  21. * Description of HaResource
  22. *
  23. * @author Pawel Kopec <pawelk@modulesgarden.com>
  24. * @version 1.0.0
  25. */
  26. class HaResourceRepository extends AbstractRepository
  27. {
  28. private $type;
  29. public function findVm()
  30. {
  31. $this->type = "vm";
  32. }
  33. public function findCt()
  34. {
  35. $this->type = "ct";
  36. }
  37. public function findVirtualization($virtualization)
  38. {
  39. switch (strtolower($virtualization))
  40. {
  41. case "lxc":
  42. $this->type = "ct";
  43. break;
  44. case "qemu":
  45. case "kvm":
  46. $this->type = "vm";
  47. break;
  48. default:
  49. throw new \Exception('Unknown virtualization type: ' . $virtualization);
  50. }
  51. return $this;
  52. }
  53. /**
  54. *
  55. * @return \MGProvision\Proxmox\v2\models\HaResource[]
  56. */
  57. public function fetch()
  58. {
  59. $parameters = array();
  60. if ($this->type)
  61. $parameters['type'] = $this->type;
  62. $resources = $this->api()->get("/cluster/ha/resources", $parameters);
  63. $data = array();
  64. foreach ($resources as $resource)
  65. {
  66. $entity = new \MGProvision\Proxmox\v2\models\HaResource($resource['sid']);
  67. $entity->setAttributes($resource);
  68. $data[] = $entity;
  69. }
  70. unset($resources, $entity);
  71. return $data;
  72. }
  73. }