SnapshotKvm.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. /* * ********************************************************************
  3. * proxmoxCloud product developed. (2017-01-20)
  4. * *
  5. *
  6. * CREATED BY MODULESGARDEN -> http://modulesgarden.com
  7. * CONTACT -> contact@modulesgarden.com
  8. *
  9. *
  10. * This software is furnished under a license and may be used and copied
  11. * only in accordance with the terms of such license and with the
  12. * inclusion of the above copyright notice. This software or any other
  13. * copies thereof may not be provided or otherwise made available to any
  14. * other person. No title to and ownership of the software is hereby
  15. * transferred.
  16. *
  17. *
  18. * ******************************************************************** */
  19. namespace MGProvision\Proxmox\v2\models;
  20. use MGProvision\Proxmox\v2 as proxmox;
  21. /**
  22. * Description of Snapshot
  23. *
  24. * @author Pawel Kopec <pawelk@modulesgarden.com>
  25. * @version 1.0.0
  26. * @deprecated 2.7.0
  27. */
  28. class SnapshotKvm extends AbstractObject
  29. {
  30. private $path;
  31. protected $name;
  32. protected $description;
  33. protected $snaptime;
  34. protected $parent;
  35. protected $vmstate;
  36. public function getName()
  37. {
  38. return $this->name;
  39. }
  40. public function getDescription()
  41. {
  42. return $this->description;
  43. }
  44. public function getSnaptime()
  45. {
  46. return $this->snaptime;
  47. }
  48. public function getParent()
  49. {
  50. return $this->parent;
  51. }
  52. public function setName($name)
  53. {
  54. $this->name = $name;
  55. return $this;
  56. }
  57. public function setDescription($description)
  58. {
  59. $this->description = $description;
  60. return $this;
  61. }
  62. public function setSnaptime($snaptime)
  63. {
  64. $this->snaptime = $snaptime;
  65. return $this;
  66. }
  67. public function setParent($parent)
  68. {
  69. $this->parent = $parent;
  70. return $this;
  71. }
  72. public function getVmstate()
  73. {
  74. return $this->vmstate;
  75. }
  76. public function setVmstate($vmstate)
  77. {
  78. $this->vmstate = $vmstate;
  79. return $this;
  80. }
  81. public function setPath($path)
  82. {
  83. if (!preg_match('/\/snapshot/', $path)) {
  84. throw new proxmox\ProxmoxApiException(sprintf("Snapshot Path ('%s') is not valid", $path));
  85. }
  86. $this->path = $path;
  87. return $this;
  88. }
  89. public function create() {
  90. if (empty($this->path))
  91. throw new proxmox\ProxmoxApiException('Snapshot [path] - property is missing and it is not optional');
  92. $request = array(
  93. "snapname" => $this->getName(),
  94. "description" => $this->getDescription(),
  95. "vmstate" => $this->getVmstate()
  96. );
  97. return $this->api()->post($this->path, $request);
  98. }
  99. public function update() {
  100. if (empty($this->path))
  101. throw new proxmox\ProxmoxApiException('Snapshot [path] - property is missing and it is not optional');
  102. return $this->api()->put($this->path . "/config", array("description" => $this->getDescription()));
  103. }
  104. public function rollback() {
  105. if (empty($this->path))
  106. throw new proxmox\ProxmoxApiException('Snapshot [path] - property is missing and it is not optional');
  107. return $this->api()->post($this->path . '/rollback');
  108. }
  109. public function delete() {
  110. if (empty($this->path))
  111. throw new proxmox\ProxmoxApiException('Snapshot [path] - property is missing and it is not optional');
  112. return $this->api()->delete($this->path);
  113. }
  114. public function getAttributes() {
  115. return array(
  116. "name" => $this->getName(),
  117. "date" => date("Y:m:d H:i:s", $this->snaptime),
  118. "description" => $this->getDescription(),
  119. "snaptime" => $this->getSnaptime(),
  120. "parent" => $this->getParent(),
  121. "vmstate" => $this->getVmstate(),
  122. );
  123. }
  124. }