File indexing completed on 2025-03-02 05:29:46
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Service_Amazon 0017 * @subpackage Ec2 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 /** 0024 * @see Zend_Service_Amazon_Ec2_Abstract 0025 */ 0026 // require_once 'Zend/Service/Amazon/Ec2/Abstract.php'; 0027 0028 /** 0029 * An Amazon EC2 interface to allocate, associate, describe and release Elastic IP address 0030 * from your account. 0031 * 0032 * @category Zend 0033 * @package Zend_Service_Amazon 0034 * @subpackage Ec2 0035 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0036 * @license http://framework.zend.com/license/new-bsd New BSD License 0037 */ 0038 class Zend_Service_Amazon_Ec2_Elasticip extends Zend_Service_Amazon_Ec2_Abstract 0039 { 0040 /** 0041 * Acquires an elastic IP address for use with your account 0042 * 0043 * @return string Returns the newly Allocated IP Address 0044 */ 0045 public function allocate() 0046 { 0047 $params = array(); 0048 $params['Action'] = 'AllocateAddress'; 0049 0050 $response = $this->sendRequest($params); 0051 0052 $xpath = $response->getXPath(); 0053 $ip = $xpath->evaluate('string(//ec2:publicIp/text())'); 0054 0055 return $ip; 0056 } 0057 0058 /** 0059 * Lists elastic IP addresses assigned to your account. 0060 * 0061 * @param string|array $publicIp Elastic IP or list of addresses to describe. 0062 * @return array 0063 */ 0064 public function describe($publicIp = null) 0065 { 0066 $params = array(); 0067 $params['Action'] = 'DescribeAddresses'; 0068 0069 if(is_array($publicIp) && !empty($publicIp)) { 0070 foreach($publicIp as $k=>$name) { 0071 $params['PublicIp.' . ($k+1)] = $name; 0072 } 0073 } elseif($publicIp) { 0074 $params['PublicIp.1'] = $publicIp; 0075 } 0076 0077 $response = $this->sendRequest($params); 0078 0079 $xpath = $response->getXPath(); 0080 $nodes = $xpath->query('//ec2:item'); 0081 0082 $return = array(); 0083 foreach ($nodes as $k => $node) { 0084 $item = array(); 0085 $item['publicIp'] = $xpath->evaluate('string(ec2:publicIp/text())', $node); 0086 $item['instanceId'] = $xpath->evaluate('string(ec2:instanceId/text())', $node); 0087 0088 $return[] = $item; 0089 unset($item); 0090 } 0091 0092 return $return; 0093 } 0094 0095 /** 0096 * Releases an elastic IP address that is associated with your account 0097 * 0098 * @param string $publicIp IP address that you are releasing from your account. 0099 * @return boolean 0100 */ 0101 public function release($publicIp) 0102 { 0103 $params = array(); 0104 $params['Action'] = 'ReleaseAddress'; 0105 $params['PublicIp'] = $publicIp; 0106 0107 $response = $this->sendRequest($params); 0108 $xpath = $response->getXPath(); 0109 0110 $return = $xpath->evaluate('string(//ec2:return/text())'); 0111 0112 return ($return === "true"); 0113 } 0114 0115 /** 0116 * Associates an elastic IP address with an instance 0117 * 0118 * @param string $instanceId The instance to which the IP address is assigned 0119 * @param string $publicIp IP address that you are assigning to the instance. 0120 * @return boolean 0121 */ 0122 public function associate($instanceId, $publicIp) 0123 { 0124 $params = array(); 0125 $params['Action'] = 'AssociateAddress'; 0126 $params['PublicIp'] = $publicIp; 0127 $params['InstanceId'] = $instanceId; 0128 0129 $response = $this->sendRequest($params); 0130 $xpath = $response->getXPath(); 0131 0132 $return = $xpath->evaluate('string(//ec2:return/text())'); 0133 0134 return ($return === "true"); 0135 } 0136 0137 /** 0138 * Disassociates the specified elastic IP address from the instance to which it is assigned. 0139 * This is an idempotent operation. If you enter it more than once, Amazon EC2 does not return an error. 0140 * 0141 * @param string $publicIp IP address that you are disassociating from the instance. 0142 * @return boolean 0143 */ 0144 public function disassocate($publicIp) 0145 { 0146 $params = array(); 0147 $params['Action'] = 'DisssociateAddress'; 0148 $params['PublicIp'] = $publicIp; 0149 0150 $response = $this->sendRequest($params); 0151 $xpath = $response->getXPath(); 0152 0153 $return = $xpath->evaluate('string(//ec2:return/text())'); 0154 0155 return ($return === "true"); 0156 } 0157 0158 }