*prechod na novsiu verziu ZF
[sport-group.git] / library / Zend / Service / Amazon / Ec2 / Elasticip.php
blob31ed64e50f464bcaad86283db56de7be85a768a7
1 <?php
2 /**
3 * Zend Framework
5 * LICENSE
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.
15 * @category Zend
16 * @package Zend_Service_Amazon
17 * @subpackage Ec2
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';
25 /**
26 * An Amazon EC2 interface to allocate, associate, describe and release Elastic IP address
27 * from your account.
29 * @category Zend
30 * @package Zend_Service_Amazon
31 * @subpackage Ec2
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
37 /**
38 * Acquires an elastic IP address for use with your account
40 * @return string Returns the newly Allocated IP Address
42 public function allocate()
44 $params = array();
45 $params['Action'] = 'AllocateAddress';
47 $response = $this->sendRequest($params);
49 $xpath = $response->getXPath();
50 $ip = $xpath->evaluate('string(//ec2:publicIp/text())');
52 return $ip;
55 /**
56 * Lists elastic IP addresses assigned to your account.
58 * @param string|array $publicIp Elastic IP or list of addresses to describe.
59 * @return array
61 public function describe($publicIp = null)
63 $params = array();
64 $params['Action'] = 'DescribeAddresses';
66 if(is_array($publicIp) && !empty($publicIp)) {
67 foreach($publicIp as $k=>$name) {
68 $params['PublicIp.' . ($k+1)] = $name;
70 } elseif($publicIp) {
71 $params['PublicIp.1'] = $publicIp;
74 $response = $this->sendRequest($params);
76 $xpath = $response->getXPath();
77 $nodes = $xpath->query('//ec2:item');
79 $return = array();
80 foreach ($nodes as $k => $node) {
81 $item = array();
82 $item['publicIp'] = $xpath->evaluate('string(ec2:publicIp/text())', $node);
83 $item['instanceId'] = $xpath->evaluate('string(ec2:instanceId/text())', $node);
85 $return[] = $item;
86 unset($item);
89 return $return;
92 /**
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.
96 * @return boolean
98 public function release($publicIp)
100 $params = array();
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.
117 * @return boolean
119 public function associate($instanceId, $publicIp)
121 $params = array();
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.
139 * @return boolean
141 public function disassocate($publicIp)
143 $params = array();
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");