1: <?php
2:
3: namespace Saklient\Cloud\Resources;
4:
5: require_once __DIR__ . "/../../../Saklient/Errors/SaklientException.php";
6: use \Saklient\Errors\SaklientException;
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/Swytch.php";
12: use \Saklient\Cloud\Resources\Swytch;
13: require_once __DIR__ . "/../../../Saklient/Cloud/Resources/IfaceActivity.php";
14: use \Saklient\Cloud\Resources\IfaceActivity;
15: require_once __DIR__ . "/../../../Saklient/Util.php";
16: use \Saklient\Util;
17:
18: 19: 20: 21: 22: 23: 24: 25: 26: 27:
28: class Iface extends Resource {
29:
30: 31: 32: 33: 34: 35: 36:
37: protected $m_id;
38:
39: 40: 41: 42: 43: 44: 45:
46: protected $m_macAddress;
47:
48: 49: 50: 51: 52: 53: 54:
55: protected $m_ipAddress;
56:
57: 58: 59: 60: 61: 62: 63:
64: protected $m_userIpAddress;
65:
66: 67: 68: 69: 70: 71: 72:
73: protected $m_serverId;
74:
75: 76: 77: 78: 79: 80:
81: protected function _apiPath()
82: {
83: return "/interface";
84: }
85:
86: 87: 88: 89: 90: 91:
92: protected function _rootKey()
93: {
94: return "Interface";
95: }
96:
97: 98: 99: 100: 101: 102:
103: protected function _rootKeyM()
104: {
105: return "Interfaces";
106: }
107:
108: 109: 110: 111: 112: 113:
114: public function _className()
115: {
116: return "Iface";
117: }
118:
119: 120: 121: 122: 123: 124:
125: public function _id()
126: {
127: return $this->get_id();
128: }
129:
130: 131: 132: 133: 134: 135:
136: public function save()
137: {
138: return $this->_save();
139: }
140:
141: 142: 143: 144: 145: 146:
147: public function reload()
148: {
149: return $this->_reload();
150: }
151:
152: 153: 154: 155: 156: 157:
158: protected $_activity;
159:
160: 161: 162: 163: 164:
165: public function get_activity()
166: {
167: return $this->_activity;
168: }
169:
170:
171:
172: 173: 174: 175: 176: 177: 178:
179: public function __construct(\Saklient\Cloud\Client $client, $obj, $wrapped=false)
180: {
181: parent::__construct($client);
182: Util::validateArgCount(func_num_args(), 2);
183: Util::validateType($client, "\\Saklient\\Cloud\\Client");
184: Util::validateType($wrapped, "boolean");
185: $this->_activity = new IfaceActivity($client);
186: $this->apiDeserialize($obj, $wrapped);
187: }
188:
189: 190: 191: 192: 193: 194: 195: 196:
197: protected function _onAfterApiDeserialize($r, $root)
198: {
199: Util::validateArgCount(func_num_args(), 2);
200: if ($r != null) {
201: $this->_activity->setSourceId($this->_id());
202: }
203: }
204:
205: 206: 207: 208: 209: 210: 211:
212: public function connectToSwytch(\Saklient\Cloud\Resources\Swytch $swytch)
213: {
214: Util::validateArgCount(func_num_args(), 1);
215: Util::validateType($swytch, "\\Saklient\\Cloud\\Resources\\Swytch");
216: $this->_client->request("PUT", $this->_apiPath() . "/" . Util::urlEncode($this->_id()) . "/to/switch/" . Util::urlEncode($swytch->_id()));
217: return $this->reload();
218: }
219:
220: 221: 222: 223: 224: 225:
226: public function connectToSharedSegment()
227: {
228: $this->_client->request("PUT", $this->_apiPath() . "/" . Util::urlEncode($this->_id()) . "/to/switch/shared");
229: return $this->reload();
230: }
231:
232: 233: 234: 235: 236: 237:
238: public function disconnectFromSwytch()
239: {
240: $this->_client->request("DELETE", $this->_apiPath() . "/" . Util::urlEncode($this->_id()) . "/to/switch");
241: return $this->reload();
242: }
243:
244: 245: 246: 247: 248:
249: private $n_id = false;
250:
251: 252: 253: 254: 255: 256: 257:
258: private function get_id()
259: {
260: return $this->m_id;
261: }
262:
263:
264:
265: 266: 267: 268: 269:
270: private $n_macAddress = false;
271:
272: 273: 274: 275: 276: 277: 278:
279: private function get_macAddress()
280: {
281: return $this->m_macAddress;
282: }
283:
284:
285:
286: 287: 288: 289: 290:
291: private $n_ipAddress = false;
292:
293: 294: 295: 296: 297: 298: 299:
300: private function get_ipAddress()
301: {
302: return $this->m_ipAddress;
303: }
304:
305:
306:
307: 308: 309: 310: 311:
312: private $n_userIpAddress = false;
313:
314: 315: 316: 317: 318: 319: 320:
321: private function get_userIpAddress()
322: {
323: return $this->m_userIpAddress;
324: }
325:
326: 327: 328: 329: 330: 331: 332: 333:
334: private function set_userIpAddress($v)
335: {
336: Util::validateArgCount(func_num_args(), 1);
337: Util::validateType($v, "string");
338: $this->m_userIpAddress = $v;
339: $this->n_userIpAddress = true;
340: return $this->m_userIpAddress;
341: }
342:
343:
344:
345: 346: 347: 348: 349:
350: private $n_serverId = false;
351:
352: 353: 354: 355: 356: 357: 358:
359: private function get_serverId()
360: {
361: return $this->m_serverId;
362: }
363:
364: 365: 366: 367: 368: 369: 370: 371:
372: private function set_serverId($v)
373: {
374: Util::validateArgCount(func_num_args(), 1);
375: Util::validateType($v, "string");
376: if (!$this->isNew) {
377: throw new SaklientException("immutable_field", "Immutable fields cannot be modified after the resource creation: " . "Saklient\\Cloud\\Resources\\Iface#serverId");
378: }
379: $this->m_serverId = $v;
380: $this->n_serverId = true;
381: return $this->m_serverId;
382: }
383:
384:
385:
386: 387: 388: 389: 390: 391: 392:
393: protected function apiDeserializeImpl($r)
394: {
395: Util::validateArgCount(func_num_args(), 1);
396: $this->isNew = $r == null;
397: if ($this->isNew) {
398: $r = (object)[];
399: }
400: $this->isIncomplete = false;
401: if (Util::existsPath($r, "ID")) {
402: $this->m_id = Util::getByPath($r, "ID") == null ? null : "" . Util::getByPath($r, "ID");
403: }
404: else {
405: $this->m_id = null;
406: $this->isIncomplete = true;
407: }
408: $this->n_id = false;
409: if (Util::existsPath($r, "MACAddress")) {
410: $this->m_macAddress = Util::getByPath($r, "MACAddress") == null ? null : "" . Util::getByPath($r, "MACAddress");
411: }
412: else {
413: $this->m_macAddress = null;
414: $this->isIncomplete = true;
415: }
416: $this->n_macAddress = false;
417: if (Util::existsPath($r, "IPAddress")) {
418: $this->m_ipAddress = Util::getByPath($r, "IPAddress") == null ? null : "" . Util::getByPath($r, "IPAddress");
419: }
420: else {
421: $this->m_ipAddress = null;
422: $this->isIncomplete = true;
423: }
424: $this->n_ipAddress = false;
425: if (Util::existsPath($r, "UserIPAddress")) {
426: $this->m_userIpAddress = Util::getByPath($r, "UserIPAddress") == null ? null : "" . Util::getByPath($r, "UserIPAddress");
427: }
428: else {
429: $this->m_userIpAddress = null;
430: $this->isIncomplete = true;
431: }
432: $this->n_userIpAddress = false;
433: if (Util::existsPath($r, "Server.ID")) {
434: $this->m_serverId = Util::getByPath($r, "Server.ID") == null ? null : "" . Util::getByPath($r, "Server.ID");
435: }
436: else {
437: $this->m_serverId = null;
438: $this->isIncomplete = true;
439: }
440: $this->n_serverId = false;
441: }
442:
443: 444: 445: 446: 447: 448:
449: protected function apiSerializeImpl($withClean=false)
450: {
451: Util::validateType($withClean, "boolean");
452: $missing = new \ArrayObject([]);
453: $ret = (object)[];
454: if ($withClean || $this->n_id) {
455: Util::setByPath($ret, "ID", $this->m_id);
456: }
457: if ($withClean || $this->n_macAddress) {
458: Util::setByPath($ret, "MACAddress", $this->m_macAddress);
459: }
460: if ($withClean || $this->n_ipAddress) {
461: Util::setByPath($ret, "IPAddress", $this->m_ipAddress);
462: }
463: if ($withClean || $this->n_userIpAddress) {
464: Util::setByPath($ret, "UserIPAddress", $this->m_userIpAddress);
465: }
466: if ($withClean || $this->n_serverId) {
467: Util::setByPath($ret, "Server.ID", $this->m_serverId);
468: }
469: else {
470: if ($this->isNew) {
471: $missing->append("serverId");
472: }
473: }
474: if ($missing->count() > 0) {
475: throw new SaklientException("required_field", "Required fields must be set before the Iface creation: " . implode(", ", (array)($missing)));
476: }
477: return $ret;
478: }
479:
480: 481: 482:
483: public function __get($key) {
484: switch ($key) {
485: case "activity": return $this->get_activity();
486: case "id": return $this->get_id();
487: case "macAddress": return $this->get_macAddress();
488: case "ipAddress": return $this->get_ipAddress();
489: case "userIpAddress": return $this->get_userIpAddress();
490: case "serverId": return $this->get_serverId();
491: default: return parent::__get($key);
492: }
493: }
494:
495: 496: 497:
498: public function __set($key, $v) {
499: switch ($key) {
500: case "userIpAddress": return $this->set_userIpAddress($v);
501: case "serverId": return $this->set_serverId($v);
502: default: return parent::__set($key, $v);
503: }
504: }
505:
506: }
507:
508: