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/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/Appliance.php";
 10: use \Saklient\Cloud\Resources\Appliance;
 11: require_once __DIR__ . "/../../../Saklient/Cloud/Resources/LbVirtualIp.php";
 12: use \Saklient\Cloud\Resources\LbVirtualIp;
 13: require_once __DIR__ . "/../../../Saklient/Cloud/Resources/Swytch.php";
 14: use \Saklient\Cloud\Resources\Swytch;
 15: require_once __DIR__ . "/../../../Saklient/Cloud/Resources/Ipv4Net.php";
 16: use \Saklient\Cloud\Resources\Ipv4Net;
 17: require_once __DIR__ . "/../../../Saklient/Cloud/Enums/EApplianceClass.php";
 18: use \Saklient\Cloud\Enums\EApplianceClass;
 19: require_once __DIR__ . "/../../../Saklient/Util.php";
 20: use \Saklient\Util;
 21: 
 22: /**
 23:  * ロードバランサの実体1つに対応し、属性の取得や操作を行うためのクラス。
 24:  * 
 25:  * @property-read \ArrayObject $virtualIps 仮想IPアドレス {@link \Saklient\Cloud\Resources\LbVirtualIp} の配列 
 26:  * @property string $defaultRoute デフォルトルート 
 27:  * @property int $maskLen マスク長 
 28:  * @property int $vrid VRID 
 29:  */
 30: class LoadBalancer extends Appliance {
 31:     
 32:     /**
 33:      * @private
 34:      * @access protected
 35:      * @ignore
 36:      * @var LbVirtualIp[]
 37:      */
 38:     protected $_virtualIps;
 39:     
 40:     /**
 41:      * @access public
 42:      * @ignore
 43:      * @return \Saklient\Cloud\Resources\LbVirtualIp[]
 44:      */
 45:     public function get_virtualIps()
 46:     {
 47:         return $this->_virtualIps;
 48:     }
 49:     
 50:     
 51:     
 52:     /**
 53:      * @access public
 54:      * @ignore
 55:      * @return string
 56:      */
 57:     public function get_defaultRoute()
 58:     {
 59:         return Util::getByPath($this->rawAnnotation, "Network.DefaultRoute");
 60:     }
 61:     
 62:     /**
 63:      * @access public
 64:      * @ignore
 65:      * @param string $v
 66:      * @return string
 67:      */
 68:     public function set_defaultRoute($v)
 69:     {
 70:         Util::validateArgCount(func_num_args(), 1);
 71:         Util::validateType($v, "string");
 72:         Util::setByPath($this->rawAnnotation, "Network.DefaultRoute", $v);
 73:         return $v;
 74:     }
 75:     
 76:     
 77:     
 78:     /**
 79:      * @access public
 80:      * @ignore
 81:      * @return int
 82:      */
 83:     public function get_maskLen()
 84:     {
 85:         $maskLen = Util::getByPath($this->rawAnnotation, "Network.NetworkMaskLen");
 86:         if ($maskLen == null) {
 87:             throw new SaklientException("invalid_data", "Data of the resource is invalid");
 88:         }
 89:         return intval($maskLen);
 90:     }
 91:     
 92:     /**
 93:      * @access public
 94:      * @ignore
 95:      * @param int $v
 96:      * @return int
 97:      */
 98:     public function set_maskLen($v)
 99:     {
100:         Util::validateArgCount(func_num_args(), 1);
101:         Util::validateType($v, "int");
102:         Util::setByPath($this->rawAnnotation, "Network.NetworkMaskLen", $v);
103:         return $v;
104:     }
105:     
106:     
107:     
108:     /**
109:      * @access public
110:      * @ignore
111:      * @return int
112:      */
113:     public function get_vrid()
114:     {
115:         $vrid = Util::getByPath($this->rawAnnotation, "VRRP.VRID");
116:         if ($vrid == null) {
117:             throw new SaklientException("invalid_data", "Data of the resource is invalid");
118:         }
119:         return intval($vrid);
120:     }
121:     
122:     /**
123:      * @access public
124:      * @ignore
125:      * @param int $v
126:      * @return int
127:      */
128:     public function set_vrid($v)
129:     {
130:         Util::validateArgCount(func_num_args(), 1);
131:         Util::validateType($v, "int");
132:         Util::setByPath($this->rawAnnotation, "VRRP.VRID", $v);
133:         return $v;
134:     }
135:     
136:     
137:     
138:     /**
139:      * @ignore
140:      * @access public
141:      * @param \Saklient\Cloud\Client $client
142:      * @param mixed $obj
143:      * @param boolean $wrapped=false
144:      */
145:     public function __construct(\Saklient\Cloud\Client $client, $obj, $wrapped=false)
146:     {
147:         parent::__construct($client, $obj, $wrapped);
148:         Util::validateArgCount(func_num_args(), 2);
149:         Util::validateType($client, "\\Saklient\\Cloud\\Client");
150:         Util::validateType($wrapped, "boolean");
151:         if ($this->rawAnnotation == null) {
152:             $this->rawAnnotation = (object)[];
153:         }
154:     }
155:     
156:     /**
157:      * @private
158:      * @access protected
159:      * @ignore
160:      * @param mixed $r
161:      * @param mixed $root
162:      * @return void
163:      */
164:     protected function _onAfterApiDeserialize($r, $root)
165:     {
166:         Util::validateArgCount(func_num_args(), 2);
167:         if ($this->rawAnnotation == null) {
168:             $this->rawAnnotation = (object)[];
169:         }
170:         $this->_virtualIps = new \ArrayObject([]);
171:         $settings = $this->rawSettings;
172:         if ($settings != null) {
173:             $lb = $settings->{"LoadBalancer"};
174:             if ($lb == null) {
175:                 $lb = new \ArrayObject([]);
176:             }
177:             $vips = $lb;
178:             foreach ($vips as $vip) {
179:                 $this->_virtualIps->append(new LbVirtualIp($vip));
180:             }
181:         }
182:     }
183:     
184:     /**
185:      * @private
186:      * @access protected
187:      * @ignore
188:      * @param boolean $withClean
189:      * @return void
190:      */
191:     protected function _onBeforeApiSerialize($withClean)
192:     {
193:         Util::validateArgCount(func_num_args(), 1);
194:         Util::validateType($withClean, "boolean");
195:         $lb = new \ArrayObject([]);
196:         foreach ($this->_virtualIps as $vip) {
197:             $lb->append($vip->toRawSettings());
198:         }
199:         if ($this->rawSettings == null) {
200:             $this->rawSettings = (object)[];
201:         }
202:         $this->rawSettings->{"LoadBalancer"} = $lb;
203:         if ($this->isNew) {
204:             $this->clazz = EApplianceClass::loadbalancer;
205:         }
206:     }
207:     
208:     /**
209:      * @ignore
210:      * @access public
211:      * @param \Saklient\Cloud\Resources\Swytch $swytch
212:      * @param int $vrid
213:      * @param string[] $realIps
214:      * @param boolean $isHighSpec=false
215:      * @return \Saklient\Cloud\Resources\LoadBalancer
216:      */
217:     public function setInitialParams(\Saklient\Cloud\Resources\Swytch $swytch, $vrid, $realIps, $isHighSpec=false)
218:     {
219:         Util::validateArgCount(func_num_args(), 3);
220:         Util::validateType($swytch, "\\Saklient\\Cloud\\Resources\\Swytch");
221:         Util::validateType($vrid, "int");
222:         Util::validateType($realIps, "\\ArrayObject");
223:         Util::validateType($isHighSpec, "boolean");
224:         $annot = $this->rawAnnotation;
225:         $this->vrid = $vrid;
226:         Util::setByPath($annot, "Switch.ID", $swytch->_id());
227:         if ($swytch->ipv4Nets != null && 0 < $swytch->ipv4Nets->count()) {
228:             $net = $swytch->ipv4Nets[0];
229:             $this->defaultRoute = $net->defaultRoute;
230:             $this->maskLen = $net->maskLen;
231:         }
232:         else {
233:             $this->defaultRoute = $swytch->userDefaultRoute;
234:             $this->maskLen = $swytch->userMaskLen;
235:         }
236:         $servers = new \ArrayObject([]);
237:         foreach ($realIps as $ip) {
238:             $servers->append((object)['IPAddress' => $ip]);
239:         }
240:         Util::setByPath($annot, "Servers", $servers);
241:         $this->planId = $isHighSpec ? 2 : 1;
242:         return $this;
243:     }
244:     
245:     /**
246:      * @access public
247:      * @return \Saklient\Cloud\Resources\LoadBalancer
248:      */
249:     public function clearVirtualIps()
250:     {
251:         while (0 < $this->_virtualIps->count()) {
252:             Util::popAobj($this->_virtualIps);
253:         }
254:         return $this;
255:     }
256:     
257:     /**
258:      * 仮想IPアドレス設定を追加します。
259:      * 
260:      * @access public
261:      * @param mixed $settings=null 設定オブジェクト
262:      * @return \Saklient\Cloud\Resources\LbVirtualIp
263:      */
264:     public function addVirtualIp($settings=null)
265:     {
266:         $ret = new LbVirtualIp($settings);
267:         $this->_virtualIps->append($ret);
268:         return $ret;
269:     }
270:     
271:     /**
272:      * 指定したIPアドレスにマッチする仮想IPアドレス設定を取得します。
273:      * 
274:      * @access public
275:      * @param string $address
276:      * @return \Saklient\Cloud\Resources\LbVirtualIp
277:      */
278:     public function getVirtualIpByAddress($address)
279:     {
280:         Util::validateArgCount(func_num_args(), 1);
281:         Util::validateType($address, "string");
282:         foreach ($this->_virtualIps as $vip) {
283:             if ($vip->virtualIpAddress == $address) {
284:                 return $vip;
285:             }
286:         }
287:         return null;
288:     }
289:     
290:     /**
291:      * 監視対象サーバのステータスを最新の状態に更新します。
292:      * 
293:      * @access public
294:      * @return \Saklient\Cloud\Resources\LoadBalancer
295:      */
296:     public function reloadStatus()
297:     {
298:         $result = $this->requestRetry("GET", $this->_apiPath() . "/" . Util::urlEncode($this->_id()) . "/status");
299:         if ($result != null && array_key_exists("LoadBalancer", (array)($result))) {
300:             $vips = $result->{"LoadBalancer"};
301:             foreach ($vips as $vipDyn) {
302:                 $vipStr = $vipDyn->{"VirtualIPAddress"};
303:                 $vip = $this->getVirtualIpByAddress($vipStr);
304:                 if ($vip == null) {
305:                     continue;
306:                 }
307:                 $vip->updateStatus($vipDyn->{"Servers"});
308:             }
309:         }
310:         return $this;
311:     }
312:     
313:     /**
314:      * @ignore
315:      */
316:     public function __get($key) {
317:         switch ($key) {
318:             case "virtualIps": return $this->get_virtualIps();
319:             case "defaultRoute": return $this->get_defaultRoute();
320:             case "maskLen": return $this->get_maskLen();
321:             case "vrid": return $this->get_vrid();
322:             default: return parent::__get($key);
323:         }
324:     }
325:     
326:     /**
327:      * @ignore
328:      */
329:     public function __set($key, $v) {
330:         switch ($key) {
331:             case "defaultRoute": return $this->set_defaultRoute($v);
332:             case "maskLen": return $this->set_maskLen($v);
333:             case "vrid": return $this->set_vrid($v);
334:             default: return parent::__set($key, $v);
335:         }
336:     }
337: 
338: }
339: 
340: 
API documentation generated by ApiGen 2.8.0