IpConfig.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. /* * ********************************************************************
  3. * ProxmoxAddon product developed. (May 25, 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 IpConfig
  23. *
  24. * @author Pawel Kopec <pawelk@modulesgardne.com>
  25. */
  26. class IpConfig extends AbstractObject
  27. {
  28. protected $id;
  29. protected $path;
  30. protected $ip;
  31. protected $gw;
  32. protected $cidr;
  33. protected $ip6;
  34. protected $gw6;
  35. protected $cidr6;
  36. public function __construct($id, $config = null)
  37. {
  38. $this->id = $id;
  39. if ($config)
  40. {
  41. $config = self::asArray($config);
  42. $this->setAttributes($config);
  43. }
  44. }
  45. public function asConfig()
  46. {
  47. $config = null;
  48. if ($this->getIp())
  49. {
  50. $config[] = "ip={$this->getIp()}/{$this->getCidr()}";
  51. }
  52. if ($this->getGw())
  53. {
  54. $config[] = "gw={$this->getGw()}";
  55. }
  56. if ($this->getIp6())
  57. {
  58. $config[] = "ip6={$this->getIp6()}/{$this->getCidr6()}";
  59. }
  60. if ($this->getGw6())
  61. {
  62. $config[] = "gw6={$this->getGw6()}";
  63. }
  64. return implode(",", $config);
  65. }
  66. public function getId()
  67. {
  68. return $this->id;
  69. }
  70. public function getPath()
  71. {
  72. return $this->path;
  73. }
  74. public function getIp($cird=true)
  75. {
  76. if(!$cird){
  77. $ex = explode("/", $this->ip);
  78. return $ex[0];
  79. }
  80. return $this->ip;
  81. }
  82. public function getGw()
  83. {
  84. return $this->gw;
  85. }
  86. public function getCidr()
  87. {
  88. return $this->cidr;
  89. }
  90. public function getIp6()
  91. {
  92. return $this->ip6;
  93. }
  94. public function getGw6()
  95. {
  96. return $this->gw6;
  97. }
  98. public function getCidr6()
  99. {
  100. return $this->cidr6;
  101. }
  102. public function setId($id)
  103. {
  104. $this->id = $id;
  105. return $this;
  106. }
  107. public function setPath($path)
  108. {
  109. $this->path = $path;
  110. return $this;
  111. }
  112. public function setIp($ip)
  113. {
  114. $ip = explode("\/", $ip);
  115. $this->ip = $ip['0'];
  116. $this->setCidr($ip['1']);
  117. return $this;
  118. }
  119. public function setGw($gw)
  120. {
  121. $this->gw = $gw;
  122. return $this;
  123. }
  124. public function setCidr($cidr)
  125. {
  126. $this->cidr = $cidr;
  127. return $this;
  128. }
  129. public function setIp6($ip6)
  130. {
  131. $ip6 = explode("\/", $ip6);
  132. $this->ip6 = $ip6['0'];
  133. $this->setCidr6($ip6['1']);
  134. return $this;
  135. }
  136. public function setGw6($gw6)
  137. {
  138. $this->gw6 = $gw6;
  139. return $this;
  140. }
  141. public function setCidr6($cidr6)
  142. {
  143. $this->cidr6 = $cidr6;
  144. return $this;
  145. }
  146. public function getAttributes(){
  147. return [
  148. "ip" => $this->getIp(),
  149. "ip6" => $this->getIp6(),
  150. "gw" => $this->getGw(),
  151. "gw6" => $this->getGw6(),
  152. ];
  153. }
  154. }