CdRom.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. namespace MGProvision\Proxmox\v2\models;
  3. class CdRom extends AbstractObject {
  4. protected $id;
  5. protected $storage;
  6. protected $isoFile;
  7. protected $path;
  8. protected $media;
  9. protected $location;
  10. public function __construct($id, $config=null) {
  11. $this->id = $id;
  12. if ($config) {
  13. $config = self::asArray($config);
  14. $this->location = key($config);
  15. $ex = explode(":", $this->location );
  16. $config['storage'] = $ex[0];
  17. $config['isoFile'] = $ex[1];
  18. $this->setAttributes($config);
  19. }
  20. }
  21. /**
  22. * @return mixed
  23. */
  24. public function getPath()
  25. {
  26. return $this->path;
  27. }
  28. /**
  29. * @param mixed $path
  30. */
  31. public function setPath($path)
  32. {
  33. $this->path = $path;
  34. }
  35. /**
  36. * @return mixed
  37. */
  38. public function getId()
  39. {
  40. return $this->id;
  41. }
  42. /**
  43. * @param mixed $id
  44. */
  45. public function setId($id)
  46. {
  47. $this->id = $id;
  48. }
  49. /**
  50. * @return mixed
  51. */
  52. public function getStorage()
  53. {
  54. return $this->storage;
  55. }
  56. /**
  57. * @param mixed $storage
  58. */
  59. public function setStorage($storage)
  60. {
  61. $this->storage = $storage;
  62. }
  63. /**
  64. * @return mixed
  65. */
  66. public function getIsoFile()
  67. {
  68. return $this->isoFile;
  69. }
  70. /**
  71. * @param mixed $isoFile
  72. */
  73. public function setIsoFile($isoFile)
  74. {
  75. $this->isoFile = $isoFile;
  76. return $this;
  77. }
  78. /**
  79. * @return mixed
  80. */
  81. public function getMedia()
  82. {
  83. return $this->media;
  84. }
  85. /**
  86. * @param mixed $media
  87. */
  88. public function setMedia($media)
  89. {
  90. $this->media = $media;
  91. }
  92. /**
  93. * @return int|string|null
  94. */
  95. public function getLocation()
  96. {
  97. return $this->location;
  98. }
  99. /**
  100. * @param int|string|null $location
  101. */
  102. public function setLocation($location)
  103. {
  104. $this->location = $location;
  105. if(preg_match("/\:/", $location)){
  106. $ex = explode(":", $this->location );
  107. $this->setStorage($ex[0]);
  108. $this->setIsoFile($ex[1]);
  109. }
  110. $this->location = $location;
  111. return $this;
  112. }
  113. public function asConfig(){
  114. $filable=['media'];
  115. $config = [];
  116. $config[]= $this->getLocation();
  117. $this->toConfig($filable, $config);
  118. return implode(",", $config);
  119. }
  120. public function update(){
  121. return $this->api()->put($this->getPath(), [$this->getId()=> $this->asConfig()]);
  122. }
  123. }