diff -r 5b37998e522e -r 162c1de6545a web/lib/Zend/Service/Amazon/Ec2/Elasticip.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/lib/Zend/Service/Amazon/Ec2/Elasticip.php Fri Mar 11 15:05:35 2011 +0100 @@ -0,0 +1,158 @@ +sendRequest($params); + + $xpath = $response->getXPath(); + $ip = $xpath->evaluate('string(//ec2:publicIp/text())'); + + return $ip; + } + + /** + * Lists elastic IP addresses assigned to your account. + * + * @param string|array $publicIp Elastic IP or list of addresses to describe. + * @return array + */ + public function describe($publicIp = null) + { + $params = array(); + $params['Action'] = 'DescribeAddresses'; + + if(is_array($publicIp) && !empty($publicIp)) { + foreach($publicIp as $k=>$name) { + $params['PublicIp.' . ($k+1)] = $name; + } + } elseif($publicIp) { + $params['PublicIp.1'] = $publicIp; + } + + $response = $this->sendRequest($params); + + $xpath = $response->getXPath(); + $nodes = $xpath->query('//ec2:item'); + + $return = array(); + foreach ($nodes as $k => $node) { + $item = array(); + $item['publicIp'] = $xpath->evaluate('string(ec2:publicIp/text())', $node); + $item['instanceId'] = $xpath->evaluate('string(ec2:instanceId/text())', $node); + + $return[] = $item; + unset($item); + } + + return $return; + } + + /** + * Releases an elastic IP address that is associated with your account + * + * @param string $publicIp IP address that you are releasing from your account. + * @return boolean + */ + public function release($publicIp) + { + $params = array(); + $params['Action'] = 'ReleaseAddress'; + $params['PublicIp'] = $publicIp; + + $response = $this->sendRequest($params); + $xpath = $response->getXPath(); + + $return = $xpath->evaluate('string(//ec2:return/text())'); + + return ($return === "true"); + } + + /** + * Associates an elastic IP address with an instance + * + * @param string $instanceId The instance to which the IP address is assigned + * @param string $publicIp IP address that you are assigning to the instance. + * @return boolean + */ + public function associate($instanceId, $publicIp) + { + $params = array(); + $params['Action'] = 'AssociateAddress'; + $params['PublicIp'] = $publicIp; + $params['InstanceId'] = $instanceId; + + $response = $this->sendRequest($params); + $xpath = $response->getXPath(); + + $return = $xpath->evaluate('string(//ec2:return/text())'); + + return ($return === "true"); + } + + /** + * Disassociates the specified elastic IP address from the instance to which it is assigned. + * This is an idempotent operation. If you enter it more than once, Amazon EC2 does not return an error. + * + * @param string $publicIp IP address that you are disassociating from the instance. + * @return boolean + */ + public function disassocate($publicIp) + { + $params = array(); + $params['Action'] = 'DisssociateAddress'; + $params['PublicIp'] = $publicIp; + + $response = $this->sendRequest($params); + $xpath = $response->getXPath(); + + $return = $xpath->evaluate('string(//ec2:return/text())'); + + return ($return === "true"); + } + +}