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 */ 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; protected $storage; public function __construct($id, $config = null) { $this->id = $id; if ($config) { $config = self::asArray($config); $config['location'] = key($config); $ex = explode(":", $config['location'] ); $config['storage'] = $ex[0]; $this->setAttributes($config); if(!$config['size']){ $this->setSize($ex[1]."G"); } 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"; } /** * @return mixed */ public function getStorage() { return $this->storage; } /** * @param mixed $storage * @return MountPoint */ public function setStorage($storage) { $this->storage = $storage; return $this; } public function move($delete=0){ $config = [ "volume" => $this->getId(), 'storage' => $this->getStorage(), 'delete' => $delete ]; $path = str_replace("/config", "/move_volume", $this->getPath()); return $this->api()->post($path ,$config ); } }