Resource.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. namespace ModulesGarden\ProxmoxAddon\App\Services\Cloud;
  3. class Resource
  4. {
  5. protected $name;
  6. protected $unit;
  7. protected $min;
  8. protected $used;
  9. protected $max;
  10. protected $total;
  11. protected $free;
  12. /**
  13. * Resource constructor.
  14. * @param $name
  15. */
  16. public function __construct($name)
  17. {
  18. $this->name = $name;
  19. }
  20. /**
  21. * @return mixed
  22. */
  23. public function getUnit()
  24. {
  25. return $this->unit;
  26. }
  27. /**
  28. * @param mixed $unit
  29. * @return Resource
  30. */
  31. public function setUnit($unit)
  32. {
  33. $this->unit = $unit;
  34. return $this;
  35. }
  36. /**
  37. * @return mixed
  38. */
  39. public function getMin()
  40. {
  41. return $this->min;
  42. }
  43. /**
  44. * @param mixed $min
  45. * @return Resource
  46. */
  47. public function setMin($min)
  48. {
  49. $this->min = $min;
  50. return $this;
  51. }
  52. /**
  53. * @return mixed
  54. */
  55. public function getMax()
  56. {
  57. return $this->max;
  58. }
  59. /**
  60. * @param mixed $max
  61. * @return Resource
  62. */
  63. public function setMax($max)
  64. {
  65. $this->max = $max;
  66. return $this;
  67. }
  68. /**
  69. * @return mixed
  70. */
  71. public function getUsed()
  72. {
  73. return $this->used;
  74. }
  75. /**
  76. * @param mixed $used
  77. * @return Resource
  78. */
  79. public function setUsed($used)
  80. {
  81. $this->used = $used;
  82. return $this;
  83. }
  84. /**
  85. * @return mixed
  86. */
  87. public function getTotal()
  88. {
  89. return $this->total;
  90. }
  91. /**
  92. * @param mixed $total
  93. * @return Resource
  94. */
  95. public function setTotal($total)
  96. {
  97. $this->total = $total;
  98. return $this;
  99. }
  100. public function free(){
  101. $totalUsed = $this->freeTotal();
  102. if($this->max && $this->max < $totalUsed){
  103. return $this->max;
  104. }
  105. return $totalUsed;
  106. }
  107. public function freeTotal(){
  108. return $this->total - $this->used;
  109. }
  110. public function hasFreeTotal(){
  111. return $this->freeTotal() > 0;
  112. }
  113. public function getPercent(){
  114. if(!$this->total){
  115. return 0;
  116. }
  117. return round($this->used / $this->total * 100);
  118. }
  119. }