7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
16 * @package Zend_Service_Amazon
18 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
20 * @version $Id: Elasticip.php 16971 2009-07-22 18:05:45Z mikaelkael $
23 require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
26 * An Amazon EC2 interface to allocate, associate, describe and release Elastic IP address
30 * @package Zend_Service_Amazon
32 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
33 * @license http://framework.zend.com/license/new-bsd New BSD License
35 class Zend_Service_Amazon_Ec2_Elasticip
extends Zend_Service_Amazon_Ec2_Abstract
38 * Acquires an elastic IP address for use with your account
40 * @return string Returns the newly Allocated IP Address
42 public function allocate()
45 $params['Action'] = 'AllocateAddress';
47 $response = $this->sendRequest($params);
49 $xpath = $response->getXPath();
50 $ip = $xpath->evaluate('string(//ec2:publicIp/text())');
56 * Lists elastic IP addresses assigned to your account.
58 * @param string|array $publicIp Elastic IP or list of addresses to describe.
61 public function describe($publicIp = null)
64 $params['Action'] = 'DescribeAddresses';
66 if(is_array($publicIp) && !empty($publicIp)) {
67 foreach($publicIp as $k=>$name) {
68 $params['PublicIp.' . ($k+
1)] = $name;
71 $params['PublicIp.1'] = $publicIp;
74 $response = $this->sendRequest($params);
76 $xpath = $response->getXPath();
77 $nodes = $xpath->query('//ec2:item');
80 foreach ($nodes as $k => $node) {
82 $item['publicIp'] = $xpath->evaluate('string(ec2:publicIp/text())', $node);
83 $item['instanceId'] = $xpath->evaluate('string(ec2:instanceId/text())', $node);
93 * Releases an elastic IP address that is associated with your account
95 * @param string $publicIp IP address that you are releasing from your account.
98 public function release($publicIp)
101 $params['Action'] = 'ReleaseAddress';
102 $params['PublicIp'] = $publicIp;
104 $response = $this->sendRequest($params);
105 $xpath = $response->getXPath();
107 $return = $xpath->evaluate('string(//ec2:return/text())');
109 return ($return === "true");
113 * Associates an elastic IP address with an instance
115 * @param string $instanceId The instance to which the IP address is assigned
116 * @param string $publicIp IP address that you are assigning to the instance.
119 public function associate($instanceId, $publicIp)
122 $params['Action'] = 'AssociateAddress';
123 $params['PublicIp'] = $publicIp;
124 $params['InstanceId'] = $instanceId;
126 $response = $this->sendRequest($params);
127 $xpath = $response->getXPath();
129 $return = $xpath->evaluate('string(//ec2:return/text())');
131 return ($return === "true");
135 * Disassociates the specified elastic IP address from the instance to which it is assigned.
136 * This is an idempotent operation. If you enter it more than once, Amazon EC2 does not return an error.
138 * @param string $publicIp IP address that you are disassociating from the instance.
141 public function disassocate($publicIp)
144 $params['Action'] = 'DisssociateAddress';
145 $params['PublicIp'] = $publicIp;
147 $response = $this->sendRequest($params);
148 $xpath = $response->getXPath();
150 $return = $xpath->evaluate('string(//ec2:return/text())');
152 return ($return === "true");