1: <?php
2:
3: namespace Saklient\Cloud\Resources;
4:
5: require_once __DIR__ . "/../../../Saklient/Util.php";
6: use \Saklient\Util;
7: require_once __DIR__ . "/../../../Saklient/Cloud/Client.php";
8: use \Saklient\Cloud\Client;
9: require_once __DIR__ . "/../../../Saklient/Cloud/Resources/Resource.php";
10: use \Saklient\Cloud\Resources\Resource;
11: require_once __DIR__ . "/../../../Saklient/Cloud/Resources/IsoImage.php";
12: use \Saklient\Cloud\Resources\IsoImage;
13: require_once __DIR__ . "/../../../Saklient/Cloud/Enums/EServerInstanceStatus.php";
14: use \Saklient\Cloud\Enums\EServerInstanceStatus;
15: require_once __DIR__ . "/../../../Saklient/Errors/SaklientException.php";
16: use \Saklient\Errors\SaklientException;
17:
18: 19: 20: 21: 22: 23: 24: 25:
26: class ServerInstance extends Resource {
27:
28: 29: 30: 31: 32: 33: 34:
35: protected $m_status;
36:
37: 38: 39: 40: 41: 42: 43:
44: protected $m_beforeStatus;
45:
46: 47: 48: 49: 50: 51: 52:
53: protected $m_statusChangedAt;
54:
55: 56: 57: 58: 59: 60: 61:
62: protected $m_isoImage;
63:
64: 65: 66: 67: 68: 69: 70:
71: public function __construct(\Saklient\Cloud\Client $client, $obj, $wrapped=false)
72: {
73: parent::__construct($client);
74: Util::validateArgCount(func_num_args(), 2);
75: Util::validateType($client, "\\Saklient\\Cloud\\Client");
76: Util::validateType($wrapped, "boolean");
77: $this->apiDeserialize($obj, $wrapped);
78: }
79:
80: 81: 82: 83: 84: 85:
86: public function isUp()
87: {
88: return $this->get_status() != null && EServerInstanceStatus::compare($this->get_status(), EServerInstanceStatus::up) == 0;
89: }
90:
91: 92: 93: 94: 95: 96:
97: public function isDown()
98: {
99: return $this->get_status() == null || EServerInstanceStatus::compare($this->get_status(), EServerInstanceStatus::down) == 0;
100: }
101:
102: 103: 104: 105: 106:
107: private $n_status = false;
108:
109: 110: 111: 112: 113: 114: 115:
116: private function get_status()
117: {
118: return $this->m_status;
119: }
120:
121:
122:
123: 124: 125: 126: 127:
128: private $n_beforeStatus = false;
129:
130: 131: 132: 133: 134: 135: 136:
137: private function get_beforeStatus()
138: {
139: return $this->m_beforeStatus;
140: }
141:
142:
143:
144: 145: 146: 147: 148:
149: private $n_statusChangedAt = false;
150:
151: 152: 153: 154: 155: 156: 157:
158: private function get_statusChangedAt()
159: {
160: return $this->m_statusChangedAt;
161: }
162:
163:
164:
165: 166: 167: 168: 169:
170: private $n_isoImage = false;
171:
172: 173: 174: 175: 176: 177: 178:
179: private function get_isoImage()
180: {
181: return $this->m_isoImage;
182: }
183:
184:
185:
186: 187: 188: 189: 190: 191: 192:
193: protected function apiDeserializeImpl($r)
194: {
195: Util::validateArgCount(func_num_args(), 1);
196: $this->isNew = $r == null;
197: if ($this->isNew) {
198: $r = (object)[];
199: }
200: $this->isIncomplete = false;
201: if (Util::existsPath($r, "Status")) {
202: $this->m_status = Util::getByPath($r, "Status") == null ? null : "" . Util::getByPath($r, "Status");
203: }
204: else {
205: $this->m_status = null;
206: $this->isIncomplete = true;
207: }
208: $this->n_status = false;
209: if (Util::existsPath($r, "BeforeStatus")) {
210: $this->m_beforeStatus = Util::getByPath($r, "BeforeStatus") == null ? null : "" . Util::getByPath($r, "BeforeStatus");
211: }
212: else {
213: $this->m_beforeStatus = null;
214: $this->isIncomplete = true;
215: }
216: $this->n_beforeStatus = false;
217: if (Util::existsPath($r, "StatusChangedAt")) {
218: $this->m_statusChangedAt = Util::getByPath($r, "StatusChangedAt") == null ? null : Util::str2date("" . Util::getByPath($r, "StatusChangedAt"));
219: }
220: else {
221: $this->m_statusChangedAt = null;
222: $this->isIncomplete = true;
223: }
224: $this->n_statusChangedAt = false;
225: if (Util::existsPath($r, "CDROM")) {
226: $this->m_isoImage = Util::getByPath($r, "CDROM") == null ? null : new IsoImage($this->_client, Util::getByPath($r, "CDROM"));
227: }
228: else {
229: $this->m_isoImage = null;
230: $this->isIncomplete = true;
231: }
232: $this->n_isoImage = false;
233: }
234:
235: 236: 237: 238: 239: 240:
241: protected function apiSerializeImpl($withClean=false)
242: {
243: Util::validateType($withClean, "boolean");
244: $ret = (object)[];
245: if ($withClean || $this->n_status) {
246: Util::setByPath($ret, "Status", $this->m_status);
247: }
248: if ($withClean || $this->n_beforeStatus) {
249: Util::setByPath($ret, "BeforeStatus", $this->m_beforeStatus);
250: }
251: if ($withClean || $this->n_statusChangedAt) {
252: Util::setByPath($ret, "StatusChangedAt", $this->m_statusChangedAt == null ? null : Util::date2str($this->m_statusChangedAt));
253: }
254: if ($withClean || $this->n_isoImage) {
255: Util::setByPath($ret, "CDROM", $withClean ? ($this->m_isoImage == null ? null : $this->m_isoImage->apiSerialize($withClean)) : ($this->m_isoImage == null ? (object)['ID' => "0"] : $this->m_isoImage->apiSerializeID()));
256: }
257: return $ret;
258: }
259:
260: 261: 262:
263: public function __get($key) {
264: switch ($key) {
265: case "status": return $this->get_status();
266: case "beforeStatus": return $this->get_beforeStatus();
267: case "statusChangedAt": return $this->get_statusChangedAt();
268: case "isoImage": return $this->get_isoImage();
269: default: return parent::__get($key);
270: }
271: }
272:
273: }
274:
275: