IpCidr.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /* * ********************************************************************
  3. * ProxmoxAddon product developed. (Mar 9, 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 MGProvision\Proxmox\v2\models;
  20. use \MGProvision\Proxmox\v2\ProxmoxApiException;
  21. /**
  22. * Description of IpCidr
  23. *
  24. * @author Pawel Kopec <pawelk@modulesgardne.com>
  25. */
  26. class IpCidr extends AbstractObject
  27. {
  28. private $cidr;
  29. private $comment;
  30. function __construct($path = null)
  31. {
  32. if (!is_null($path))
  33. {
  34. $this->setPath($path);
  35. }
  36. }
  37. /**
  38. *
  39. * @param string $path /api2/json/nodes/{node}/qemu/{vmid}/firewall/ipset/{$name}
  40. * @throws proxmox\ProxmoxApiException
  41. */
  42. public function setPath($path)
  43. {
  44. if (!preg_match('/ipset/', $path))
  45. {
  46. throw new ProxmoxApiException(sprintf("IpCidr path ('%s') is not valid", $path));
  47. }
  48. $this->path = $path;
  49. return $this;
  50. }
  51. public function getCidr()
  52. {
  53. return $this->cidr;
  54. }
  55. public function getComment()
  56. {
  57. return $this->comment;
  58. }
  59. public function setCidr($cidr)
  60. {
  61. $this->cidr = $cidr;
  62. return $this;
  63. }
  64. public function setComment($comment)
  65. {
  66. $this->comment = $comment;
  67. return $this;
  68. }
  69. public function create()
  70. {
  71. if (empty($this->path))
  72. {
  73. throw new ProxmoxApiException("IpCidr path is empty");
  74. }
  75. $this->api()->post($this->path, ['cidr' => $this->cidr, "comment" => $this->comment]);
  76. $this->setPath($this->path . "/{$this->cidr}");
  77. return $this;
  78. }
  79. public function delete()
  80. {
  81. if (empty($this->path))
  82. {
  83. throw new ProxmoxApiException("IpSet path is empty");
  84. }
  85. $this->api()->delete($this->path);
  86. return $this;
  87. }
  88. }