Overview

Namespaces

  • PHP
  • Saklient
    • Cloud
      • Enums
      • Errors
      • Models
      • Resources
    • Errors

Classes

  • Activity
  • Appliance
  • Archive
  • Bridge
  • Disk
  • DiskActivity
  • DiskConfig
  • DiskPlan
  • FtpInfo
  • Icon
  • Iface
  • IfaceActivity
  • Ipv4Net
  • Ipv4Range
  • Ipv6Net
  • IsoImage
  • LbServer
  • LbVirtualIp
  • License
  • LicenseInfo
  • LoadBalancer
  • Region
  • Router
  • RouterActivity
  • RouterPlan
  • Script
  • Server
  • ServerActivity
  • ServerInstance
  • ServerPlan
  • Swytch
  • VpcRouter
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: 
  3: namespace Saklient\Cloud\Resources;
  4: 
  5: require_once __DIR__ . "/../../../Saklient/Errors/HttpException.php";
  6: use \Saklient\Errors\HttpException;
  7: require_once __DIR__ . "/../../../Saklient/Errors/SaklientException.php";
  8: use \Saklient\Errors\SaklientException;
  9: require_once __DIR__ . "/../../../Saklient/Cloud/Client.php";
 10: use \Saklient\Cloud\Client;
 11: require_once __DIR__ . "/../../../Saklient/Cloud/Resources/Resource.php";
 12: use \Saklient\Cloud\Resources\Resource;
 13: require_once __DIR__ . "/../../../Saklient/Cloud/Resources/Icon.php";
 14: use \Saklient\Cloud\Resources\Icon;
 15: require_once __DIR__ . "/../../../Saklient/Cloud/Resources/Swytch.php";
 16: use \Saklient\Cloud\Resources\Swytch;
 17: require_once __DIR__ . "/../../../Saklient/Cloud/Resources/Ipv4Net.php";
 18: use \Saklient\Cloud\Resources\Ipv4Net;
 19: require_once __DIR__ . "/../../../Saklient/Cloud/Resources/Ipv6Net.php";
 20: use \Saklient\Cloud\Resources\Ipv6Net;
 21: require_once __DIR__ . "/../../../Saklient/Cloud/Resources/RouterActivity.php";
 22: use \Saklient\Cloud\Resources\RouterActivity;
 23: require_once __DIR__ . "/../../../Saklient/Cloud/Models/Model_Swytch.php";
 24: use \Saklient\Cloud\Models\Model_Swytch;
 25: require_once __DIR__ . "/../../../Saklient/Util.php";
 26: use \Saklient\Util;
 27: 
 28: /**
 29:  * ルータの実体1つに対応し、属性の取得や操作を行うためのクラス。
 30:  * 
 31:  * @property-read \Saklient\Cloud\Resources\RouterActivity $activity アクティビティ 
 32:  * @property-read string $id ID 
 33:  * @property string $name 名前 
 34:  * @property string $description 説明 
 35:  * @property int $networkMaskLen ネットワークのマスク長 
 36:  * @property int $bandWidthMbps 帯域幅 
 37:  * @property-read string $swytchId スイッチ 
 38:  */
 39: class Router extends Resource {
 40:     
 41:     /**
 42:      * ID
 43:      * 
 44:      * @access protected
 45:      * @ignore
 46:      * @var string
 47:      */
 48:     protected $m_id;
 49:     
 50:     /**
 51:      * 名前
 52:      * 
 53:      * @access protected
 54:      * @ignore
 55:      * @var string
 56:      */
 57:     protected $m_name;
 58:     
 59:     /**
 60:      * 説明
 61:      * 
 62:      * @access protected
 63:      * @ignore
 64:      * @var string
 65:      */
 66:     protected $m_description;
 67:     
 68:     /**
 69:      * ネットワークのマスク長
 70:      * 
 71:      * @access protected
 72:      * @ignore
 73:      * @var int
 74:      */
 75:     protected $m_networkMaskLen;
 76:     
 77:     /**
 78:      * 帯域幅
 79:      * 
 80:      * @access protected
 81:      * @ignore
 82:      * @var int
 83:      */
 84:     protected $m_bandWidthMbps;
 85:     
 86:     /**
 87:      * スイッチ
 88:      * 
 89:      * @access protected
 90:      * @ignore
 91:      * @var string
 92:      */
 93:     protected $m_swytchId;
 94:     
 95:     /**
 96:      * @private
 97:      * @access protected
 98:      * @ignore
 99:      * @return string
100:      */
101:     protected function _apiPath()
102:     {
103:         return "/internet";
104:     }
105:     
106:     /**
107:      * @private
108:      * @access protected
109:      * @ignore
110:      * @return string
111:      */
112:     protected function _rootKey()
113:     {
114:         return "Internet";
115:     }
116:     
117:     /**
118:      * @private
119:      * @access protected
120:      * @ignore
121:      * @return string
122:      */
123:     protected function _rootKeyM()
124:     {
125:         return "Internet";
126:     }
127:     
128:     /**
129:      * @private
130:      * @access public
131:      * @ignore
132:      * @return string
133:      */
134:     public function _className()
135:     {
136:         return "Router";
137:     }
138:     
139:     /**
140:      * @private
141:      * @access public
142:      * @ignore
143:      * @return string
144:      */
145:     public function _id()
146:     {
147:         return $this->get_id();
148:     }
149:     
150:     /**
151:      * このローカルオブジェクトに現在設定されているリソース情報をAPIに送信し、新規作成または上書き保存します。
152:      * 
153:      * @access public
154:      * @return \Saklient\Cloud\Resources\Router this
155:      */
156:     public function save()
157:     {
158:         return $this->_save();
159:     }
160:     
161:     /**
162:      * 最新のリソース情報を再取得します。
163:      * 
164:      * @access public
165:      * @return \Saklient\Cloud\Resources\Router this
166:      */
167:     public function reload()
168:     {
169:         return $this->_reload();
170:     }
171:     
172:     /**
173:      * @private
174:      * @access protected
175:      * @ignore
176:      * @var RouterActivity
177:      */
178:     protected $_activity;
179:     
180:     /**
181:      * @access public
182:      * @ignore
183:      * @return \Saklient\Cloud\Resources\RouterActivity
184:      */
185:     public function get_activity()
186:     {
187:         return $this->_activity;
188:     }
189:     
190:     
191:     
192:     /**
193:      * @ignore
194:      * @access public
195:      * @param \Saklient\Cloud\Client $client
196:      * @param mixed $obj
197:      * @param boolean $wrapped=false
198:      */
199:     public function __construct(\Saklient\Cloud\Client $client, $obj, $wrapped=false)
200:     {
201:         parent::__construct($client);
202:         Util::validateArgCount(func_num_args(), 2);
203:         Util::validateType($client, "\\Saklient\\Cloud\\Client");
204:         Util::validateType($wrapped, "boolean");
205:         $this->_activity = new RouterActivity($client);
206:         $this->apiDeserialize($obj, $wrapped);
207:     }
208:     
209:     /**
210:      * @private
211:      * @access protected
212:      * @ignore
213:      * @param mixed $r
214:      * @param mixed $root
215:      * @return void
216:      */
217:     protected function _onAfterApiDeserialize($r, $root)
218:     {
219:         Util::validateArgCount(func_num_args(), 2);
220:         if ($r != null) {
221:             $this->_activity->setSourceId($this->_id());
222:         }
223:     }
224:     
225:     /**
226:      * 作成中のルータが利用可能になるまで待機します。
227:      * 
228:      * @ignore
229:      * @access public
230:      * @param int $timeoutSec
231:      * @param callback $callback
232:      * @return void
233:      */
234:     public function afterCreate($timeoutSec, $callback)
235:     {
236:         Util::validateArgCount(func_num_args(), 2);
237:         Util::validateType($timeoutSec, "int");
238:         Util::validateType($callback, "callback");
239:         $ret = $this->sleepWhileCreating($timeoutSec);
240:         $callback($this, $ret);
241:     }
242:     
243:     /**
244:      * 作成中のルータが利用可能になるまで待機します。
245:      * 
246:      * @access public
247:      * @param int $timeoutSec=120
248:      * @return boolean 成功時はtrue、タイムアウトやエラーによる失敗時はfalseを返します。
249:      */
250:     public function sleepWhileCreating($timeoutSec=120)
251:     {
252:         Util::validateType($timeoutSec, "int");
253:         $step = 3;
254:         $isOk = false;
255:         while (0 < $timeoutSec) {
256:             try {
257:                 if ($this->exists()) {
258:                     $this->reload();
259:                     $isOk = true;
260:                 }
261:             }
262:             catch (HttpException $ex) {
263:             }
264:             $timeoutSec -= $step;
265:             if ($isOk) {
266:                 $timeoutSec = 0;
267:             }
268:             if (0 < $timeoutSec) {
269:                 Util::sleep($step);
270:             }
271:         }
272:         return $isOk;
273:     }
274:     
275:     /**
276:      * このルータが接続されているスイッチを取得します。
277:      * 
278:      * @access public
279:      * @return \Saklient\Cloud\Resources\Swytch
280:      */
281:     public function getSwytch()
282:     {
283:         $model = Util::createClassInstance("saklient.cloud.models.Model_Swytch", new \ArrayObject([$this->_client]));
284:         $id = $this->get_swytchId();
285:         return $model->getById($id);
286:     }
287:     
288:     /**
289:      * このルータ+スイッチでIPv6アドレスを有効にします。
290:      * 
291:      * @access public
292:      * @return \Saklient\Cloud\Resources\Ipv6Net 有効化されたIPv6ネットワーク
293:      */
294:     public function addIpv6Net()
295:     {
296:         $result = $this->_client->request("POST", $this->_apiPath() . "/" . Util::urlEncode($this->_id()) . "/ipv6net");
297:         $this->reload();
298:         return new Ipv6Net($this->_client, $result->{"IPv6Net"});
299:     }
300:     
301:     /**
302:      * このルータ+スイッチでIPv6アドレスを無効にします。
303:      * 
304:      * @access public
305:      * @param \Saklient\Cloud\Resources\Ipv6Net $ipv6Net
306:      * @return \Saklient\Cloud\Resources\Router this
307:      */
308:     public function removeIpv6Net(\Saklient\Cloud\Resources\Ipv6Net $ipv6Net)
309:     {
310:         Util::validateArgCount(func_num_args(), 1);
311:         Util::validateType($ipv6Net, "\\Saklient\\Cloud\\Resources\\Ipv6Net");
312:         $this->_client->request("DELETE", $this->_apiPath() . "/" . Util::urlEncode($this->_id()) . "/ipv6net/" . $ipv6Net->_id());
313:         $this->reload();
314:         return $this;
315:     }
316:     
317:     /**
318:      * このルータ+スイッチにスタティックルートを追加します。
319:      * 
320:      * @access public
321:      * @param int $maskLen
322:      * @param string $nextHop
323:      * @return \Saklient\Cloud\Resources\Ipv4Net 追加されたスタティックルート
324:      */
325:     public function addStaticRoute($maskLen, $nextHop)
326:     {
327:         Util::validateArgCount(func_num_args(), 2);
328:         Util::validateType($maskLen, "int");
329:         Util::validateType($nextHop, "string");
330:         $q = (object)[];
331:         Util::setByPath($q, "NetworkMaskLen", $maskLen);
332:         Util::setByPath($q, "NextHop", $nextHop);
333:         $result = $this->_client->request("POST", $this->_apiPath() . "/" . Util::urlEncode($this->_id()) . "/subnet", $q);
334:         $this->reload();
335:         return new Ipv4Net($this->_client, $result->{"Subnet"});
336:     }
337:     
338:     /**
339:      * このルータ+スイッチからスタティックルートを削除します。
340:      * 
341:      * @access public
342:      * @param \Saklient\Cloud\Resources\Ipv4Net $ipv4Net
343:      * @return \Saklient\Cloud\Resources\Router this
344:      */
345:     public function removeStaticRoute(\Saklient\Cloud\Resources\Ipv4Net $ipv4Net)
346:     {
347:         Util::validateArgCount(func_num_args(), 1);
348:         Util::validateType($ipv4Net, "\\Saklient\\Cloud\\Resources\\Ipv4Net");
349:         $this->_client->request("DELETE", $this->_apiPath() . "/" . Util::urlEncode($this->_id()) . "/subnet/" . $ipv4Net->_id());
350:         $this->reload();
351:         return $this;
352:     }
353:     
354:     /**
355:      * このルータ+スイッチの帯域プランを変更します。
356:      * 
357:      * 成功時はリソースIDが変わることにご注意ください。
358:      * 
359:      * @access public
360:      * @param int $bandWidthMbps
361:      * @return \Saklient\Cloud\Resources\Router this
362:      */
363:     public function changePlan($bandWidthMbps)
364:     {
365:         Util::validateArgCount(func_num_args(), 1);
366:         Util::validateType($bandWidthMbps, "int");
367:         $path = $this->_apiPath() . "/" . Util::urlEncode($this->_id()) . "/bandwidth";
368:         $q = (object)[];
369:         Util::setByPath($q, "Internet.BandWidthMbps", $bandWidthMbps);
370:         $result = $this->_client->request("PUT", $path, $q);
371:         $this->apiDeserialize($result, true);
372:         return $this;
373:     }
374:     
375:     /**
376:      * @access private
377:      * @ignore
378:      * @var boolean
379:      */
380:     private $n_id = false;
381:     
382:     /**
383:      * (This method is generated in Translator_default#buildImpl)
384:      * 
385:      * @access private
386:      * @ignore
387:      * @return string
388:      */
389:     private function get_id()
390:     {
391:         return $this->m_id;
392:     }
393:     
394:     
395:     
396:     /**
397:      * @access private
398:      * @ignore
399:      * @var boolean
400:      */
401:     private $n_name = false;
402:     
403:     /**
404:      * (This method is generated in Translator_default#buildImpl)
405:      * 
406:      * @access private
407:      * @ignore
408:      * @return string
409:      */
410:     private function get_name()
411:     {
412:         return $this->m_name;
413:     }
414:     
415:     /**
416:      * (This method is generated in Translator_default#buildImpl)
417:      * 
418:      * @access private
419:      * @ignore
420:      * @param string $v
421:      * @return string
422:      */
423:     private function set_name($v)
424:     {
425:         Util::validateArgCount(func_num_args(), 1);
426:         Util::validateType($v, "string");
427:         $this->m_name = $v;
428:         $this->n_name = true;
429:         return $this->m_name;
430:     }
431:     
432:     
433:     
434:     /**
435:      * @access private
436:      * @ignore
437:      * @var boolean
438:      */
439:     private $n_description = false;
440:     
441:     /**
442:      * (This method is generated in Translator_default#buildImpl)
443:      * 
444:      * @access private
445:      * @ignore
446:      * @return string
447:      */
448:     private function get_description()
449:     {
450:         return $this->m_description;
451:     }
452:     
453:     /**
454:      * (This method is generated in Translator_default#buildImpl)
455:      * 
456:      * @access private
457:      * @ignore
458:      * @param string $v
459:      * @return string
460:      */
461:     private function set_description($v)
462:     {
463:         Util::validateArgCount(func_num_args(), 1);
464:         Util::validateType($v, "string");
465:         $this->m_description = $v;
466:         $this->n_description = true;
467:         return $this->m_description;
468:     }
469:     
470:     
471:     
472:     /**
473:      * @access private
474:      * @ignore
475:      * @var boolean
476:      */
477:     private $n_networkMaskLen = false;
478:     
479:     /**
480:      * (This method is generated in Translator_default#buildImpl)
481:      * 
482:      * @access private
483:      * @ignore
484:      * @return int
485:      */
486:     private function get_networkMaskLen()
487:     {
488:         return $this->m_networkMaskLen;
489:     }
490:     
491:     /**
492:      * (This method is generated in Translator_default#buildImpl)
493:      * 
494:      * @access private
495:      * @ignore
496:      * @param int|null $v
497:      * @return int
498:      */
499:     private function set_networkMaskLen($v)
500:     {
501:         Util::validateArgCount(func_num_args(), 1);
502:         Util::validateType($v, "int");
503:         if (!$this->isNew) {
504:             throw new SaklientException("immutable_field", "Immutable fields cannot be modified after the resource creation: " . "Saklient\\Cloud\\Resources\\Router#networkMaskLen");
505:         }
506:         $this->m_networkMaskLen = $v;
507:         $this->n_networkMaskLen = true;
508:         return $this->m_networkMaskLen;
509:     }
510:     
511:     
512:     
513:     /**
514:      * @access private
515:      * @ignore
516:      * @var boolean
517:      */
518:     private $n_bandWidthMbps = false;
519:     
520:     /**
521:      * (This method is generated in Translator_default#buildImpl)
522:      * 
523:      * @access private
524:      * @ignore
525:      * @return int
526:      */
527:     private function get_bandWidthMbps()
528:     {
529:         return $this->m_bandWidthMbps;
530:     }
531:     
532:     /**
533:      * (This method is generated in Translator_default#buildImpl)
534:      * 
535:      * @access private
536:      * @ignore
537:      * @param int|null $v
538:      * @return int
539:      */
540:     private function set_bandWidthMbps($v)
541:     {
542:         Util::validateArgCount(func_num_args(), 1);
543:         Util::validateType($v, "int");
544:         if (!$this->isNew) {
545:             throw new SaklientException("immutable_field", "Immutable fields cannot be modified after the resource creation: " . "Saklient\\Cloud\\Resources\\Router#bandWidthMbps");
546:         }
547:         $this->m_bandWidthMbps = $v;
548:         $this->n_bandWidthMbps = true;
549:         return $this->m_bandWidthMbps;
550:     }
551:     
552:     
553:     
554:     /**
555:      * @access private
556:      * @ignore
557:      * @var boolean
558:      */
559:     private $n_swytchId = false;
560:     
561:     /**
562:      * (This method is generated in Translator_default#buildImpl)
563:      * 
564:      * @access private
565:      * @ignore
566:      * @return string
567:      */
568:     private function get_swytchId()
569:     {
570:         return $this->m_swytchId;
571:     }
572:     
573:     
574:     
575:     /**
576:      * (This method is generated in Translator_default#buildImpl)
577:      * 
578:      * @access protected
579:      * @ignore
580:      * @param mixed $r
581:      */
582:     protected function apiDeserializeImpl($r)
583:     {
584:         Util::validateArgCount(func_num_args(), 1);
585:         $this->isNew = $r == null;
586:         if ($this->isNew) {
587:             $r = (object)[];
588:         }
589:         $this->isIncomplete = false;
590:         if (Util::existsPath($r, "ID")) {
591:             $this->m_id = Util::getByPath($r, "ID") == null ? null : "" . Util::getByPath($r, "ID");
592:         }
593:         else {
594:             $this->m_id = null;
595:             $this->isIncomplete = true;
596:         }
597:         $this->n_id = false;
598:         if (Util::existsPath($r, "Name")) {
599:             $this->m_name = Util::getByPath($r, "Name") == null ? null : "" . Util::getByPath($r, "Name");
600:         }
601:         else {
602:             $this->m_name = null;
603:             $this->isIncomplete = true;
604:         }
605:         $this->n_name = false;
606:         if (Util::existsPath($r, "Description")) {
607:             $this->m_description = Util::getByPath($r, "Description") == null ? null : "" . Util::getByPath($r, "Description");
608:         }
609:         else {
610:             $this->m_description = null;
611:             $this->isIncomplete = true;
612:         }
613:         $this->n_description = false;
614:         if (Util::existsPath($r, "NetworkMaskLen")) {
615:             $this->m_networkMaskLen = Util::getByPath($r, "NetworkMaskLen") == null ? null : intval("" . Util::getByPath($r, "NetworkMaskLen"));
616:         }
617:         else {
618:             $this->m_networkMaskLen = null;
619:             $this->isIncomplete = true;
620:         }
621:         $this->n_networkMaskLen = false;
622:         if (Util::existsPath($r, "BandWidthMbps")) {
623:             $this->m_bandWidthMbps = Util::getByPath($r, "BandWidthMbps") == null ? null : intval("" . Util::getByPath($r, "BandWidthMbps"));
624:         }
625:         else {
626:             $this->m_bandWidthMbps = null;
627:             $this->isIncomplete = true;
628:         }
629:         $this->n_bandWidthMbps = false;
630:         if (Util::existsPath($r, "Switch.ID")) {
631:             $this->m_swytchId = Util::getByPath($r, "Switch.ID") == null ? null : "" . Util::getByPath($r, "Switch.ID");
632:         }
633:         else {
634:             $this->m_swytchId = null;
635:             $this->isIncomplete = true;
636:         }
637:         $this->n_swytchId = false;
638:     }
639:     
640:     /**
641:      * @ignore
642:      * @access protected
643:      * @param boolean $withClean=false
644:      * @return mixed
645:      */
646:     protected function apiSerializeImpl($withClean=false)
647:     {
648:         Util::validateType($withClean, "boolean");
649:         $missing = new \ArrayObject([]);
650:         $ret = (object)[];
651:         if ($withClean || $this->n_id) {
652:             Util::setByPath($ret, "ID", $this->m_id);
653:         }
654:         if ($withClean || $this->n_name) {
655:             Util::setByPath($ret, "Name", $this->m_name);
656:         }
657:         else {
658:             if ($this->isNew) {
659:                 $missing->append("name");
660:             }
661:         }
662:         if ($withClean || $this->n_description) {
663:             Util::setByPath($ret, "Description", $this->m_description);
664:         }
665:         if ($withClean || $this->n_networkMaskLen) {
666:             Util::setByPath($ret, "NetworkMaskLen", $this->m_networkMaskLen);
667:         }
668:         else {
669:             if ($this->isNew) {
670:                 $missing->append("networkMaskLen");
671:             }
672:         }
673:         if ($withClean || $this->n_bandWidthMbps) {
674:             Util::setByPath($ret, "BandWidthMbps", $this->m_bandWidthMbps);
675:         }
676:         else {
677:             if ($this->isNew) {
678:                 $missing->append("bandWidthMbps");
679:             }
680:         }
681:         if ($withClean || $this->n_swytchId) {
682:             Util::setByPath($ret, "Switch.ID", $this->m_swytchId);
683:         }
684:         if ($missing->count() > 0) {
685:             throw new SaklientException("required_field", "Required fields must be set before the Router creation: " . implode(", ", (array)($missing)));
686:         }
687:         return $ret;
688:     }
689:     
690:     /**
691:      * @ignore
692:      */
693:     public function __get($key) {
694:         switch ($key) {
695:             case "activity": return $this->get_activity();
696:             case "id": return $this->get_id();
697:             case "name": return $this->get_name();
698:             case "description": return $this->get_description();
699:             case "networkMaskLen": return $this->get_networkMaskLen();
700:             case "bandWidthMbps": return $this->get_bandWidthMbps();
701:             case "swytchId": return $this->get_swytchId();
702:             default: return parent::__get($key);
703:         }
704:     }
705:     
706:     /**
707:      * @ignore
708:      */
709:     public function __set($key, $v) {
710:         switch ($key) {
711:             case "name": return $this->set_name($v);
712:             case "description": return $this->set_description($v);
713:             case "networkMaskLen": return $this->set_networkMaskLen($v);
714:             case "bandWidthMbps": return $this->set_bandWidthMbps($v);
715:             default: return parent::__set($key, $v);
716:         }
717:     }
718: 
719: }
720: 
721: 
API documentation generated by ApiGen 2.8.0