| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- <?php
- namespace ModulesGarden\ProxmoxAddon\App\Services\Cloud;
- class Resource
- {
- protected $name;
- protected $unit;
- protected $min;
- protected $used;
- protected $max;
- protected $total;
- protected $free;
- /**
- * Resource constructor.
- * @param $name
- */
- public function __construct($name)
- {
- $this->name = $name;
- }
- /**
- * @return mixed
- */
- public function getUnit()
- {
- return $this->unit;
- }
- /**
- * @param mixed $unit
- * @return Resource
- */
- public function setUnit($unit)
- {
- $this->unit = $unit;
- return $this;
- }
- /**
- * @return mixed
- */
- public function getMin()
- {
- return $this->min;
- }
- /**
- * @param mixed $min
- * @return Resource
- */
- public function setMin($min)
- {
- $this->min = $min;
- return $this;
- }
- /**
- * @return mixed
- */
- public function getMax()
- {
- return $this->max;
- }
- /**
- * @param mixed $max
- * @return Resource
- */
- public function setMax($max)
- {
- $this->max = $max;
- return $this;
- }
- /**
- * @return mixed
- */
- public function getUsed()
- {
- return $this->used;
- }
- /**
- * @param mixed $used
- * @return Resource
- */
- public function setUsed($used)
- {
- $this->used = $used;
- return $this;
- }
- /**
- * @return mixed
- */
- public function getTotal()
- {
- return $this->total;
- }
- /**
- * @param mixed $total
- * @return Resource
- */
- public function setTotal($total)
- {
- $this->total = $total;
- return $this;
- }
- public function free(){
- $totalUsed = $this->freeTotal();
- if($this->max && $this->max < $totalUsed){
- return $this->max;
- }
- return $totalUsed;
- }
- public function freeTotal(){
- return $this->total - $this->used;
- }
- public function hasFreeTotal(){
- return $this->freeTotal() > 0;
- }
- public function getPercent(){
- if(!$this->total){
- return 0;
- }
- return round($this->used / $this->total * 100);
- }
- }
|