| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- <?php
- /* * ********************************************************************
- * ProxmoxAddon product developed. (Apr 12, 2018)
- * *
- *
- * CREATED BY MODULESGARDEN -> http://modulesgarden.com
- * CONTACT -> contact@modulesgarden.com
- *
- *
- * This software is furnished under a license and may be used and copied
- * only in accordance with the terms of such license and with the
- * inclusion of the above copyright notice. This software or any other
- * copies thereof may not be provided or otherwise made available to any
- * other person. No title to and ownership of the software is hereby
- * transferred.
- *
- *
- * ******************************************************************** */
- namespace MGProvision\Proxmox\v2\models;
- /**
- * Description of MounPoint
- *
- * @author Pawel Kopec <pawelk@modulesgardne.com>
- */
- class MountPoint extends AbstractObject
- {
- protected $id;
- protected $path;
- protected $mp;
- protected $size;
- protected $acl;
- protected $backup;
- protected $quota;
- protected $replicate;
- protected $ro;
- protected $location;
- protected $name;
- protected $gb;
- public function __construct($id, $config = null)
- {
- $this->id = $id;
- if ($config)
- {
- $config = self::asArray($config);
- $config['location'] = key($config);
- $matches['0'] = str_replace(['-'], [" "], $matches['0']);
- $config['name'] = ucfirst($matches['0']);
- $this->setAttributes($config);
- if ($id == 'rootfs')
- {
- $this->setBackup(1);
- }
- }
- }
- public function getId()
- {
- return $this->id;
- }
- public function getPath()
- {
- return $this->path;
- }
- public function getLocation()
- {
- return $this->location;
- }
- public function getName()
- {
- if($this->getId()=="rootfs"){
- return $this->name = "Root Disk";
- }
- preg_match('/disk-[0-9]/', $this->getLocation(), $matches);
- $matches['0'] = str_replace(['-'], [" "], $matches['0']);
- return $this->name = ucfirst($matches['0']);
- }
- public function setLocation($location)
- {
- $this->location = $location;
- return $this;
- }
- public function setName($name)
- {
- $this->name = $name;
- return $this;
- }
- public function setPath($path)
- {
- $this->path = $path;
- return $this;
- }
- public function getMp()
- {
- return $this->mp;
- }
- public function getSize()
- {
- return $this->size;
- }
- public function getAcl()
- {
- return $this->acl;
- }
- public function getBackup()
- {
- return $this->backup;
- }
- public function isBackup()
- {
- return $this->backup==1;
- }
- public function getQuota()
- {
- return $this->quota;
- }
- public function getReplicate()
- {
- return $this->replicate;
- }
- public function getRo()
- {
- return $this->ro;
- }
- public function setMp($mp)
- {
- $this->mp = $mp;
- return $this;
- }
- public function setSize($size)
- {
- $this->size = $size;
- return $this;
- }
- public function setAcl($acl)
- {
- $this->acl = $acl;
- return $this;
- }
- public function setBackup($backup)
- {
- $this->backup = $backup;
- return $this;
- }
- public function setQuota($quota)
- {
- $this->quota = $quota;
- return $this;
- }
- public function setReplicate($replicate)
- {
- $this->replicate = $replicate;
- return $this;
- }
- public function setRo($ro)
- {
- $this->ro = $ro;
- return $this;
- }
- public function getBytes()
- {
- if(preg_match('/K/', $this->getSize())){//KB => Bytes
- $size = (int) $this->getSize();
- return $size * 1024 ;
- }
- elseif(preg_match('/M/', $this->getSize())){//MB => Bytes
- $size = (int) $this->getSize();
- return $size * pow(1024,2);
- }
- else if(preg_match('/T/', $this->getSize())){//T => Bytes
- $size = (int) $this->getSize();
- return $size * pow(1024,4);
- }
- else{//GB => Bytes
- $size = (int) $this->getSize();
- return $size * pow(1024,3);
- }
- }
- public function getGb()
- {
- if(preg_match('/M/', $this->getSize())){//MB => GB
- $size = (int) $this->getSize();
- return $size / 1024;
- }
- else if(preg_match('/T/', $this->getSize())){//T => GB
- $size = (int) $this->getSize();
- return $size * 1024;
- }
- else{//GB
- return (int) $this->getSize();
- }
- }
- /**
- * @param mixed $id
- */
- public function setId($id)
- {
- $this->id = $id;
- return $this;
- }
- public function resize($size)
- {
- $path = str_replace('config', 'resize', $this->path);
- return $this->api()->put($path, ['disk' => $this->id, 'size' => $size]);
- }
- public function asConfig()
- {
- $config = [$this->location];
- foreach (['mp', 'acl', 'backup', 'quota', 'replicate', 'ro'] as $k)
- {
- if (!is_null($this->{$k}))
- {
- $config[] = "{$k}=" . $this->{$k};
- }
- }
- return implode(",", $config);
- }
- public function update()
- {
- return $this->api()->put($this->path, [$this->id => $this->asConfig()]);
- }
- public function create()
- {
- return $this->api()->put($this->path, [$this->id => $this->asConfig()]);
- }
- public function delete()
- {
- return $this->api()->put($this->path, ["delete" => $this->id]);
- }
- public function isMaster(){
- return $this->getId() == "rootfs";
- }
- }
|