PageRenderTime 55ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/oiclient/lib/hardware/fileSystemOppClass.php

http://openirudi.googlecode.com/
PHP | 293 lines | 235 code | 58 blank | 0 comment | 25 complexity | 6fe3a16d1da9f620de01ac3c6ec9e5fe MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-3.0
  1. <?php
  2. class FileSystemOppClass {
  3. private $disk;
  4. private $partitionNumber;
  5. private $partitionName;
  6. private $partitionTypeId;
  7. private $label;
  8. private $type;
  9. private $version;
  10. private $uuid;
  11. private $size;
  12. private $sizeHuman;
  13. private $free;
  14. private $freeHuman;
  15. private $used;
  16. private $usedHuman;
  17. private $isOIFileSystem=false;
  18. private $canCreateImage;
  19. private $os=null;
  20. private $mountable=true;
  21. private $bootable=false;
  22. private $resizable=false;
  23. private $drivers=false;
  24. function __construct($disk,$partitionNumber,$partitionName,$partitionTypeId) {
  25. $this->disk=$disk;
  26. $this->partitionNumber=$partitionNumber;
  27. $this->partitionName=$partitionName;
  28. $this->partitionTypeId=$partitionTypeId;
  29. }
  30. function __get($propertyName) {
  31. try {
  32. if(property_exists($this , $propertyName)) {
  33. if(!isset( $this->$propertyName)) {
  34. $this->__set($propertyName, '');
  35. }
  36. return $this->$propertyName;
  37. }
  38. throw new Exception("Invalid property name \"{$propertyName}\" in FileSystemOppClass get ");
  39. }catch(Exception $e) {
  40. exceptionHandlerClass::saveError($e->getMessage());
  41. }
  42. }
  43. function __set($propertyName, $value) {
  44. try {
  45. if(!property_exists($this, $propertyName)) {
  46. throw new Exception("Invalid property value \"{$propertyName}\" in FileSystemOppClass ");
  47. }
  48. if(method_exists($this,'set_'.$propertyName)) {
  49. call_user_func(array($this,'set_'.$propertyName),$value);
  50. }else {
  51. throw new Exception("*Invalid property value \"{$propertyName}\" in FileSystemOppClass ");
  52. }
  53. }catch(Exception $e) {
  54. exceptionHandlerClass::saveError($e->getMessage());
  55. }
  56. }
  57. function getOS(){
  58. if(isset($this->os) && !is_null($this->os)){
  59. return $this->os;
  60. }else{
  61. return null;
  62. }
  63. }
  64. function set_canCreateImage() {
  65. $this->__get('type');
  66. if(!empty($this->type) && strpos(sfConfig::get('app_oipartition_fsImageCreateType'),$this->type) !== false ) {
  67. $this->canCreateImage= true;
  68. }else {
  69. $this->canCreateImage= false;
  70. }
  71. }
  72. function set_os($os) {
  73. $this->os=$os;
  74. }
  75. function set_bootable($bootable) {
  76. $this->bootable=$bootable;
  77. }
  78. function set_drivers($drivers) {
  79. $this->drivers=$drivers;
  80. }
  81. function set_mountable($mountable) {
  82. $this->mountable=$mountable;
  83. }
  84. function set_resizable($resizable) {
  85. $this->resizable=$resizable;
  86. }
  87. function set_isOIFileSystem($isOIFileSystem) {
  88. $this->isOIFileSystem=$isOIFileSystem;
  89. }
  90. function set_size() {
  91. if(!$mountPoint=$this->isMounted()) {
  92. $mountedAlready=false;
  93. $mountPoint=$this->mount();
  94. }else {
  95. $mountedAlready=true;
  96. }
  97. if(!empty($mountPoint)) {
  98. $this->free=disk_free_space($mountPoint);
  99. $this->freeHuman=unitsClass::sizeUnit($this->free);
  100. $this->size=disk_total_space($mountPoint);
  101. $this->sizeHuman=unitsClass::sizeUnit($this->size);
  102. $this->used=$this->size - $this->free;
  103. $this->usedHuman=unitsClass::sizeUnit($this->used);
  104. }
  105. if(!$mountedAlready) {
  106. $this->umount();
  107. }
  108. }
  109. function set_sizeHuman() {
  110. $this->__get('size');
  111. }
  112. function set_free() {
  113. $this->__get('size');
  114. }
  115. function set_freeHuman() {
  116. $this->__get('size');
  117. }
  118. function set_used() {
  119. $this->__get('size');
  120. }
  121. function set_usedHuman() {
  122. $this->__get('size');
  123. }
  124. function set_type() {
  125. $this->volid();
  126. }
  127. function set_label() {
  128. $this->volid();
  129. }
  130. function set_uuid() {
  131. $this->volid();
  132. }
  133. function volid() {
  134. if(empty($this->partitionName)) return;
  135. $this->type=null;
  136. $this->version=null;
  137. $this->uuid=null;
  138. $this->label=null;
  139. $blkid_result=executeClass::strExecute(str_replace('$partitionName',$this->partitionName, sfConfig::get('app_command_volid')));
  140. preg_match_all('~([A-Z_]*)\=\"([^\"]*)\"~sim',$blkid_result,$blkid_resultArray);
  141. if(!empty($blkid_resultArray[1]) ) {
  142. foreach($blkid_resultArray[1] as $k => $v) {
  143. switch($v) {
  144. case 'TYPE':
  145. $this->type=$blkid_resultArray[2][$k];
  146. break;
  147. case 'VERSION':
  148. $this->version=$blkid_resultArray[2][$k];
  149. break;
  150. case 'UUID':
  151. $this->uuid=$blkid_resultArray[2][$k];
  152. break;
  153. case 'LABEL':
  154. $this->label=$blkid_resultArray[2][$k];
  155. break;
  156. }
  157. }
  158. }
  159. }
  160. function isMounted() {
  161. if(!$this->mountable) return null;
  162. $cmd=str_replace('$partitionName',$this->partitionName, sfConfig::get('app_command_ismounted'));
  163. $s=executeClass::execute($cmd);
  164. if( $s['return']==0 ){
  165. $s2=implode("\n",$s['output']);
  166. if (strpos($s2,'!@@@') !==false ) {
  167. $s1=explode('!@@@', $s2 );
  168. return $s1[1];
  169. }else{
  170. return false;
  171. }
  172. }else {
  173. return false;
  174. }
  175. }
  176. function mount($mountPoint1='') {
  177. $this->__get('type');
  178. if(!$this->mountable) {
  179. return null;
  180. }
  181. if(!$mountPoint=$this->isMounted()) {
  182. $mountPoint=str_replace('$partitionName',$this->partitionName, sfConfig::get('app_command_mountpoint'));
  183. $cmd=str_replace('$partitionName',$this->partitionName,sfConfig::get('app_command_mount'));
  184. $cmd=str_replace('$mountpoint',$mountPoint, $cmd );
  185. $s=executeClass::execute($cmd);
  186. if($s['return']==0) {
  187. $s2=implode("\n",$s['output']);
  188. if (strpos($s2,'!@@@') !==false ) {
  189. $s1=explode('!@@@', $s2 );
  190. return $s1[1];
  191. }else{
  192. exceptionHandlerClass::saveMessage("No mounting res ".print_r($m,1));
  193. return false;
  194. }
  195. }else{
  196. exceptionHandlerClass::saveMessage("ERROR mounting cod: {$s['return'] } ".$this->partitionName);
  197. exceptionHandlerClass::saveMessage("ERROR mounting res ".print_r($s,1));
  198. return false;
  199. }
  200. }else {
  201. return $mountPoint;
  202. }
  203. }
  204. function umount() {
  205. if(!$this->mountable) return null;
  206. $this->__get('type');
  207. if(is_null($this->type)) {
  208. return null;
  209. }
  210. $mountPoint=$this->isMounted();
  211. if($mountPoint===false){
  212. return true;
  213. }
  214. $cmd=str_replace('$partitionName',$this->partitionName, sfConfig::get('app_command_umount'));
  215. $m=executeClass::execute($cmd);
  216. if($m['return']!=0) {
  217. exceptionHandlerClass::saveError("error umounting $this->partitionName");
  218. return false;
  219. }
  220. return true;
  221. }
  222. function changeUUID($uuid){
  223. exceptionHandlerClass::saveMessage("modify system uuid" );
  224. exceptionHandlerClass::saveMessage("image UUID: $uuid" );
  225. $cmd=str_replace('$partitionName',$this->partitionName, sfConfig::get('app_oipartition_changeUUID'));
  226. $cmd=str_replace('$uuid',$uuid, $cmd );
  227. $re=executeClass::execute($cmd);
  228. if ($re['return'] !=0 ){
  229. exceptionHandlerClass::saveMessage("Error modyfing UUID" );
  230. exceptionHandlerClass::saveMessage("output:: ".implode('<br>',$re['output']) );
  231. }
  232. $this->volid();
  233. }
  234. }
  235. ?>