CC-2166: Packaging Improvements. Moved the Zend app into airtime_mvc. It is now installed to /var/www/airtime. Storage is now set to /srv/airtime/stor. Utils are now installed to /usr/lib/airtime/utils/. Added install/airtime-dircheck.php as a simple test to see if everything is install/uninstalled correctly.
This commit is contained in:
parent
514777e8d2
commit
b11cbd8159
4546 changed files with 138 additions and 51 deletions
277
airtime_mvc/library/Zend/Service/Amazon/Ec2/Abstract.php
Normal file
277
airtime_mvc/library/Zend/Service/Amazon/Ec2/Abstract.php
Normal file
|
@ -0,0 +1,277 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Service_Amazon_Abstract
|
||||
*/
|
||||
require_once 'Zend/Service/Amazon/Abstract.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Service_Amazon_Ec2_Response
|
||||
*/
|
||||
require_once 'Zend/Service/Amazon/Ec2/Response.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Service_Amazon_Ec2_Exception
|
||||
*/
|
||||
require_once 'Zend/Service/Amazon/Ec2/Exception.php';
|
||||
|
||||
/**
|
||||
* Provides the basic functionality to send a request to the Amazon Ec2 Query API
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Service_Amazon_Ec2_Abstract extends Zend_Service_Amazon_Abstract
|
||||
{
|
||||
/**
|
||||
* The HTTP query server
|
||||
*/
|
||||
protected $_ec2Endpoint = 'ec2.amazonaws.com';
|
||||
|
||||
/**
|
||||
* The API version to use
|
||||
*/
|
||||
protected $_ec2ApiVersion = '2009-04-04';
|
||||
|
||||
/**
|
||||
* Signature Version
|
||||
*/
|
||||
protected $_ec2SignatureVersion = '2';
|
||||
|
||||
/**
|
||||
* Signature Encoding Method
|
||||
*/
|
||||
protected $_ec2SignatureMethod = 'HmacSHA256';
|
||||
|
||||
/**
|
||||
* Period after which HTTP request will timeout in seconds
|
||||
*/
|
||||
protected $_httpTimeout = 10;
|
||||
|
||||
/**
|
||||
* @var string Amazon Region
|
||||
*/
|
||||
protected static $_defaultRegion = null;
|
||||
|
||||
/**
|
||||
* @var string Amazon Region
|
||||
*/
|
||||
protected $_region;
|
||||
|
||||
/**
|
||||
* An array that contains all the valid Amazon Ec2 Regions.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $_validEc2Regions = array('eu-west-1', 'us-east-1');
|
||||
|
||||
/**
|
||||
* Create Amazon client.
|
||||
*
|
||||
* @param string $access_key Override the default Access Key
|
||||
* @param string $secret_key Override the default Secret Key
|
||||
* @param string $region Sets the AWS Region
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($accessKey=null, $secretKey=null, $region=null)
|
||||
{
|
||||
if(!$region) {
|
||||
$region = self::$_defaultRegion;
|
||||
} else {
|
||||
// make rue the region is valid
|
||||
if(!empty($region) && !in_array(strtolower($region), self::$_validEc2Regions, true)) {
|
||||
require_once 'Zend/Service/Amazon/Exception.php';
|
||||
throw new Zend_Service_Amazon_Exception('Invalid Amazon Ec2 Region');
|
||||
}
|
||||
}
|
||||
|
||||
$this->_region = $region;
|
||||
|
||||
parent::__construct($accessKey, $secretKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set which region you are working in. It will append the
|
||||
* end point automaticly
|
||||
*
|
||||
* @param string $region
|
||||
*/
|
||||
public static function setRegion($region)
|
||||
{
|
||||
if(in_array(strtolower($region), self::$_validEc2Regions, true)) {
|
||||
self::$_defaultRegion = $region;
|
||||
} else {
|
||||
require_once 'Zend/Service/Amazon/Exception.php';
|
||||
throw new Zend_Service_Amazon_Exception('Invalid Amazon Ec2 Region');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to fetch the AWS Region
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _getRegion()
|
||||
{
|
||||
return (!empty($this->_region)) ? $this->_region . '.' : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a HTTP request to the queue service using Zend_Http_Client
|
||||
*
|
||||
* @param array $params List of parameters to send with the request
|
||||
* @return Zend_Service_Amazon_Ec2_Response
|
||||
* @throws Zend_Service_Amazon_Ec2_Exception
|
||||
*/
|
||||
protected function sendRequest(array $params = array())
|
||||
{
|
||||
$url = 'https://' . $this->_getRegion() . $this->_ec2Endpoint . '/';
|
||||
|
||||
$params = $this->addRequiredParameters($params);
|
||||
|
||||
try {
|
||||
/* @var $request Zend_Http_Client */
|
||||
$request = self::getHttpClient();
|
||||
$request->resetParameters();
|
||||
|
||||
$request->setConfig(array(
|
||||
'timeout' => $this->_httpTimeout
|
||||
));
|
||||
|
||||
$request->setUri($url);
|
||||
$request->setMethod(Zend_Http_Client::POST);
|
||||
$request->setParameterPost($params);
|
||||
|
||||
$httpResponse = $request->request();
|
||||
|
||||
|
||||
} catch (Zend_Http_Client_Exception $zhce) {
|
||||
$message = 'Error in request to AWS service: ' . $zhce->getMessage();
|
||||
throw new Zend_Service_Amazon_Ec2_Exception($message, $zhce->getCode(), $zhce);
|
||||
}
|
||||
$response = new Zend_Service_Amazon_Ec2_Response($httpResponse);
|
||||
$this->checkForErrors($response);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds required authentication and version parameters to an array of
|
||||
* parameters
|
||||
*
|
||||
* The required parameters are:
|
||||
* - AWSAccessKey
|
||||
* - SignatureVersion
|
||||
* - Timestamp
|
||||
* - Version and
|
||||
* - Signature
|
||||
*
|
||||
* If a required parameter is already set in the <tt>$parameters</tt> array,
|
||||
* it is overwritten.
|
||||
*
|
||||
* @param array $parameters the array to which to add the required
|
||||
* parameters.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function addRequiredParameters(array $parameters)
|
||||
{
|
||||
$parameters['AWSAccessKeyId'] = $this->_getAccessKey();
|
||||
$parameters['SignatureVersion'] = $this->_ec2SignatureVersion;
|
||||
$parameters['Timestamp'] = gmdate('Y-m-d\TH:i:s\Z');
|
||||
$parameters['Version'] = $this->_ec2ApiVersion;
|
||||
$parameters['SignatureMethod'] = $this->_ec2SignatureMethod;
|
||||
$parameters['Signature'] = $this->signParameters($parameters);
|
||||
|
||||
return $parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the RFC 2104-compliant HMAC signature for request parameters
|
||||
*
|
||||
* This implements the Amazon Web Services signature, as per the following
|
||||
* specification:
|
||||
*
|
||||
* 1. Sort all request parameters (including <tt>SignatureVersion</tt> and
|
||||
* excluding <tt>Signature</tt>, the value of which is being created),
|
||||
* ignoring case.
|
||||
*
|
||||
* 2. Iterate over the sorted list and append the parameter name (in its
|
||||
* original case) and then its value. Do not URL-encode the parameter
|
||||
* values before constructing this string. Do not use any separator
|
||||
* characters when appending strings.
|
||||
*
|
||||
* @param array $parameters the parameters for which to get the signature.
|
||||
* @param string $secretKey the secret key to use to sign the parameters.
|
||||
*
|
||||
* @return string the signed data.
|
||||
*/
|
||||
protected function signParameters(array $paramaters)
|
||||
{
|
||||
$data = "POST\n";
|
||||
$data .= $this->_getRegion() . $this->_ec2Endpoint . "\n";
|
||||
$data .= "/\n";
|
||||
|
||||
uksort($paramaters, 'strcmp');
|
||||
unset($paramaters['Signature']);
|
||||
|
||||
$arrData = array();
|
||||
foreach($paramaters as $key => $value) {
|
||||
$arrData[] = $key . '=' . str_replace("%7E", "~", rawurlencode($value));
|
||||
}
|
||||
|
||||
$data .= implode('&', $arrData);
|
||||
|
||||
require_once 'Zend/Crypt/Hmac.php';
|
||||
$hmac = Zend_Crypt_Hmac::compute($this->_getSecretKey(), 'SHA256', $data, Zend_Crypt_Hmac::BINARY);
|
||||
|
||||
return base64_encode($hmac);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for errors responses from Amazon
|
||||
*
|
||||
* @param Zend_Service_Amazon_Ec2_Response $response the response object to
|
||||
* check.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws Zend_Service_Amazon_Ec2_Exception if one or more errors are
|
||||
* returned from Amazon.
|
||||
*/
|
||||
private function checkForErrors(Zend_Service_Amazon_Ec2_Response $response)
|
||||
{
|
||||
$xpath = new DOMXPath($response->getDocument());
|
||||
$list = $xpath->query('//Error');
|
||||
if ($list->length > 0) {
|
||||
$node = $list->item(0);
|
||||
$code = $xpath->evaluate('string(Code/text())', $node);
|
||||
$message = $xpath->evaluate('string(Message/text())', $node);
|
||||
throw new Zend_Service_Amazon_Ec2_Exception($message, 0, $code);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Availabilityzones.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Service_Amazon_Ec2_Abstract
|
||||
*/
|
||||
require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
|
||||
|
||||
/**
|
||||
* An Amazon EC2 interface to query which Availibity Zones your account has access to.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Ec2_Availabilityzones extends Zend_Service_Amazon_Ec2_Abstract
|
||||
{
|
||||
/**
|
||||
* Describes availability zones that are currently available to the account
|
||||
* and their states.
|
||||
*
|
||||
* @param string|array $zoneName Name of an availability zone.
|
||||
* @return array An array that contains all the return items. Keys: zoneName and zoneState.
|
||||
*/
|
||||
public function describe($zoneName = null)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'DescribeAvailabilityZones';
|
||||
|
||||
if(is_array($zoneName) && !empty($zoneName)) {
|
||||
foreach($zoneName as $k=>$name) {
|
||||
$params['ZoneName.' . ($k+1)] = $name;
|
||||
}
|
||||
} elseif($zoneName) {
|
||||
$params['ZoneName.1'] = $zoneName;
|
||||
}
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
$nodes = $xpath->query('//ec2:item');
|
||||
|
||||
$return = array();
|
||||
foreach ($nodes as $k => $node) {
|
||||
$item = array();
|
||||
$item['zoneName'] = $xpath->evaluate('string(ec2:zoneName/text())', $node);
|
||||
$item['zoneState'] = $xpath->evaluate('string(ec2:zoneState/text())', $node);
|
||||
|
||||
$return[] = $item;
|
||||
unset($item);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
357
airtime_mvc/library/Zend/Service/Amazon/Ec2/CloudWatch.php
Normal file
357
airtime_mvc/library/Zend/Service/Amazon/Ec2/CloudWatch.php
Normal file
|
@ -0,0 +1,357 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: CloudWatch.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Service_Amazon_Ec2_Abstract
|
||||
*/
|
||||
require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
|
||||
|
||||
/**
|
||||
* An Amazon EC2 interface that allows yout to run, terminate, reboot and describe Amazon
|
||||
* Ec2 Instances.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Ec2_CloudWatch extends Zend_Service_Amazon_Ec2_Abstract
|
||||
{
|
||||
/**
|
||||
* The HTTP query server
|
||||
*/
|
||||
protected $_ec2Endpoint = 'monitoring.amazonaws.com';
|
||||
|
||||
/**
|
||||
* The API version to use
|
||||
*/
|
||||
protected $_ec2ApiVersion = '2009-05-15';
|
||||
|
||||
/**
|
||||
* XML Namespace for the CloudWatch Stuff
|
||||
*/
|
||||
protected $_xmlNamespace = 'http://monitoring.amazonaws.com/doc/2009-05-15/';
|
||||
|
||||
/**
|
||||
* The following metrics are available from each EC2 instance.
|
||||
*
|
||||
* CPUUtilization: The percentage of allocated EC2 compute units that are
|
||||
* currently in use on the instance. This metric identifies the processing
|
||||
* power required to run an application upon a selected instance.
|
||||
*
|
||||
* NetworkIn: The number of bytes received on all network interfaces by
|
||||
* the instance. This metric identifies the volume of incoming network
|
||||
* traffic to an application on a single instance.
|
||||
*
|
||||
* NetworkOut: The number of bytes sent out on all network interfaces
|
||||
* by the instance. This metric identifies the volume of outgoing network
|
||||
* traffic to an application on a single instance.
|
||||
*
|
||||
* DiskWriteOps: Completed write operations to all hard disks available to
|
||||
* the instance. This metric identifies the rate at which an application
|
||||
* writes to a hard disk. This can be used to determine the speed in which
|
||||
* an application saves data to a hard disk.
|
||||
*
|
||||
* DiskReadBytes: Bytes read from all disks available to the instance. This
|
||||
* metric is used to determine the volume of the data the application reads
|
||||
* from the hard disk of the instance. This can be used to determine the
|
||||
* speed of the application for the customer.
|
||||
*
|
||||
* DiskReadOps: Completed read operations from all disks available to the
|
||||
* instances. This metric identifies the rate at which an application reads
|
||||
* a disk. This can be used to determine the speed in which an application
|
||||
* reads data from a hard disk.
|
||||
*
|
||||
* DiskWriteBytes: Bytes written to all disks available to the instance. This
|
||||
* metric is used to determine the volume of the data the application writes
|
||||
* onto the hard disk of the instance. This can be used to determine the speed
|
||||
* of the application for the customer.
|
||||
*
|
||||
* Latency: Time taken between a request and the corresponding response as seen
|
||||
* by the load balancer.
|
||||
*
|
||||
* RequestCount: The number of requests processed by the LoadBalancer.
|
||||
*
|
||||
* HealthyHostCount: The number of healthy instances. Both Load Balancing dimensions,
|
||||
* LoadBalancerName and AvailabilityZone, should be specified when retreiving
|
||||
* HealthyHostCount.
|
||||
*
|
||||
* UnHealthyHostCount: The number of unhealthy instances. Both Load Balancing dimensions,
|
||||
* LoadBalancerName and AvailabilityZone, should be specified when retreiving
|
||||
* UnHealthyHostCount.
|
||||
*
|
||||
* Amazon CloudWatch data for a new EC2 instance becomes available typically
|
||||
* within one minute of the end of the first aggregation period for the new
|
||||
* instance. You can use the currently available dimensions for EC2 instances
|
||||
* along with these metrics in order to refine the slice of data you want returned,
|
||||
* such as metric CPUUtilization and dimension ImageId to get all CPUUtilization
|
||||
* data for instances using the specified AMI.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_validMetrics = array('CPUUtilization', 'NetworkIn', 'NetworkOut',
|
||||
'DiskWriteOps', 'DiskReadBytes', 'DiskReadOps',
|
||||
'DiskWriteBytes', 'Latency', 'RequestCount',
|
||||
'HealthyHostCount', 'UnHealthyHostCount');
|
||||
|
||||
/**
|
||||
* Amazon CloudWatch not only aggregates the raw data coming in, it also computes
|
||||
* several statistics on the data. The following table lists the statistics that you can request:
|
||||
*
|
||||
* Minimum: The lowest value observed during the specified period. This can be used to
|
||||
* determine low volumes of activity for your application.
|
||||
*
|
||||
* Maximum: The highest value observed during the specified period. You can use this to
|
||||
* determine high volumes of activity for your application.
|
||||
*
|
||||
* Sum: The sum of all values received (if appropriate, for example a rate would not be
|
||||
* summed, but a number of items would be). This statistic is useful for determining
|
||||
* the total volume of a metric.
|
||||
*
|
||||
* Average: The Average of all values received during the specified period. By comparing
|
||||
* this statistic with the minimum and maximum statistics, you can determine the full
|
||||
* scope of a metric and how close the average use is to the minimum and the maximum.
|
||||
* This will allow you to increase or decrease your resources as needed.
|
||||
*
|
||||
* Samples: The count (number) of measures used. This statistic is always returned to
|
||||
* show the user the size of the dataset collected. This will allow the user to properly
|
||||
* weight the data.
|
||||
*
|
||||
* Statistics are computed within a period you specify, such as all CPUUtilization within a
|
||||
* five minute period. At a minimum, all data is aggregated into one minute intervals. This
|
||||
* is the minimum resolution of the data. It is this data that can be aggregated into larger
|
||||
* periods of time that you request.
|
||||
*
|
||||
* Aggregate data is generally available from the service within one minute from the end of the
|
||||
* aggregation period. Delays in data propagation might cause late or partially late data in
|
||||
* some cases. If your data is delayed, you should check the service’s Health Dashboard for
|
||||
* any current operational issues with either Amazon CloudWatch or the services collecting
|
||||
* the data, such as EC2 or Elastic Load Balancing.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_validStatistics = array('Average', 'Maximum', 'Minimum', 'Samples', 'Sum');
|
||||
|
||||
/**
|
||||
* Valid Dimention Keys for getMetricStatistics
|
||||
*
|
||||
* ImageId: This dimension filters the data you request for all instances running
|
||||
* this EC2 Amazon Machine Image (AMI).
|
||||
*
|
||||
* AvailabilityZone: This dimension filters the data you request for all instances
|
||||
* running in that EC2 Availability Zone.
|
||||
*
|
||||
* AutoScalingGroupName: This dimension filters the data you request for all instances
|
||||
* in a specified capacity group. An AutoScalingGroup is a collection of instances
|
||||
* defined by customers of the Auto Scaling service. This dimension is only available
|
||||
* for EC2 metrics when the instances are in such an AutoScalingGroup.
|
||||
*
|
||||
* InstanceId: This dimension filters the data you request for only the identified
|
||||
* instance. This allows a user to pinpoint an exact instance from which to monitor data.
|
||||
*
|
||||
* InstanceType: This dimension filters the data you request for all instances running
|
||||
* with this specified instance type. This allows a user to catagorize his data by the
|
||||
* type of instance running. For example, a user might compare data from an m1.small instance
|
||||
* and an m1.large instance to determine which has the better business value for his application.
|
||||
*
|
||||
* LoadBalancerName: This dimension filters the data you request for the specified LoadBalancer
|
||||
* name. A LoadBalancer is represented by a DNS name and provides the single destination to
|
||||
* which all requests intended for your application should be directed. This metric allows
|
||||
* you to examine data from all instances connected to a single LoadBalancer.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_validDimensionsKeys = array('ImageId', 'AvailabilityZone', 'AutoScalingGroupName',
|
||||
'InstanceId', 'InstanceType', 'LoadBalancerName');
|
||||
|
||||
/**
|
||||
* Returns data for one or more statistics of given a metric
|
||||
*
|
||||
* Note:
|
||||
* The maximum number of datapoints that the Amazon CloudWatch service will
|
||||
* return in a single GetMetricStatistics request is 1,440. If a request is
|
||||
* made that would generate more datapoints than this amount, Amazon CloudWatch
|
||||
* will return an error. You can alter your request by narrowing the time range
|
||||
* (StartTime, EndTime) or increasing the Period in your single request. You may
|
||||
* also get all of the data at the granularity you originally asked for by making
|
||||
* multiple requests with adjacent time ranges.
|
||||
*
|
||||
* @param array $options The options you want to get statistics for:
|
||||
* ** Required **
|
||||
* MeasureName: The measure name that corresponds to
|
||||
* the measure for the gathered metric. Valid EC2 Values are
|
||||
* CPUUtilization, NetworkIn, NetworkOut, DiskWriteOps
|
||||
* DiskReadBytes, DiskReadOps, DiskWriteBytes. Valid Elastic
|
||||
* Load Balancing Metrics are Latency, RequestCount, HealthyHostCount
|
||||
* UnHealthyHostCount
|
||||
* Statistics: The statistics to be returned for the given metric. Valid
|
||||
* values are Average, Maximum, Minimum, Samples, Sum. You can specify
|
||||
* this as a string or as an array of values. If you don't specify one
|
||||
* it will default to Average instead of failing out. If you specify an incorrect
|
||||
* option it will just skip it.
|
||||
* ** Optional **
|
||||
* Dimensions: Amazon CloudWatch allows you to specify one Dimension to further filter
|
||||
* metric data on. If you don't specify a dimension, the service returns the aggregate
|
||||
* of all the measures with the given measure name and time range.
|
||||
* Unit: The standard unit of Measurement for a given Measure. Valid Values: Seconds,
|
||||
* Percent, Bytes, Bits, Count, Bytes/Second, Bits/Second, Count/Second, and None
|
||||
* Constraints: When using count/second as the unit, you should use Sum as the statistic
|
||||
* instead of Average. Otherwise, the sample returns as equal to the number of requests
|
||||
* instead of the number of 60-second intervals. This will cause the Average to
|
||||
* always equals one when the unit is count/second.
|
||||
* StartTime: The timestamp of the first datapoint to return, inclusive. For example,
|
||||
* 2008-02-26T19:00:00+00:00. We round your value down to the nearest minute.
|
||||
* You can set your start time for more than two weeks in the past. However,
|
||||
* you will only get data for the past two weeks. (in ISO 8601 format)
|
||||
* Constraints: Must be before EndTime
|
||||
* EndTime: The timestamp to use for determining the last datapoint to return. This is
|
||||
* the last datapoint to fetch, exclusive. For example, 2008-02-26T20:00:00+00:00.
|
||||
* (in ISO 8601 format)
|
||||
*/
|
||||
public function getMetricStatistics(array $options)
|
||||
{
|
||||
$_usedStatistics = array();
|
||||
|
||||
$params = array();
|
||||
$params['Action'] = 'GetMetricStatistics';
|
||||
|
||||
if (!isset($options['Period'])) {
|
||||
$options['Period'] = 60;
|
||||
}
|
||||
if (!isset($options['Namespace'])) {
|
||||
$options['Namespace'] = 'AWS/EC2';
|
||||
}
|
||||
|
||||
if (!isset($options['MeasureName']) || !in_array($options['MeasureName'], $this->_validMetrics, true)) {
|
||||
throw new Zend_Service_Amazon_Ec2_Exception('Invalid Metric Type: ' . $options['MeasureName']);
|
||||
}
|
||||
|
||||
if(!isset($options['Statistics'])) {
|
||||
$options['Statistics'][] = 'Average';
|
||||
} elseif(!is_array($options['Statistics'])) {
|
||||
$options['Statistics'][] = $options['Statistics'];
|
||||
}
|
||||
|
||||
foreach($options['Statistics'] as $k=>$s) {
|
||||
if(!in_array($s, $this->_validStatistics, true)) continue;
|
||||
$options['Statistics.member.' . ($k+1)] = $s;
|
||||
$_usedStatistics[] = $s;
|
||||
}
|
||||
unset($options['Statistics']);
|
||||
|
||||
if(isset($options['StartTime'])) {
|
||||
if(!is_numeric($options['StartTime'])) $options['StartTime'] = strtotime($options['StartTime']);
|
||||
$options['StartTime'] = gmdate('c', $options['StartTime']);
|
||||
} else {
|
||||
$options['StartTime'] = gmdate('c', strtotime('-1 hour'));
|
||||
}
|
||||
|
||||
if(isset($options['EndTime'])) {
|
||||
if(!is_numeric($options['EndTime'])) $options['EndTime'] = strtotime($options['EndTime']);
|
||||
$options['EndTime'] = gmdate('c', $options['EndTime']);
|
||||
} else {
|
||||
$options['EndTime'] = gmdate('c');
|
||||
}
|
||||
|
||||
if(isset($options['Dimensions'])) {
|
||||
$x = 1;
|
||||
foreach($options['Dimensions'] as $dimKey=>$dimVal) {
|
||||
if(!in_array($dimKey, $this->_validDimensionsKeys, true)) continue;
|
||||
$options['Dimensions.member.' . $x . '.Name'] = $dimKey;
|
||||
$options['Dimensions.member.' . $x . '.Value'] = $dimVal;
|
||||
$x++;
|
||||
}
|
||||
|
||||
unset($options['Dimensions']);
|
||||
}
|
||||
|
||||
$params = array_merge($params, $options);
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$response->setNamespace($this->_xmlNamespace);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
$nodes = $xpath->query('//ec2:GetMetricStatisticsResult/ec2:Datapoints/ec2:member');
|
||||
|
||||
$return = array();
|
||||
$return['label'] = $xpath->evaluate('string(//ec2:GetMetricStatisticsResult/ec2:Label/text())');
|
||||
foreach ( $nodes as $node ) {
|
||||
$item = array();
|
||||
|
||||
$item['Timestamp'] = $xpath->evaluate('string(ec2:Timestamp/text())', $node);
|
||||
$item['Unit'] = $xpath->evaluate('string(ec2:Unit/text())', $node);
|
||||
$item['Samples'] = $xpath->evaluate('string(ec2:Samples/text())', $node);
|
||||
foreach($_usedStatistics as $us) {
|
||||
$item[$us] = $xpath->evaluate('string(ec2:' . $us . '/text())', $node);
|
||||
}
|
||||
|
||||
$return['datapoints'][] = $item;
|
||||
unset($item, $node);
|
||||
}
|
||||
|
||||
return $return;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Metrics that are aviable for your current monitored instances
|
||||
*
|
||||
* @param string $nextToken The NextToken parameter is an optional parameter
|
||||
* that allows you to retrieve the next set of results
|
||||
* for your ListMetrics query.
|
||||
* @return array
|
||||
*/
|
||||
public function listMetrics($nextToken = null)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'ListMetrics';
|
||||
if (!empty($nextToken)) {
|
||||
$params['NextToken'] = $nextToken;
|
||||
}
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$response->setNamespace($this->_xmlNamespace);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
$nodes = $xpath->query('//ec2:ListMetricsResult/ec2:Metrics/ec2:member');
|
||||
|
||||
$return = array();
|
||||
foreach ( $nodes as $node ) {
|
||||
$item = array();
|
||||
|
||||
$item['MeasureName'] = $xpath->evaluate('string(ec2:MeasureName/text())', $node);
|
||||
$item['Namespace'] = $xpath->evaluate('string(ec2:Namespace/text())', $node);
|
||||
$item['Deminsions']['name'] = $xpath->evaluate('string(ec2:Dimensions/ec2:member/ec2:Name/text())', $node);
|
||||
$item['Deminsions']['value'] = $xpath->evaluate('string(ec2:Dimensions/ec2:member/ec2:Value/text())', $node);
|
||||
|
||||
if (empty($item['Deminsions']['name'])) {
|
||||
$item['Deminsions'] = array();
|
||||
}
|
||||
|
||||
$return[] = $item;
|
||||
unset($item, $node);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
342
airtime_mvc/library/Zend/Service/Amazon/Ec2/Ebs.php
Normal file
342
airtime_mvc/library/Zend/Service/Amazon/Ec2/Ebs.php
Normal file
|
@ -0,0 +1,342 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Ebs.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Service_Amazon_Ec2_Abstract
|
||||
*/
|
||||
require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
|
||||
|
||||
/**
|
||||
* An Amazon EC2 interface to create, describe, attach, detach and delete Elastic Block
|
||||
* Storage Volumes and Snaphsots.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Ec2_Ebs extends Zend_Service_Amazon_Ec2_Abstract
|
||||
{
|
||||
/**
|
||||
* Creates a new Amazon EBS volume that you can mount from any Amazon EC2 instance.
|
||||
*
|
||||
* You must specify an availability zone when creating a volume. The volume and
|
||||
* any instance to which it attaches must be in the same availability zone.
|
||||
*
|
||||
* @param string $size The size of the volume, in GiB.
|
||||
* @param string $availabilityZone The availability zone in which to create the new volume.
|
||||
* @return array
|
||||
*/
|
||||
public function createNewVolume($size, $availabilityZone)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'CreateVolume';
|
||||
$params['AvailabilityZone'] = $availabilityZone;
|
||||
$params['Size'] = $size;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$return = array();
|
||||
$return['volumeId'] = $xpath->evaluate('string(//ec2:volumeId/text())');
|
||||
$return['size'] = $xpath->evaluate('string(//ec2:size/text())');
|
||||
$return['status'] = $xpath->evaluate('string(//ec2:status/text())');
|
||||
$return['createTime'] = $xpath->evaluate('string(//ec2:createTime/text())');
|
||||
$return['availabilityZone'] = $xpath->evaluate('string(//ec2:availabilityZone/text())');
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Amazon EBS volume that you can mount from any Amazon EC2 instance.
|
||||
*
|
||||
* You must specify an availability zone when creating a volume. The volume and
|
||||
* any instance to which it attaches must be in the same availability zone.
|
||||
*
|
||||
* @param string $snapshotId The snapshot from which to create the new volume.
|
||||
* @param string $availabilityZone The availability zone in which to create the new volume.
|
||||
* @return array
|
||||
*/
|
||||
public function createVolumeFromSnapshot($snapshotId, $availabilityZone)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'CreateVolume';
|
||||
$params['AvailabilityZone'] = $availabilityZone;
|
||||
$params['SnapshotId'] = $snapshotId;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$return = array();
|
||||
$return['volumeId'] = $xpath->evaluate('string(//ec2:volumeId/text())');
|
||||
$return['size'] = $xpath->evaluate('string(//ec2:size/text())');
|
||||
$return['status'] = $xpath->evaluate('string(//ec2:status/text())');
|
||||
$return['createTime'] = $xpath->evaluate('string(//ec2:createTime/text())');
|
||||
$return['availabilityZone'] = $xpath->evaluate('string(//ec2:availabilityZone/text())');
|
||||
$return['snapshotId'] = $xpath->evaluate('string(//ec2:snapshotId/text())');
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists one or more Amazon EBS volumes that you own, If you do not
|
||||
* specify any volumes, Amazon EBS returns all volumes that you own.
|
||||
*
|
||||
* @param string|array $volumeId The ID or array of ID's of the volume(s) to list
|
||||
* @return array
|
||||
*/
|
||||
public function describeVolume($volumeId = null)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'DescribeVolumes';
|
||||
|
||||
if(is_array($volumeId) && !empty($volumeId)) {
|
||||
foreach($volumeId as $k=>$name) {
|
||||
$params['VolumeId.' . ($k+1)] = $name;
|
||||
}
|
||||
} elseif($volumeId) {
|
||||
$params['VolumeId.1'] = $volumeId;
|
||||
}
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
$nodes = $xpath->query('//ec2:volumeSet/ec2:item', $response->getDocument());
|
||||
|
||||
$return = array();
|
||||
foreach ($nodes as $node) {
|
||||
$item = array();
|
||||
|
||||
$item['volumeId'] = $xpath->evaluate('string(ec2:volumeId/text())', $node);
|
||||
$item['size'] = $xpath->evaluate('string(ec2:size/text())', $node);
|
||||
$item['status'] = $xpath->evaluate('string(ec2:status/text())', $node);
|
||||
$item['createTime'] = $xpath->evaluate('string(ec2:createTime/text())', $node);
|
||||
|
||||
$attachmentSet = $xpath->query('ec2:attachmentSet/ec2:item', $node);
|
||||
if($attachmentSet->length == 1) {
|
||||
$_as = $attachmentSet->item(0);
|
||||
$as = array();
|
||||
$as['volumeId'] = $xpath->evaluate('string(ec2:volumeId/text())', $_as);
|
||||
$as['instanceId'] = $xpath->evaluate('string(ec2:instanceId/text())', $_as);
|
||||
$as['device'] = $xpath->evaluate('string(ec2:device/text())', $_as);
|
||||
$as['status'] = $xpath->evaluate('string(ec2:status/text())', $_as);
|
||||
$as['attachTime'] = $xpath->evaluate('string(ec2:attachTime/text())', $_as);
|
||||
$item['attachmentSet'] = $as;
|
||||
}
|
||||
|
||||
$return[] = $item;
|
||||
unset($item, $node);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function describeAttachedVolumes($instanceId)
|
||||
{
|
||||
$volumes = $this->describeVolume();
|
||||
|
||||
$return = array();
|
||||
foreach($volumes as $vol) {
|
||||
if(isset($vol['attachmentSet']) && $vol['attachmentSet']['instanceId'] == $instanceId) {
|
||||
$return[] = $vol;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attaches an Amazon EBS volume to an instance
|
||||
*
|
||||
* @param string $volumeId The ID of the Amazon EBS volume
|
||||
* @param string $instanceId The ID of the instance to which the volume attaches
|
||||
* @param string $device Specifies how the device is exposed to the instance (e.g., /dev/sdh).
|
||||
* @return array
|
||||
*/
|
||||
public function attachVolume($volumeId, $instanceId, $device)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'AttachVolume';
|
||||
$params['VolumeId'] = $volumeId;
|
||||
$params['InstanceId'] = $instanceId;
|
||||
$params['Device'] = $device;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$return = array();
|
||||
$return['volumeId'] = $xpath->evaluate('string(//ec2:volumeId/text())');
|
||||
$return['instanceId'] = $xpath->evaluate('string(//ec2:instanceId/text())');
|
||||
$return['device'] = $xpath->evaluate('string(//ec2:device/text())');
|
||||
$return['status'] = $xpath->evaluate('string(//ec2:status/text())');
|
||||
$return['attachTime'] = $xpath->evaluate('string(//ec2:attachTime/text())');
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detaches an Amazon EBS volume from an instance
|
||||
*
|
||||
* @param string $volumeId The ID of the Amazon EBS volume
|
||||
* @param string $instanceId The ID of the instance from which the volume will detach
|
||||
* @param string $device The device name
|
||||
* @param boolean $force Forces detachment if the previous detachment attempt did not occur cleanly
|
||||
* (logging into an instance, unmounting the volume, and detaching normally).
|
||||
* This option can lead to data loss or a corrupted file system. Use this option
|
||||
* only as a last resort to detach an instance from a failed instance. The
|
||||
* instance will not have an opportunity to flush file system caches nor
|
||||
* file system meta data.
|
||||
* @return array
|
||||
*/
|
||||
public function detachVolume($volumeId, $instanceId = null, $device = null, $force = false)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'DetachVolume';
|
||||
$params['VolumeId'] = $volumeId;
|
||||
$params['InstanceId'] = strval($instanceId);
|
||||
$params['Device'] = strval($device);
|
||||
$params['Force'] = strval($force);
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$return = array();
|
||||
$return['volumeId'] = $xpath->evaluate('string(//ec2:volumeId/text())');
|
||||
$return['instanceId'] = $xpath->evaluate('string(//ec2:instanceId/text())');
|
||||
$return['device'] = $xpath->evaluate('string(//ec2:device/text())');
|
||||
$return['status'] = $xpath->evaluate('string(//ec2:status/text())');
|
||||
$return['attachTime'] = $xpath->evaluate('string(//ec2:attachTime/text())');
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an Amazon EBS volume
|
||||
*
|
||||
* @param string $volumeId The ID of the volume to delete
|
||||
* @return boolean
|
||||
*/
|
||||
public function deleteVolume($volumeId)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'DeleteVolume';
|
||||
$params['volumeId'] = $volumeId;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$return = $xpath->evaluate('string(//ec2:return/text())');
|
||||
|
||||
return ($return === "true");
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a snapshot of an Amazon EBS volume and stores it in Amazon S3. You can use snapshots for backups,
|
||||
* to launch instances from identical snapshots, and to save data before shutting down an instance
|
||||
*
|
||||
* @param string $volumeId The ID of the Amazon EBS volume to snapshot
|
||||
* @return array
|
||||
*/
|
||||
public function createSnapshot($volumeId)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'CreateSnapshot';
|
||||
$params['VolumeId'] = $volumeId;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$return = array();
|
||||
$return['snapshotId'] = $xpath->evaluate('string(//ec2:snapshotId/text())');
|
||||
$return['volumeId'] = $xpath->evaluate('string(//ec2:volumeId/text())');
|
||||
$return['status'] = $xpath->evaluate('string(//ec2:status/text())');
|
||||
$return['startTime'] = $xpath->evaluate('string(//ec2:startTime/text())');
|
||||
$return['progress'] = $xpath->evaluate('string(//ec2:progress/text())');
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes the status of Amazon EBS snapshots
|
||||
*
|
||||
* @param string|array $snapshotId The ID or arry of ID's of the Amazon EBS snapshot
|
||||
* @return array
|
||||
*/
|
||||
public function describeSnapshot($snapshotId = null)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'DescribeSnapshots';
|
||||
|
||||
if(is_array($snapshotId) && !empty($snapshotId)) {
|
||||
foreach($snapshotId as $k=>$name) {
|
||||
$params['SnapshotId.' . ($k+1)] = $name;
|
||||
}
|
||||
} elseif($snapshotId) {
|
||||
$params['SnapshotId.1'] = $snapshotId;
|
||||
}
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
$nodes = $xpath->query('//ec2:snapshotSet/ec2:item', $response->getDocument());
|
||||
|
||||
$return = array();
|
||||
foreach ($nodes as $node) {
|
||||
$item = array();
|
||||
|
||||
$item['snapshotId'] = $xpath->evaluate('string(ec2:snapshotId/text())', $node);
|
||||
$item['volumeId'] = $xpath->evaluate('string(ec2:volumeId/text())', $node);
|
||||
$item['status'] = $xpath->evaluate('string(ec2:status/text())', $node);
|
||||
$item['startTime'] = $xpath->evaluate('string(ec2:startTime/text())', $node);
|
||||
$item['progress'] = $xpath->evaluate('string(ec2:progress/text())', $node);
|
||||
|
||||
$return[] = $item;
|
||||
unset($item, $node);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a snapshot of an Amazon EBS volume that is stored in Amazon S3
|
||||
*
|
||||
* @param string $snapshotId The ID of the Amazon EBS snapshot to delete
|
||||
* @return boolean
|
||||
*/
|
||||
public function deleteSnapshot($snapshotId)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'DeleteSnapshot';
|
||||
$params['SnapshotId'] = $snapshotId;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
$return = $xpath->evaluate('string(//ec2:return/text())');
|
||||
|
||||
return ($return === "true");
|
||||
}
|
||||
}
|
158
airtime_mvc/library/Zend/Service/Amazon/Ec2/Elasticip.php
Normal file
158
airtime_mvc/library/Zend/Service/Amazon/Ec2/Elasticip.php
Normal file
|
@ -0,0 +1,158 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Elasticip.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Service_Amazon_Ec2_Abstract
|
||||
*/
|
||||
require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
|
||||
|
||||
/**
|
||||
* An Amazon EC2 interface to allocate, associate, describe and release Elastic IP address
|
||||
* from your account.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Ec2_Elasticip extends Zend_Service_Amazon_Ec2_Abstract
|
||||
{
|
||||
/**
|
||||
* Acquires an elastic IP address for use with your account
|
||||
*
|
||||
* @return string Returns the newly Allocated IP Address
|
||||
*/
|
||||
public function allocate()
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'AllocateAddress';
|
||||
|
||||
$response = $this->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");
|
||||
}
|
||||
|
||||
}
|
51
airtime_mvc/library/Zend/Service/Amazon/Ec2/Exception.php
Normal file
51
airtime_mvc/library/Zend/Service/Amazon/Ec2/Exception.php
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Service_Amazon_Exception
|
||||
*/
|
||||
require_once 'Zend/Service/Amazon/Exception.php';
|
||||
|
||||
/**
|
||||
* The Custom Exception class that allows you to have access to the AWS Error Code.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Ec2_Exception extends Zend_Service_Amazon_Exception
|
||||
{
|
||||
private $awsErrorCode = '';
|
||||
|
||||
public function __construct($message, $code = 0, $awsErrorCode = '')
|
||||
{
|
||||
parent::__construct($message, $code);
|
||||
$this->awsErrorCode = $awsErrorCode;
|
||||
}
|
||||
|
||||
public function getErrorCode()
|
||||
{
|
||||
return $this->awsErrorCode;
|
||||
}
|
||||
}
|
333
airtime_mvc/library/Zend/Service/Amazon/Ec2/Image.php
Normal file
333
airtime_mvc/library/Zend/Service/Amazon/Ec2/Image.php
Normal file
|
@ -0,0 +1,333 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Image.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Service_Amazon_Ec2_Abstract
|
||||
*/
|
||||
require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
|
||||
|
||||
/**
|
||||
* An Amazon EC2 interface to register, describe and deregister Amamzon Machine Instances (AMI)
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Ec2_Image extends Zend_Service_Amazon_Ec2_Abstract
|
||||
{
|
||||
/**
|
||||
* Registers an AMI with Amazon EC2. Images must be registered before
|
||||
* they can be launched.
|
||||
*
|
||||
* Each AMI is associated with an unique ID which is provided by the Amazon
|
||||
* EC2 service through the RegisterImage operation. During registration, Amazon
|
||||
* EC2 retrieves the specified image manifest from Amazon S3 and verifies that
|
||||
* the image is owned by the user registering the image.
|
||||
*
|
||||
* The image manifest is retrieved once and stored within the Amazon EC2.
|
||||
* Any modifications to an image in Amazon S3 invalidates this registration.
|
||||
* If you make changes to an image, deregister the previous image and register
|
||||
* the new image. For more information, see DeregisterImage.
|
||||
*
|
||||
* @param string $imageLocation Full path to your AMI manifest in Amazon S3 storage.
|
||||
* @return string The ami fro the newly registred image;
|
||||
*/
|
||||
public function register($imageLocation)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'RegisterImage';
|
||||
$params['ImageLocation']= $imageLocation;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$amiId = $xpath->evaluate('string(//ec2:imageId/text())');
|
||||
|
||||
return $amiId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information about AMIs, AKIs, and ARIs available to the user.
|
||||
* Information returned includes image type, product codes, architecture,
|
||||
* and kernel and RAM disk IDs. Images available to the user include public
|
||||
* images available for any user to launch, private images owned by the user
|
||||
* making the request, and private images owned by other users for which the
|
||||
* user has explicit launch permissions.
|
||||
*
|
||||
* Launch permissions fall into three categories:
|
||||
* public: The owner of the AMI granted launch permissions for the AMI
|
||||
* to the all group. All users have launch permissions for these AMIs.
|
||||
* explicit: The owner of the AMI granted launch permissions to a specific user.
|
||||
* implicit: A user has implicit launch permissions for all AMIs he or she owns.
|
||||
*
|
||||
* The list of AMIs returned can be modified by specifying AMI IDs, AMI owners,
|
||||
* or users with launch permissions. If no options are specified, Amazon EC2 returns
|
||||
* all AMIs for which the user has launch permissions.
|
||||
*
|
||||
* If you specify one or more AMI IDs, only AMIs that have the specified IDs are returned.
|
||||
* If you specify an invalid AMI ID, a fault is returned. If you specify an AMI ID for which
|
||||
* you do not have access, it will not be included in the returned results.
|
||||
*
|
||||
* If you specify one or more AMI owners, only AMIs from the specified owners and for
|
||||
* which you have access are returned. The results can include the account IDs of the
|
||||
* specified owners, amazon for AMIs owned by Amazon or self for AMIs that you own.
|
||||
*
|
||||
* If you specify a list of executable users, only users that have launch permissions
|
||||
* for the AMIs are returned. You can specify account IDs (if you own the AMI(s)), self
|
||||
* for AMIs for which you own or have explicit permissions, or all for public AMIs.
|
||||
*
|
||||
* @param string|array $imageId A list of image descriptions
|
||||
* @param string|array $owner Owners of AMIs to describe.
|
||||
* @param string|array $executableBy AMIs for which specified users have access.
|
||||
* @return array
|
||||
*/
|
||||
public function describe($imageId = null, $owner = null, $executableBy = null)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'DescribeImages';
|
||||
|
||||
if(is_array($imageId) && !empty($imageId)) {
|
||||
foreach($imageId as $k=>$name) {
|
||||
$params['ImageId.' . ($k+1)] = $name;
|
||||
}
|
||||
} elseif($imageId) {
|
||||
$params['ImageId.1'] = $imageId;
|
||||
}
|
||||
|
||||
if(is_array($owner) && !empty($owner)) {
|
||||
foreach($owner as $k=>$name) {
|
||||
$params['Owner.' . ($k+1)] = $name;
|
||||
}
|
||||
} elseif($owner) {
|
||||
$params['Owner.1'] = $owner;
|
||||
}
|
||||
|
||||
if(is_array($executableBy) && !empty($executableBy)) {
|
||||
foreach($executableBy as $k=>$name) {
|
||||
$params['ExecutableBy.' . ($k+1)] = $name;
|
||||
}
|
||||
} elseif($executableBy) {
|
||||
$params['ExecutableBy.1'] = $executableBy;
|
||||
}
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
$nodes = $xpath->query('//ec2:imagesSet/ec2:item');
|
||||
|
||||
$return = array();
|
||||
foreach ($nodes as $node) {
|
||||
$item = array();
|
||||
|
||||
$item['imageId'] = $xpath->evaluate('string(ec2:imageId/text())', $node);
|
||||
$item['imageLocation'] = $xpath->evaluate('string(ec2:imageLocation/text())', $node);
|
||||
$item['imageState'] = $xpath->evaluate('string(ec2:imageState/text())', $node);
|
||||
$item['imageOwnerId'] = $xpath->evaluate('string(ec2:imageOwnerId/text())', $node);
|
||||
$item['isPublic'] = $xpath->evaluate('string(ec2:isPublic/text())', $node);
|
||||
$item['architecture'] = $xpath->evaluate('string(ec2:architecture/text())', $node);
|
||||
$item['imageType'] = $xpath->evaluate('string(ec2:imageType/text())', $node);
|
||||
$item['kernelId'] = $xpath->evaluate('string(ec2:kernelId/text())', $node);
|
||||
$item['ramdiskId'] = $xpath->evaluate('string(ec2:ramdiskId/text())', $node);
|
||||
$item['platform'] = $xpath->evaluate('string(ec2:platform/text())', $node);
|
||||
|
||||
$return[] = $item;
|
||||
unset($item, $node);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deregisters an AMI. Once deregistered, instances of the AMI can no longer be launched.
|
||||
*
|
||||
* @param string $imageId Unique ID of a machine image, returned by a call
|
||||
* to RegisterImage or DescribeImages.
|
||||
* @return boolean
|
||||
*/
|
||||
public function deregister($imageId)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'DeregisterImage';
|
||||
$params['ImageId'] = $imageId;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$return = $xpath->evaluate('string(//ec2:return/text())');
|
||||
|
||||
return ($return === "true");
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifies an attribute of an AMI.
|
||||
*
|
||||
* Valid Attributes:
|
||||
* launchPermission: Controls who has permission to launch the AMI. Launch permissions
|
||||
* can be granted to specific users by adding userIds.
|
||||
* To make the AMI public, add the all group.
|
||||
* productCodes: Associates a product code with AMIs. This allows developers to
|
||||
* charge users for using AMIs. The user must be signed up for the
|
||||
* product before they can launch the AMI. This is a write once attribute;
|
||||
* after it is set, it cannot be changed or removed.
|
||||
*
|
||||
* @param string $imageId AMI ID to modify.
|
||||
* @param string $attribute Specifies the attribute to modify. See the preceding
|
||||
* attributes table for supported attributes.
|
||||
* @param string $operationType Specifies the operation to perform on the attribute.
|
||||
* See the preceding attributes table for supported operations for attributes.
|
||||
* Valid Values: add | remove
|
||||
* Required for launchPermssion Attribute
|
||||
*
|
||||
* @param string|array $userId User IDs to add to or remove from the launchPermission attribute.
|
||||
* Required for launchPermssion Attribute
|
||||
* @param string|array $userGroup User groups to add to or remove from the launchPermission attribute.
|
||||
* Currently, the all group is available, which will make it a public AMI.
|
||||
* Required for launchPermssion Attribute
|
||||
* @param string $productCode Attaches a product code to the AMI. Currently only one product code
|
||||
* can be associated with an AMI. Once set, the product code cannot be changed or reset.
|
||||
* Required for productCodes Attribute
|
||||
* @return boolean
|
||||
*/
|
||||
public function modifyAttribute($imageId, $attribute, $operationType = 'add', $userId = null, $userGroup = null, $productCode = null)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'ModifyImageAttribute';
|
||||
$parmas['ImageId'] = $imageId;
|
||||
$params['Attribute'] = $attribute;
|
||||
|
||||
switch($attribute) {
|
||||
case 'launchPermission':
|
||||
// break left out
|
||||
case 'launchpermission':
|
||||
$params['Attribute'] = 'launchPermission';
|
||||
$params['OperationType'] = $operationType;
|
||||
|
||||
if(is_array($userId) && !empty($userId)) {
|
||||
foreach($userId as $k=>$name) {
|
||||
$params['UserId.' . ($k+1)] = $name;
|
||||
}
|
||||
} elseif($userId) {
|
||||
$params['UserId.1'] = $userId;
|
||||
}
|
||||
|
||||
if(is_array($userGroup) && !empty($userGroup)) {
|
||||
foreach($userGroup as $k=>$name) {
|
||||
$params['UserGroup.' . ($k+1)] = $name;
|
||||
}
|
||||
} elseif($userGroup) {
|
||||
$params['UserGroup.1'] = $userGroup;
|
||||
}
|
||||
|
||||
break;
|
||||
case 'productCodes':
|
||||
// break left out
|
||||
case 'productcodes':
|
||||
$params['Attribute'] = 'productCodes';
|
||||
$params['ProductCode.1'] = $productCode;
|
||||
break;
|
||||
default:
|
||||
require_once 'Zend/Service/Amazon/Ec2/Exception.php';
|
||||
throw new Zend_Service_Amazon_Ec2_Exception('Invalid Attribute Passed In. Valid Image Attributes are launchPermission and productCode.');
|
||||
break;
|
||||
}
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$return = $xpath->evaluate('string(//ec2:return/text())');
|
||||
|
||||
return ($return === "true");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information about an attribute of an AMI. Only one attribute can be specified per call.
|
||||
*
|
||||
* @param string $imageId ID of the AMI for which an attribute will be described.
|
||||
* @param string $attribute Specifies the attribute to describe. Valid Attributes are
|
||||
* launchPermission, productCodes
|
||||
*/
|
||||
public function describeAttribute($imageId, $attribute)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'DescribeImageAttribute';
|
||||
$params['ImageId'] = $imageId;
|
||||
$params['Attribute'] = $attribute;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$return = array();
|
||||
$return['imageId'] = $xpath->evaluate('string(//ec2:imageId/text())');
|
||||
|
||||
// check for launchPermission
|
||||
if($attribute == 'launchPermission') {
|
||||
$lPnodes = $xpath->query('//ec2:launchPermission/ec2:item');
|
||||
|
||||
if($lPnodes->length > 0) {
|
||||
$return['launchPermission'] = array();
|
||||
foreach($lPnodes as $node) {
|
||||
$return['launchPermission'][] = $xpath->evaluate('string(ec2:userId/text())', $node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check for product codes
|
||||
if($attribute == 'productCodes') {
|
||||
$pCnodes = $xpath->query('//ec2:productCodes/ec2:item');
|
||||
if($pCnodes->length > 0) {
|
||||
$return['productCodes'] = array();
|
||||
foreach($pCnodes as $node) {
|
||||
$return['productCodes'][] = $xpath->evaluate('string(ec2:productCode/text())', $node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets an attribute of an AMI to its default value. The productCodes attribute cannot be reset
|
||||
*
|
||||
* @param string $imageId ID of the AMI for which an attribute will be reset.
|
||||
* @param String $attribute Specifies the attribute to reset. Currently, only launchPermission is supported.
|
||||
* In the case of launchPermission, all public and explicit launch permissions for
|
||||
* the AMI are revoked.
|
||||
* @return boolean
|
||||
*/
|
||||
public function resetAttribute($imageId, $attribute)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'ResetImageAttribute';
|
||||
$params['ImageId'] = $imageId;
|
||||
$params['Attribute'] = $attribute;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$return = $xpath->evaluate('string(//ec2:return/text())');
|
||||
|
||||
return ($return === "true");
|
||||
}
|
||||
}
|
529
airtime_mvc/library/Zend/Service/Amazon/Ec2/Instance.php
Normal file
529
airtime_mvc/library/Zend/Service/Amazon/Ec2/Instance.php
Normal file
|
@ -0,0 +1,529 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Instance.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Service_Amazon_Ec2_Abstract
|
||||
*/
|
||||
require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
|
||||
|
||||
/**
|
||||
* An Amazon EC2 interface that allows yout to run, terminate, reboot and describe Amazon
|
||||
* Ec2 Instances.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Ec2_Instance extends Zend_Service_Amazon_Ec2_Abstract
|
||||
{
|
||||
/**
|
||||
* Constant for Small Instance TYpe
|
||||
*/
|
||||
const SMALL = 'm1.small';
|
||||
|
||||
/**
|
||||
* Constant for Large Instance TYpe
|
||||
*/
|
||||
const LARGE = 'm1.large';
|
||||
|
||||
/**
|
||||
* Constant for X-Large Instance TYpe
|
||||
*/
|
||||
const XLARGE = 'm1.xlarge';
|
||||
|
||||
/**
|
||||
* Constant for High CPU Medium Instance TYpe
|
||||
*/
|
||||
const HCPU_MEDIUM = 'c1.medium';
|
||||
|
||||
/**
|
||||
* Constant for High CPU X-Large Instance TYpe
|
||||
*/
|
||||
const HCPU_XLARGE = 'c1.xlarge';
|
||||
|
||||
|
||||
/**
|
||||
* Launches a specified number of Instances.
|
||||
*
|
||||
* If Amazon EC2 cannot launch the minimum number AMIs you request, no
|
||||
* instances launch. If there is insufficient capacity to launch the
|
||||
* maximum number of AMIs you request, Amazon EC2 launches as many
|
||||
* as possible to satisfy the requested maximum values.
|
||||
*
|
||||
* Every instance is launched in a security group. If you do not specify
|
||||
* a security group at launch, the instances start in your default security group.
|
||||
* For more information on creating security groups, see CreateSecurityGroup.
|
||||
*
|
||||
* An optional instance type can be specified. For information
|
||||
* about instance types, see Instance Types.
|
||||
*
|
||||
* You can provide an optional key pair ID for each image in the launch request
|
||||
* (for more information, see CreateKeyPair). All instances that are created
|
||||
* from images that use this key pair will have access to the associated public
|
||||
* key at boot. You can use this key to provide secure access to an instance of an
|
||||
* image on a per-instance basis. Amazon EC2 public images use this feature to
|
||||
* provide secure access without passwords.
|
||||
*
|
||||
* Launching public images without a key pair ID will leave them inaccessible.
|
||||
*
|
||||
* @param array $options An array that contins the options to start an instance.
|
||||
* Required Values:
|
||||
* imageId string ID of the AMI with which to launch instances.
|
||||
* Optional Values:
|
||||
* minCount integer Minimum number of instances to launch.
|
||||
* maxCount integer Maximum number of instances to launch.
|
||||
* keyName string Name of the key pair with which to launch instances.
|
||||
* securityGruop string|array Names of the security groups with which to associate the instances.
|
||||
* userData string The user data available to the launched instances. This should not be Base64 encoded.
|
||||
* instanceType constant Specifies the instance type.
|
||||
* placement string Specifies the availability zone in which to launch the instance(s). By default, Amazon EC2 selects an availability zone for you.
|
||||
* kernelId string The ID of the kernel with which to launch the instance.
|
||||
* ramdiskId string The ID of the RAM disk with which to launch the instance.
|
||||
* blockDeviceVirtualName string Specifies the virtual name to map to the corresponding device name. For example: instancestore0
|
||||
* blockDeviceName string Specifies the device to which you are mapping a virtual name. For example: sdb
|
||||
* monitor boolean Turn on CloudWatch Monitoring for an instance.
|
||||
* @return array
|
||||
*/
|
||||
public function run(array $options)
|
||||
{
|
||||
$_defaultOptions = array(
|
||||
'minCount' => 1,
|
||||
'maxCount' => 1,
|
||||
'instanceType' => Zend_Service_Amazon_Ec2_Instance::SMALL
|
||||
);
|
||||
|
||||
// set / override the defualt optoins if they are not passed into the array;
|
||||
$options = array_merge($_defaultOptions, $options);
|
||||
|
||||
if(!isset($options['imageId'])) {
|
||||
require_once 'Zend/Service/Amazon/Ec2/Exception.php';
|
||||
throw new Zend_Service_Amazon_Ec2_Exception('No Image Id Provided');
|
||||
}
|
||||
|
||||
|
||||
$params = array();
|
||||
$params['Action'] = 'RunInstances';
|
||||
$params['ImageId'] = $options['imageId'];
|
||||
$params['MinCount'] = $options['minCount'];
|
||||
$params['MaxCount'] = $options['maxCount'];
|
||||
|
||||
if(isset($options['keyName'])) {
|
||||
$params['KeyName'] = $options['keyName'];
|
||||
}
|
||||
|
||||
if(is_array($options['securityGroup']) && !empty($options['securityGroup'])) {
|
||||
foreach($options['securityGroup'] as $k=>$name) {
|
||||
$params['SecurityGroup.' . ($k+1)] = $name;
|
||||
}
|
||||
} elseif(isset($options['securityGroup'])) {
|
||||
$params['SecurityGroup.1'] = $options['securityGroup'];
|
||||
}
|
||||
|
||||
if(isset($options['userData'])) {
|
||||
$params['UserData'] = base64_encode($options['userData']);
|
||||
}
|
||||
|
||||
if(isset($options['instanceType'])) {
|
||||
$params['InstanceType'] = $options['instanceType'];
|
||||
}
|
||||
|
||||
if(isset($options['placement'])) {
|
||||
$params['Placement.AvailabilityZone'] = $options['placement'];
|
||||
}
|
||||
|
||||
if(isset($options['kernelId'])) {
|
||||
$params['KernelId'] = $options['kernelId'];
|
||||
}
|
||||
|
||||
if(isset($options['ramdiskId'])) {
|
||||
$params['RamdiskId'] = $options['ramdiskId'];
|
||||
}
|
||||
|
||||
if(isset($options['blockDeviceVirtualName']) && isset($options['blockDeviceName'])) {
|
||||
$params['BlockDeviceMapping.n.VirtualName'] = $options['blockDeviceVirtualName'];
|
||||
$params['BlockDeviceMapping.n.DeviceName'] = $options['blockDeviceName'];
|
||||
}
|
||||
|
||||
if(isset($options['monitor']) && $options['monitor'] === true) {
|
||||
$params['Monitoring.Enabled'] = true;
|
||||
}
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$return = array();
|
||||
|
||||
$return['reservationId'] = $xpath->evaluate('string(//ec2:reservationId/text())');
|
||||
$return['ownerId'] = $xpath->evaluate('string(//ec2:ownerId/text())');
|
||||
|
||||
$gs = $xpath->query('//ec2:groupSet/ec2:item');
|
||||
foreach($gs as $gs_node) {
|
||||
$return['groupSet'][] = $xpath->evaluate('string(ec2:groupId/text())', $gs_node);
|
||||
unset($gs_node);
|
||||
}
|
||||
unset($gs);
|
||||
|
||||
$is = $xpath->query('//ec2:instancesSet/ec2:item');
|
||||
foreach($is as $is_node) {
|
||||
$item = array();
|
||||
|
||||
$item['instanceId'] = $xpath->evaluate('string(ec2:instanceId/text())', $is_node);
|
||||
$item['imageId'] = $xpath->evaluate('string(ec2:imageId/text())', $is_node);
|
||||
$item['instanceState']['code'] = $xpath->evaluate('string(ec2:instanceState/ec2:code/text())', $is_node);
|
||||
$item['instanceState']['name'] = $xpath->evaluate('string(ec2:instanceState/ec2:name/text())', $is_node);
|
||||
$item['privateDnsName'] = $xpath->evaluate('string(ec2:privateDnsName/text())', $is_node);
|
||||
$item['dnsName'] = $xpath->evaluate('string(ec2:dnsName/text())', $is_node);
|
||||
$item['keyName'] = $xpath->evaluate('string(ec2:keyName/text())', $is_node);
|
||||
$item['instanceType'] = $xpath->evaluate('string(ec2:instanceType/text())', $is_node);
|
||||
$item['amiLaunchIndex'] = $xpath->evaluate('string(ec2:amiLaunchIndex/text())', $is_node);
|
||||
$item['launchTime'] = $xpath->evaluate('string(ec2:launchTime/text())', $is_node);
|
||||
$item['availabilityZone'] = $xpath->evaluate('string(ec2:placement/ec2:availabilityZone/text())', $is_node);
|
||||
|
||||
$return['instances'][] = $item;
|
||||
unset($item);
|
||||
unset($is_node);
|
||||
}
|
||||
unset($is);
|
||||
|
||||
return $return;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information about instances that you own.
|
||||
*
|
||||
* If you specify one or more instance IDs, Amazon EC2 returns information
|
||||
* for those instances. If you do not specify instance IDs, Amazon EC2
|
||||
* returns information for all relevant instances. If you specify an invalid
|
||||
* instance ID, a fault is returned. If you specify an instance that you do
|
||||
* not own, it will not be included in the returned results.
|
||||
*
|
||||
* Recently terminated instances might appear in the returned results.
|
||||
* This interval is usually less than one hour.
|
||||
*
|
||||
* @param string|array $instaceId Set of instances IDs of which to get the status.
|
||||
* @param boolean Ture to ignore Terminated Instances.
|
||||
* @return array
|
||||
*/
|
||||
public function describe($instanceId = null, $ignoreTerminated = false)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'DescribeInstances';
|
||||
|
||||
if(is_array($instanceId) && !empty($instanceId)) {
|
||||
foreach($instanceId as $k=>$name) {
|
||||
$params['InstanceId.' . ($k+1)] = $name;
|
||||
}
|
||||
} elseif($instanceId) {
|
||||
$params['InstanceId.1'] = $instanceId;
|
||||
}
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$nodes = $xpath->query('//ec2:reservationSet/ec2:item');
|
||||
|
||||
$return = array();
|
||||
$return['instances'] = array();
|
||||
|
||||
foreach($nodes as $node) {
|
||||
if($xpath->evaluate('string(ec2:instancesSet/ec2:item/ec2:instanceState/ec2:code/text())', $node) == 48 && $ignoreTerminated) continue;
|
||||
$item = array();
|
||||
|
||||
$item['reservationId'] = $xpath->evaluate('string(ec2:reservationId/text())', $node);
|
||||
$item['ownerId'] = $xpath->evaluate('string(ec2:ownerId/text())', $node);
|
||||
|
||||
$gs = $xpath->query('ec2:groupSet/ec2:item', $node);
|
||||
foreach($gs as $gs_node) {
|
||||
$item['groupSet'][] = $xpath->evaluate('string(ec2:groupId/text())', $gs_node);
|
||||
unset($gs_node);
|
||||
}
|
||||
unset($gs);
|
||||
|
||||
$is = $xpath->query('ec2:instancesSet/ec2:item', $node);
|
||||
|
||||
foreach($is as $is_node) {
|
||||
|
||||
$item['instanceId'] = $xpath->evaluate('string(ec2:instanceId/text())', $is_node);
|
||||
$item['imageId'] = $xpath->evaluate('string(ec2:imageId/text())', $is_node);
|
||||
$item['instanceState']['code'] = $xpath->evaluate('string(ec2:instanceState/ec2:code/text())', $is_node);
|
||||
$item['instanceState']['name'] = $xpath->evaluate('string(ec2:instanceState/ec2:name/text())', $is_node);
|
||||
$item['privateDnsName'] = $xpath->evaluate('string(ec2:privateDnsName/text())', $is_node);
|
||||
$item['dnsName'] = $xpath->evaluate('string(ec2:dnsName/text())', $is_node);
|
||||
$item['keyName'] = $xpath->evaluate('string(ec2:keyName/text())', $is_node);
|
||||
$item['productCode'] = $xpath->evaluate('string(ec2:productCodesSet/ec2:item/ec2:productCode/text())', $is_node);
|
||||
$item['instanceType'] = $xpath->evaluate('string(ec2:instanceType/text())', $is_node);
|
||||
$item['launchTime'] = $xpath->evaluate('string(ec2:launchTime/text())', $is_node);
|
||||
$item['availabilityZone'] = $xpath->evaluate('string(ec2:placement/ec2:availabilityZone/text())', $is_node);
|
||||
$item['kernelId'] = $xpath->evaluate('string(ec2:kernelId/text())', $is_node);
|
||||
$item['ramediskId'] = $xpath->evaluate('string(ec2:ramediskId/text())', $is_node);
|
||||
$item['amiLaunchIndex'] = $xpath->evaluate('string(ec2:amiLaunchIndex/text())', $is_node);
|
||||
$item['monitoringState'] = $xpath->evaluate('string(ec2:monitoring/ec2:state/text())', $is_node);
|
||||
|
||||
unset($is_node);
|
||||
}
|
||||
$return['instances'][] = $item;
|
||||
unset($item);
|
||||
unset($is);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information about instances that you own that were started from
|
||||
* a specific imageId
|
||||
*
|
||||
* Recently terminated instances might appear in the returned results.
|
||||
* This interval is usually less than one hour.
|
||||
*
|
||||
* @param string $imageId The imageId used to start the Instance.
|
||||
* @param boolean Ture to ignore Terminated Instances.
|
||||
* @return array
|
||||
*/
|
||||
public function describeByImageId($imageId, $ignoreTerminated = false)
|
||||
{
|
||||
$arrInstances = $this->describe(null, $ignoreTerminated);
|
||||
|
||||
$return = array();
|
||||
|
||||
foreach($arrInstances['instances'] as $instance) {
|
||||
if($instance['imageId'] !== $imageId) continue;
|
||||
$return[] = $instance;
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shuts down one or more instances. This operation is idempotent; if you terminate
|
||||
* an instance more than once, each call will succeed.
|
||||
*
|
||||
* Terminated instances will remain visible after termination (approximately one hour).
|
||||
*
|
||||
* @param string|array $instanceId One or more instance IDs returned.
|
||||
* @return array
|
||||
*/
|
||||
public function terminate($instanceId)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'TerminateInstances';
|
||||
|
||||
if(is_array($instanceId) && !empty($instanceId)) {
|
||||
foreach($instanceId as $k=>$name) {
|
||||
$params['InstanceId.' . ($k+1)] = $name;
|
||||
}
|
||||
} elseif($instanceId) {
|
||||
$params['InstanceId.1'] = $instanceId;
|
||||
}
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$nodes = $xpath->query('//ec2:instancesSet/ec2:item');
|
||||
|
||||
$return = array();
|
||||
foreach($nodes as $node) {
|
||||
$item = array();
|
||||
|
||||
$item['instanceId'] = $xpath->evaluate('string(ec2:instanceId/text())', $node);
|
||||
$item['shutdownState']['code'] = $xpath->evaluate('string(ec2:shutdownState/ec2:code/text())', $node);
|
||||
$item['shutdownState']['name'] = $xpath->evaluate('string(ec2:shutdownState/ec2:name/text())', $node);
|
||||
$item['previousState']['code'] = $xpath->evaluate('string(ec2:previousState/ec2:code/text())', $node);
|
||||
$item['previousState']['name'] = $xpath->evaluate('string(ec2:previousState/ec2:name/text())', $node);
|
||||
|
||||
$return[] = $item;
|
||||
unset($item);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests a reboot of one or more instances.
|
||||
*
|
||||
* This operation is asynchronous; it only queues a request to reboot the specified instance(s). The operation
|
||||
* will succeed if the instances are valid and belong to the user. Requests to reboot terminated instances are ignored.
|
||||
*
|
||||
* @param string|array $instanceId One or more instance IDs.
|
||||
* @return boolean
|
||||
*/
|
||||
public function reboot($instanceId)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'RebootInstances';
|
||||
|
||||
if(is_array($instanceId) && !empty($instanceId)) {
|
||||
foreach($instanceId as $k=>$name) {
|
||||
$params['InstanceId.' . ($k+1)] = $name;
|
||||
}
|
||||
} elseif($instanceId) {
|
||||
$params['InstanceId.1'] = $instanceId;
|
||||
}
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$return = $xpath->evaluate('string(//ec2:return/text())');
|
||||
|
||||
return ($return === "true");
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves console output for the specified instance.
|
||||
*
|
||||
* Instance console output is buffered and posted shortly after instance boot, reboot, and termination.
|
||||
* Amazon EC2 preserves the most recent 64 KB output which will be available for at least one hour after the most recent post.
|
||||
*
|
||||
* @param string $instanceId An instance ID
|
||||
* @return array
|
||||
*/
|
||||
public function consoleOutput($instanceId)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'GetConsoleOutput';
|
||||
$params['InstanceId'] = $instanceId;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$return = array();
|
||||
|
||||
$return['instanceId'] = $xpath->evaluate('string(//ec2:instanceId/text())');
|
||||
$return['timestamp'] = $xpath->evaluate('string(//ec2:timestamp/text())');
|
||||
$return['output'] = base64_decode($xpath->evaluate('string(//ec2:output/text())'));
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the specified product code is attached to the specified instance.
|
||||
* The operation returns false if the product code is not attached to the instance.
|
||||
*
|
||||
* The confirmProduct operation can only be executed by the owner of the AMI.
|
||||
* This feature is useful when an AMI owner is providing support and wants to
|
||||
* verify whether a user's instance is eligible.
|
||||
*
|
||||
* @param string $productCode The product code to confirm.
|
||||
* @param string $instanceId The instance for which to confirm the product code.
|
||||
* @return array|boolean An array if the product code is attached to the instance, false if it is not.
|
||||
*/
|
||||
public function confirmProduct($productCode, $instanceId)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'ConfirmProductInstance';
|
||||
$params['ProductCode'] = $productCode;
|
||||
$params['InstanceId'] = $instanceId;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$result = $xpath->evaluate('string(//ec2:result/text())');
|
||||
|
||||
if($result === "true") {
|
||||
$return['result'] = true;
|
||||
$return['ownerId'] = $xpath->evaluate('string(//ec2:ownerId/text())');
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn on Amazon CloudWatch Monitoring for an instance or a list of instances
|
||||
*
|
||||
* @param array|string $instanceId The instance or list of instances you want to enable monitoring for
|
||||
* @return array
|
||||
*/
|
||||
public function monitor($instanceId)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'MonitorInstances';
|
||||
|
||||
if(is_array($instanceId) && !empty($instanceId)) {
|
||||
foreach($instanceId as $k=>$name) {
|
||||
$params['InstanceId.' . ($k+1)] = $name;
|
||||
}
|
||||
} elseif($instanceId) {
|
||||
$params['InstanceId.1'] = $instanceId;
|
||||
}
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
|
||||
$items = $xpath->query('//ec2:instancesSet/ec2:item');
|
||||
|
||||
$arrReturn = array();
|
||||
foreach($items as $item) {
|
||||
$i = array();
|
||||
$i['instanceid'] = $xpath->evaluate('string(//ec2:instanceId/text())', $item);
|
||||
$i['monitorstate'] = $xpath->evaluate('string(//ec2:monitoring/ec2:state/text())');
|
||||
$arrReturn[] = $i;
|
||||
unset($i);
|
||||
}
|
||||
|
||||
return $arrReturn;
|
||||
}
|
||||
/**
|
||||
* Turn off Amazon CloudWatch Monitoring for an instance or a list of instances
|
||||
*
|
||||
* @param array|string $instanceId The instance or list of instances you want to disable monitoring for
|
||||
* @return array
|
||||
*/
|
||||
public function unmonitor($instanceId)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'UnmonitorInstances';
|
||||
|
||||
if(is_array($instanceId) && !empty($instanceId)) {
|
||||
foreach($instanceId as $k=>$name) {
|
||||
$params['InstanceId.' . ($k+1)] = $name;
|
||||
}
|
||||
} elseif($instanceId) {
|
||||
$params['InstanceId.1'] = $instanceId;
|
||||
}
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
|
||||
$items = $xpath->query('//ec2:instancesSet/ec2:item');
|
||||
|
||||
$arrReturn = array();
|
||||
foreach($items as $item) {
|
||||
$i = array();
|
||||
$i['instanceid'] = $xpath->evaluate('string(//ec2:instanceId/text())', $item);
|
||||
$i['monitorstate'] = $xpath->evaluate('string(//ec2:monitoring/ec2:state/text())');
|
||||
$arrReturn[] = $i;
|
||||
unset($i);
|
||||
}
|
||||
|
||||
return $arrReturn;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,143 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Reserved.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Service_Amazon_Ec2_Abstract
|
||||
*/
|
||||
require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
|
||||
|
||||
/**
|
||||
* Allows you to interface with the reserved instances on Amazon Ec2
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Ec2_Instance_Reserved extends Zend_Service_Amazon_Ec2_Abstract
|
||||
{
|
||||
/**
|
||||
* Describes Reserved Instances that you purchased.
|
||||
*
|
||||
* @param string|array $instanceId IDs of the Reserved Instance to describe.
|
||||
* @return array
|
||||
*/
|
||||
public function describeInstances($instanceId)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'DescribeReservedInstances';
|
||||
|
||||
if(is_array($instanceId) && !empty($instanceId)) {
|
||||
foreach($instanceId as $k=>$name) {
|
||||
$params['ReservedInstancesId.' . ($k+1)] = $name;
|
||||
}
|
||||
} elseif($instanceId) {
|
||||
$params['ReservedInstancesId.1'] = $instanceId;
|
||||
}
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
$items = $xpath->query('//ec2:reservedInstancesSet/ec2:item');
|
||||
|
||||
$return = array();
|
||||
foreach($items as $item) {
|
||||
$i = array();
|
||||
$i['reservedInstancesId'] = $xpath->evaluate('string(ec2:reservedInstancesId/text())', $item);
|
||||
$i['instanceType'] = $xpath->evaluate('string(ec2:instanceType/text())', $item);
|
||||
$i['availabilityZone'] = $xpath->evaluate('string(ec2:availabilityZone/text())', $item);
|
||||
$i['duration'] = $xpath->evaluate('string(ec2:duration/text())', $item);
|
||||
$i['fixedPrice'] = $xpath->evaluate('string(ec2:fixedPrice/text())', $item);
|
||||
$i['usagePrice'] = $xpath->evaluate('string(ec2:usagePrice/text())', $item);
|
||||
$i['productDescription'] = $xpath->evaluate('string(ec2:productDescription/text())', $item);
|
||||
$i['instanceCount'] = $xpath->evaluate('string(ec2:instanceCount/text())', $item);
|
||||
$i['state'] = $xpath->evaluate('string(ec2:state/text())', $item);
|
||||
|
||||
$return[] = $i;
|
||||
unset($i);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes Reserved Instance offerings that are available for purchase.
|
||||
* With Amazon EC2 Reserved Instances, you purchase the right to launch Amazon
|
||||
* EC2 instances for a period of time (without getting insufficient capacity
|
||||
* errors) and pay a lower usage rate for the actual time used.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function describeOfferings()
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'DescribeReservedInstancesOfferings';
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
$items = $xpath->query('//ec2:reservedInstancesOfferingsSet/ec2:item');
|
||||
|
||||
$return = array();
|
||||
foreach($items as $item) {
|
||||
$i = array();
|
||||
$i['reservedInstancesOfferingId'] = $xpath->evaluate('string(ec2:reservedInstancesOfferingId/text())', $item);
|
||||
$i['instanceType'] = $xpath->evaluate('string(ec2:instanceType/text())', $item);
|
||||
$i['availabilityZone'] = $xpath->evaluate('string(ec2:availabilityZone/text())', $item);
|
||||
$i['duration'] = $xpath->evaluate('string(ec2:duration/text())', $item);
|
||||
$i['fixedPrice'] = $xpath->evaluate('string(ec2:fixedPrice/text())', $item);
|
||||
$i['usagePrice'] = $xpath->evaluate('string(ec2:usagePrice/text())', $item);
|
||||
$i['productDescription'] = $xpath->evaluate('string(ec2:productDescription/text())', $item);
|
||||
|
||||
$return[] = $i;
|
||||
unset($i);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Purchases a Reserved Instance for use with your account. With Amazon EC2
|
||||
* Reserved Instances, you purchase the right to launch Amazon EC2 instances
|
||||
* for a period of time (without getting insufficient capacity errors) and
|
||||
* pay a lower usage rate for the actual time used.
|
||||
*
|
||||
* @param string $offeringId The offering ID of the Reserved Instance to purchase
|
||||
* @param integer $intanceCount The number of Reserved Instances to purchase.
|
||||
* @return string The ID of the purchased Reserved Instances.
|
||||
*/
|
||||
public function purchaseOffering($offeringId, $intanceCount = 1)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'PurchaseReservedInstancesOffering';
|
||||
$params['OfferingId.1'] = $offeringId;
|
||||
$params['instanceCount.1'] = intval($intanceCount);
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
$reservedInstancesId = $xpath->evaluate('string(//ec2:reservedInstancesId/text())');
|
||||
|
||||
return $reservedInstancesId;
|
||||
}
|
||||
}
|
195
airtime_mvc/library/Zend/Service/Amazon/Ec2/Instance/Windows.php
Normal file
195
airtime_mvc/library/Zend/Service/Amazon/Ec2/Instance/Windows.php
Normal file
|
@ -0,0 +1,195 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Windows.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Service_Amazon_Ec2_Abstract
|
||||
*/
|
||||
require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Crypt_Hmac
|
||||
*/
|
||||
require_once 'Zend/Crypt/Hmac.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Json
|
||||
*/
|
||||
require_once 'Zend/Json.php';
|
||||
|
||||
/**
|
||||
* An Amazon EC2 interface that allows yout to run, terminate, reboot and describe Amazon
|
||||
* Ec2 Instances.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Ec2_Instance_Windows extends Zend_Service_Amazon_Ec2_Abstract
|
||||
{
|
||||
/**
|
||||
* Bundles an Amazon EC2 instance running Windows
|
||||
*
|
||||
* @param string $instanceId The instance you want to bundle
|
||||
* @param string $s3Bucket Where you want the ami to live on S3
|
||||
* @param string $s3Prefix The prefix you want to assign to the AMI on S3
|
||||
* @param integer $uploadExpiration The expiration of the upload policy. Amazon recommends 12 hours or longer.
|
||||
* This is based in nubmer of minutes. Default is 1440 minutes (24 hours)
|
||||
* @return array containing the information on the new bundle operation
|
||||
*/
|
||||
public function bundle($instanceId, $s3Bucket, $s3Prefix, $uploadExpiration = 1440)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'BundleInstance';
|
||||
$params['InstanceId'] = $instanceId;
|
||||
$params['Storage.S3.AWSAccessKeyId'] = $this->_getAccessKey();
|
||||
$params['Storage.S3.Bucket'] = $s3Bucket;
|
||||
$params['Storage.S3.Prefix'] = $s3Prefix;
|
||||
$uploadPolicy = $this->_getS3UploadPolicy($s3Bucket, $s3Prefix, $uploadExpiration);
|
||||
$params['Storage.S3.UploadPolicy'] = $uploadPolicy;
|
||||
$params['Storage.S3.UploadPolicySignature'] = $this->_signS3UploadPolicy($uploadPolicy);
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$return = array();
|
||||
$return['instanceId'] = $xpath->evaluate('string(//ec2:bundleInstanceTask/ec2:instanceId/text())');
|
||||
$return['bundleId'] = $xpath->evaluate('string(//ec2:bundleInstanceTask/ec2:bundleId/text())');
|
||||
$return['state'] = $xpath->evaluate('string(//ec2:bundleInstanceTask/ec2:state/text())');
|
||||
$return['startTime'] = $xpath->evaluate('string(//ec2:bundleInstanceTask/ec2:startTime/text())');
|
||||
$return['updateTime'] = $xpath->evaluate('string(//ec2:bundleInstanceTask/ec2:updateTime/text())');
|
||||
$return['progress'] = $xpath->evaluate('string(//ec2:bundleInstanceTask/ec2:progress/text())');
|
||||
$return['storage']['s3']['bucket'] = $xpath->evaluate('string(//ec2:bundleInstanceTask/ec2:storage/ec2:S3/ec2:bucket/text())');
|
||||
$return['storage']['s3']['prefix'] = $xpath->evaluate('string(//ec2:bundleInstanceTask/ec2:storage/ec2:S3/ec2:prefix/text())');
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels an Amazon EC2 bundling operation
|
||||
*
|
||||
* @param string $bundleId The ID of the bundle task to cancel
|
||||
* @return array Information on the bundle task
|
||||
*/
|
||||
public function cancelBundle($bundleId)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'CancelBundleTask';
|
||||
$params['BundleId'] = $bundleId;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$return = array();
|
||||
$return['instanceId'] = $xpath->evaluate('string(//ec2:bundleInstanceTask/ec2:instanceId/text())');
|
||||
$return['bundleId'] = $xpath->evaluate('string(//ec2:bundleInstanceTask/ec2:bundleId/text())');
|
||||
$return['state'] = $xpath->evaluate('string(//ec2:bundleInstanceTask/ec2:state/text())');
|
||||
$return['startTime'] = $xpath->evaluate('string(//ec2:bundleInstanceTask/ec2:startTime/text())');
|
||||
$return['updateTime'] = $xpath->evaluate('string(//ec2:bundleInstanceTask/ec2:updateTime/text())');
|
||||
$return['progress'] = $xpath->evaluate('string(//ec2:bundleInstanceTask/ec2:progress/text())');
|
||||
$return['storage']['s3']['bucket'] = $xpath->evaluate('string(//ec2:bundleInstanceTask/ec2:storage/ec2:S3/ec2:bucket/text())');
|
||||
$return['storage']['s3']['prefix'] = $xpath->evaluate('string(//ec2:bundleInstanceTask/ec2:storage/ec2:S3/ec2:prefix/text())');
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes current bundling tasks
|
||||
*
|
||||
* @param string|array $bundleId A single or a list of bundle tasks that you want
|
||||
* to find information for.
|
||||
* @return array Information for the task that you requested
|
||||
*/
|
||||
public function describeBundle($bundleId = '')
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'DescribeBundleTasks';
|
||||
|
||||
if(is_array($bundleId) && !empty($bundleId)) {
|
||||
foreach($bundleId as $k=>$name) {
|
||||
$params['bundleId.' . ($k+1)] = $name;
|
||||
}
|
||||
} elseif(!empty($bundleId)) {
|
||||
$params['bundleId.1'] = $bundleId;
|
||||
}
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$items = $xpath->evaluate('//ec2:bundleInstanceTasksSet/ec2:item');
|
||||
$return = array();
|
||||
|
||||
foreach($items as $item) {
|
||||
$i = array();
|
||||
$i['instanceId'] = $xpath->evaluate('string(ec2:instanceId/text())', $item);
|
||||
$i['bundleId'] = $xpath->evaluate('string(ec2:bundleId/text())', $item);
|
||||
$i['state'] = $xpath->evaluate('string(ec2:state/text())', $item);
|
||||
$i['startTime'] = $xpath->evaluate('string(ec2:startTime/text())', $item);
|
||||
$i['updateTime'] = $xpath->evaluate('string(ec2:updateTime/text())', $item);
|
||||
$i['progress'] = $xpath->evaluate('string(ec2:progress/text())', $item);
|
||||
$i['storage']['s3']['bucket'] = $xpath->evaluate('string(ec2:storage/ec2:S3/ec2:bucket/text())', $item);
|
||||
$i['storage']['s3']['prefix'] = $xpath->evaluate('string(ec2:storage/ec2:S3/ec2:prefix/text())', $item);
|
||||
|
||||
$return[] = $i;
|
||||
unset($i);
|
||||
}
|
||||
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the S3 Upload Policy Information
|
||||
*
|
||||
* @param string $bucketName Which bucket you want the ami to live in on S3
|
||||
* @param string $prefix The prefix you want to assign to the AMI on S3
|
||||
* @param integer $expireInMinutes The expiration of the upload policy. Amazon recommends 12 hours or longer.
|
||||
* This is based in nubmer of minutes. Default is 1440 minutes (24 hours)
|
||||
* @return string Base64 encoded string that is the upload policy
|
||||
*/
|
||||
protected function _getS3UploadPolicy($bucketName, $prefix, $expireInMinutes = 1440)
|
||||
{
|
||||
$arrParams = array();
|
||||
$arrParams['expiration'] = gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", (time() + ($expireInMinutes * 60)));
|
||||
$arrParams['conditions'][] = array('bucket' => $bucketName);
|
||||
$arrParams['conditions'][] = array('acl' => 'ec2-bundle-read');
|
||||
$arrParams['conditions'][] = array('starts-with', '$key', $prefix);
|
||||
|
||||
return base64_encode(Zend_Json::encode($arrParams));
|
||||
}
|
||||
|
||||
/**
|
||||
* Signed S3 Upload Policy
|
||||
*
|
||||
* @param string $policy Base64 Encoded string that is the upload policy
|
||||
* @return string SHA1 encoded S3 Upload Policy
|
||||
*/
|
||||
protected function _signS3UploadPolicy($policy)
|
||||
{
|
||||
$hmac = Zend_Crypt_Hmac::compute($this->_getSecretKey(), 'SHA1', $policy, Zend_Crypt_Hmac::BINARY);
|
||||
return $hmac;
|
||||
}
|
||||
}
|
137
airtime_mvc/library/Zend/Service/Amazon/Ec2/Keypair.php
Normal file
137
airtime_mvc/library/Zend/Service/Amazon/Ec2/Keypair.php
Normal file
|
@ -0,0 +1,137 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Keypair.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Service_Amazon_Ec2_Abstract
|
||||
*/
|
||||
require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
|
||||
|
||||
/**
|
||||
* An Amazon EC2 interface to create, delete and describe Ec2 KeyPairs.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Ec2_Keypair extends Zend_Service_Amazon_Ec2_Abstract
|
||||
{
|
||||
/**
|
||||
* Creates a new 2048 bit RSA key pair and returns a unique ID that can
|
||||
* be used to reference this key pair when launching new instances.
|
||||
*
|
||||
* @param string $keyName A unique name for the key pair.
|
||||
* @throws Zend_Service_Amazon_Ec2_Exception
|
||||
* @return array
|
||||
*/
|
||||
public function create($keyName)
|
||||
{
|
||||
$params = array();
|
||||
|
||||
$params['Action'] = 'CreateKeyPair';
|
||||
|
||||
if(!$keyName) {
|
||||
require_once 'Zend/Service/Amazon/Ec2/Exception.php';
|
||||
throw new Zend_Service_Amazon_Ec2_Exception('Invalid Key Name');
|
||||
}
|
||||
|
||||
$params['KeyName'] = $keyName;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$return = array();
|
||||
$return['keyName'] = $xpath->evaluate('string(//ec2:keyName/text())');
|
||||
$return['keyFingerprint'] = $xpath->evaluate('string(//ec2:keyFingerprint/text())');
|
||||
$return['keyMaterial'] = $xpath->evaluate('string(//ec2:keyMaterial/text())');
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information about key pairs available to you. If you specify
|
||||
* key pairs, information about those key pairs is returned. Otherwise,
|
||||
* information for all registered key pairs is returned.
|
||||
*
|
||||
* @param string|rarray $keyName Key pair IDs to describe.
|
||||
* @return array
|
||||
*/
|
||||
public function describe($keyName = null)
|
||||
{
|
||||
$params = array();
|
||||
|
||||
$params['Action'] = 'DescribeKeyPairs';
|
||||
if(is_array($keyName) && !empty($keyName)) {
|
||||
foreach($keyName as $k=>$name) {
|
||||
$params['KeyName.' . ($k+1)] = $name;
|
||||
}
|
||||
} elseif($keyName) {
|
||||
$params['KeyName.1'] = $keyName;
|
||||
}
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$nodes = $xpath->query('//ec2:keySet/ec2:item');
|
||||
|
||||
$return = array();
|
||||
foreach ($nodes as $k => $node) {
|
||||
$item = array();
|
||||
$item['keyName'] = $xpath->evaluate('string(ec2:keyName/text())', $node);
|
||||
$item['keyFingerprint'] = $xpath->evaluate('string(ec2:keyFingerprint/text())', $node);
|
||||
|
||||
$return[] = $item;
|
||||
unset($item);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a key pair
|
||||
*
|
||||
* @param string $keyName Name of the key pair to delete.
|
||||
* @throws Zend_Service_Amazon_Ec2_Exception
|
||||
* @return boolean Return true or false from the deletion.
|
||||
*/
|
||||
public function delete($keyName)
|
||||
{
|
||||
$params = array();
|
||||
|
||||
$params['Action'] = 'DeleteKeyPair';
|
||||
|
||||
if(!$keyName) {
|
||||
require_once 'Zend/Service/Amazon/Ec2/Exception.php';
|
||||
throw new Zend_Service_Amazon_Ec2_Exception('Invalid Key Name');
|
||||
}
|
||||
|
||||
$params['KeyName'] = $keyName;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
$success = $xpath->evaluate('string(//ec2:return/text())');
|
||||
|
||||
return ($success === "true");
|
||||
}
|
||||
}
|
77
airtime_mvc/library/Zend/Service/Amazon/Ec2/Region.php
Normal file
77
airtime_mvc/library/Zend/Service/Amazon/Ec2/Region.php
Normal file
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Region.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Service_Amazon_Ec2_Abstract
|
||||
*/
|
||||
require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
|
||||
|
||||
/**
|
||||
* An Amazon EC2 interface to query which Regions your account has access to.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Ec2_Region extends Zend_Service_Amazon_Ec2_Abstract
|
||||
{
|
||||
|
||||
/**
|
||||
* Describes availability zones that are currently available to the account
|
||||
* and their states.
|
||||
*
|
||||
* @param string|array $region Name of an region.
|
||||
* @return array An array that contains all the return items. Keys: regionName and regionUrl.
|
||||
*/
|
||||
public function describe($region = null)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'DescribeRegions';
|
||||
|
||||
if(is_array($region) && !empty($region)) {
|
||||
foreach($region as $k=>$name) {
|
||||
$params['Region.' . ($k+1)] = $name;
|
||||
}
|
||||
} elseif($region) {
|
||||
$params['Region.1'] = $region;
|
||||
}
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
|
||||
$xpath = $response->getXPath();
|
||||
$nodes = $xpath->query('//ec2:item');
|
||||
|
||||
$return = array();
|
||||
foreach ($nodes as $k => $node) {
|
||||
$item = array();
|
||||
$item['regionName'] = $xpath->evaluate('string(ec2:regionName/text())', $node);
|
||||
$item['regionUrl'] = $xpath->evaluate('string(ec2:regionUrl/text())', $node);
|
||||
|
||||
$return[] = $item;
|
||||
unset($item);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
163
airtime_mvc/library/Zend/Service/Amazon/Ec2/Response.php
Normal file
163
airtime_mvc/library/Zend/Service/Amazon/Ec2/Response.php
Normal file
|
@ -0,0 +1,163 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Response.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Http_Response
|
||||
*/
|
||||
require_once 'Zend/Http/Response.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Ec2_Response {
|
||||
/**
|
||||
* XML namespace used for EC2 responses.
|
||||
*/
|
||||
protected $_xmlNamespace = 'http://ec2.amazonaws.com/doc/2009-04-04/';
|
||||
|
||||
/**
|
||||
* The original HTTP response
|
||||
*
|
||||
* This contains the response body and headers.
|
||||
*
|
||||
* @var Zend_Http_Response
|
||||
*/
|
||||
private $_httpResponse = null;
|
||||
|
||||
/**
|
||||
* The response document object
|
||||
*
|
||||
* @var DOMDocument
|
||||
*/
|
||||
private $_document = null;
|
||||
|
||||
/**
|
||||
* The response XPath
|
||||
*
|
||||
* @var DOMXPath
|
||||
*/
|
||||
private $_xpath = null;
|
||||
|
||||
/**
|
||||
* Last error code
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $_errorCode = 0;
|
||||
|
||||
/**
|
||||
* Last error message
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_errorMessage = '';
|
||||
|
||||
/**
|
||||
* Creates a new high-level EC2 response object
|
||||
*
|
||||
* @param Zend_Http_Response $httpResponse the HTTP response.
|
||||
*/
|
||||
public function __construct(Zend_Http_Response $httpResponse)
|
||||
{
|
||||
$this->_httpResponse = $httpResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the XPath object for this response
|
||||
*
|
||||
* @return DOMXPath the XPath object for response.
|
||||
*/
|
||||
public function getXPath()
|
||||
{
|
||||
if ($this->_xpath === null) {
|
||||
$document = $this->getDocument();
|
||||
if ($document === false) {
|
||||
$this->_xpath = false;
|
||||
} else {
|
||||
$this->_xpath = new DOMXPath($document);
|
||||
$this->_xpath->registerNamespace('ec2',
|
||||
$this->getNamespace());
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_xpath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the document object for this response
|
||||
*
|
||||
* @return DOMDocument the DOM Document for this response.
|
||||
*/
|
||||
public function getDocument()
|
||||
{
|
||||
try {
|
||||
$body = $this->_httpResponse->getBody();
|
||||
} catch (Zend_Http_Exception $e) {
|
||||
$body = false;
|
||||
}
|
||||
|
||||
if ($this->_document === null) {
|
||||
if ($body !== false) {
|
||||
// turn off libxml error handling
|
||||
$errors = libxml_use_internal_errors();
|
||||
|
||||
$this->_document = new DOMDocument();
|
||||
if (!$this->_document->loadXML($body)) {
|
||||
$this->_document = false;
|
||||
}
|
||||
|
||||
// reset libxml error handling
|
||||
libxml_clear_errors();
|
||||
libxml_use_internal_errors($errors);
|
||||
} else {
|
||||
$this->_document = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_document;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current set XML Namespace.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNamespace()
|
||||
{
|
||||
return $this->_xmlNamespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a new XML Namespace
|
||||
*
|
||||
* @param string $namespace
|
||||
*/
|
||||
public function setNamespace($namespace)
|
||||
{
|
||||
$this->_xmlNamespace = $namespace;
|
||||
}
|
||||
|
||||
}
|
301
airtime_mvc/library/Zend/Service/Amazon/Ec2/Securitygroups.php
Normal file
301
airtime_mvc/library/Zend/Service/Amazon/Ec2/Securitygroups.php
Normal file
|
@ -0,0 +1,301 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Securitygroups.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Service_Amazon_Ec2_Abstract
|
||||
*/
|
||||
require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
|
||||
|
||||
/**
|
||||
* An Amazon EC2 interface to create, delete, describe, grand and revoke sercurity permissions.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Service_Amazon
|
||||
* @subpackage Ec2
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Service_Amazon_Ec2_Securitygroups extends Zend_Service_Amazon_Ec2_Abstract
|
||||
{
|
||||
/**
|
||||
* Creates a new security group.
|
||||
*
|
||||
* Every instance is launched in a security group. If no security group is specified
|
||||
* during launch, the instances are launched in the default security group. Instances
|
||||
* within the same security group have unrestricted network access to each other.
|
||||
* Instances will reject network access attempts from other instances in a different
|
||||
* security group. As the owner of instances you can grant or revoke specific permissions
|
||||
* using the {@link authorizeIp}, {@link authorizeGroup}, {@link revokeGroup} and
|
||||
* {$link revokeIp} operations.
|
||||
*
|
||||
* @param string $name Name of the new security group.
|
||||
* @param string $description Description of the new security group.
|
||||
* @return boolean
|
||||
*/
|
||||
public function create($name, $description)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'CreateSecurityGroup';
|
||||
$params['GroupName'] = $name;
|
||||
$params['GroupDescription'] = $description;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
$success = $xpath->evaluate('string(//ec2:return/text())');
|
||||
|
||||
return ($success === "true");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information about security groups that you own.
|
||||
*
|
||||
* If you specify security group names, information about those security group is returned.
|
||||
* Otherwise, information for all security group is returned. If you specify a group
|
||||
* that does not exist, a fault is returned.
|
||||
*
|
||||
* @param string|array $name List of security groups to describe
|
||||
* @return array
|
||||
*/
|
||||
public function describe($name = null)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'DescribeSecurityGroups';
|
||||
if(is_array($name) && !empty($name)) {
|
||||
foreach($name as $k=>$name) {
|
||||
$params['GroupName.' . ($k+1)] = $name;
|
||||
}
|
||||
} elseif($name) {
|
||||
$params['GroupName.1'] = $name;
|
||||
}
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
|
||||
$return = array();
|
||||
|
||||
$nodes = $xpath->query('//ec2:securityGroupInfo/ec2:item');
|
||||
|
||||
foreach($nodes as $node) {
|
||||
$item = array();
|
||||
|
||||
$item['ownerId'] = $xpath->evaluate('string(ec2:ownerId/text())', $node);
|
||||
$item['groupName'] = $xpath->evaluate('string(ec2:groupName/text())', $node);
|
||||
$item['groupDescription'] = $xpath->evaluate('string(ec2:groupDescription/text())', $node);
|
||||
|
||||
$ip_nodes = $xpath->query('ec2:ipPermissions/ec2:item', $node);
|
||||
|
||||
foreach($ip_nodes as $ip_node) {
|
||||
$sItem = array();
|
||||
|
||||
$sItem['ipProtocol'] = $xpath->evaluate('string(ec2:ipProtocol/text())', $ip_node);
|
||||
$sItem['fromPort'] = $xpath->evaluate('string(ec2:fromPort/text())', $ip_node);
|
||||
$sItem['toPort'] = $xpath->evaluate('string(ec2:toPort/text())', $ip_node);
|
||||
|
||||
$ips = $xpath->query('ec2:ipRanges/ec2:item', $ip_node);
|
||||
|
||||
$sItem['ipRanges'] = array();
|
||||
foreach($ips as $ip) {
|
||||
$sItem['ipRanges'][] = $xpath->evaluate('string(ec2:cidrIp/text())', $ip);
|
||||
}
|
||||
|
||||
if(count($sItem['ipRanges']) == 1) {
|
||||
$sItem['ipRanges'] = $sItem['ipRanges'][0];
|
||||
}
|
||||
|
||||
$item['ipPermissions'][] = $sItem;
|
||||
unset($ip_node, $sItem);
|
||||
}
|
||||
|
||||
$return[] = $item;
|
||||
|
||||
unset($item, $node);
|
||||
}
|
||||
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a security group.
|
||||
*
|
||||
* If you attempt to delete a security group that contains instances, a fault is returned.
|
||||
* If you attempt to delete a security group that is referenced by another security group,
|
||||
* a fault is returned. For example, if security group B has a rule that allows access
|
||||
* from security group A, security group A cannot be deleted until the allow rule is removed.
|
||||
*
|
||||
* @param string $name Name of the security group to delete.
|
||||
* @return boolean
|
||||
*/
|
||||
public function delete($name)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'DeleteSecurityGroup';
|
||||
$params['GroupName'] = $name;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
$success = $xpath->evaluate('string(//ec2:return/text())');
|
||||
|
||||
return ($success === "true");
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds permissions to a security group
|
||||
*
|
||||
* Permissions are specified by the IP protocol (TCP, UDP or ICMP), the source of the request
|
||||
* (by IP range or an Amazon EC2 user-group pair), the source and destination port ranges
|
||||
* (for TCP and UDP), and the ICMP codes and types (for ICMP). When authorizing ICMP, -1
|
||||
* can be used as a wildcard in the type and code fields.
|
||||
*
|
||||
* Permission changes are propagated to instances within the security group as quickly as
|
||||
* possible. However, depending on the number of instances, a small delay might occur.
|
||||
*
|
||||
*
|
||||
* @param string $name Name of the group to modify.
|
||||
* @param string $ipProtocol IP protocol to authorize access to when operating on a CIDR IP.
|
||||
* @param integer $fromPort Bottom of port range to authorize access to when operating on a CIDR IP.
|
||||
* This contains the ICMP type if ICMP is being authorized.
|
||||
* @param integer $toPort Top of port range to authorize access to when operating on a CIDR IP.
|
||||
* This contains the ICMP code if ICMP is being authorized.
|
||||
* @param string $cidrIp CIDR IP range to authorize access to when operating on a CIDR IP.
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorizeIp($name, $ipProtocol, $fromPort, $toPort, $cidrIp)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'AuthorizeSecurityGroupIngress';
|
||||
$params['GroupName'] = $name;
|
||||
$params['IpProtocol'] = $ipProtocol;
|
||||
$params['FromPort'] = $fromPort;
|
||||
$params['ToPort'] = $toPort;
|
||||
$params['CidrIp'] = $cidrIp;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
$success = $xpath->evaluate('string(//ec2:return/text())');
|
||||
|
||||
return ($success === "true");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds permissions to a security group
|
||||
*
|
||||
* When authorizing a user/group pair permission, GroupName, SourceSecurityGroupName and
|
||||
* SourceSecurityGroupOwnerId must be specified.
|
||||
*
|
||||
* Permission changes are propagated to instances within the security group as quickly as
|
||||
* possible. However, depending on the number of instances, a small delay might occur.
|
||||
*
|
||||
* @param string $name Name of the group to modify.
|
||||
* @param string $groupName Name of security group to authorize access to when operating on a user/group pair.
|
||||
* @param string $ownerId Owner of security group to authorize access to when operating on a user/group pair.
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorizeGroup($name, $groupName, $ownerId)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'AuthorizeSecurityGroupIngress';
|
||||
$params['GroupName'] = $name;
|
||||
$params['SourceSecurityGroupName'] = $groupName;
|
||||
$params['SourceSecurityGroupOwnerId'] = $ownerId;
|
||||
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
$success = $xpath->evaluate('string(//ec2:return/text())');
|
||||
|
||||
|
||||
return ($success === "true");
|
||||
}
|
||||
|
||||
/**
|
||||
* Revokes permissions from a security group. The permissions used to revoke must be specified
|
||||
* using the same values used to grant the permissions.
|
||||
*
|
||||
* Permissions are specified by the IP protocol (TCP, UDP or ICMP), the source of the request
|
||||
* (by IP range or an Amazon EC2 user-group pair), the source and destination port ranges
|
||||
* (for TCP and UDP), and the ICMP codes and types (for ICMP). When authorizing ICMP, -1
|
||||
* can be used as a wildcard in the type and code fields.
|
||||
*
|
||||
* Permission changes are propagated to instances within the security group as quickly as
|
||||
* possible. However, depending on the number of instances, a small delay might occur.
|
||||
*
|
||||
*
|
||||
* @param string $name Name of the group to modify.
|
||||
* @param string $ipProtocol IP protocol to revoke access to when operating on a CIDR IP.
|
||||
* @param integer $fromPort Bottom of port range to revoke access to when operating on a CIDR IP.
|
||||
* This contains the ICMP type if ICMP is being revoked.
|
||||
* @param integer $toPort Top of port range to revoked access to when operating on a CIDR IP.
|
||||
* This contains the ICMP code if ICMP is being revoked.
|
||||
* @param string $cidrIp CIDR IP range to revoke access to when operating on a CIDR IP.
|
||||
* @return boolean
|
||||
*/
|
||||
public function revokeIp($name, $ipProtocol, $fromPort, $toPort, $cidrIp)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'RevokeSecurityGroupIngress';
|
||||
$params['GroupName'] = $name;
|
||||
$params['IpProtocol'] = $ipProtocol;
|
||||
$params['FromPort'] = $fromPort;
|
||||
$params['ToPort'] = $toPort;
|
||||
$params['CidrIp'] = $cidrIp;
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
$success = $xpath->evaluate('string(//ec2:return/text())');
|
||||
|
||||
return ($success === "true");
|
||||
}
|
||||
|
||||
/**
|
||||
* Revokes permissions from a security group. The permissions used to revoke must be specified
|
||||
* using the same values used to grant the permissions.
|
||||
*
|
||||
* Permission changes are propagated to instances within the security group as quickly as
|
||||
* possible. However, depending on the number of instances, a small delay might occur.
|
||||
*
|
||||
* When revoking a user/group pair permission, GroupName, SourceSecurityGroupName and
|
||||
* SourceSecurityGroupOwnerId must be specified.
|
||||
*
|
||||
* @param string $name Name of the group to modify.
|
||||
* @param string $groupName Name of security group to revoke access to when operating on a user/group pair.
|
||||
* @param string $ownerId Owner of security group to revoke access to when operating on a user/group pair.
|
||||
* @return boolean
|
||||
*/
|
||||
public function revokeGroup($name, $groupName, $ownerId)
|
||||
{
|
||||
$params = array();
|
||||
$params['Action'] = 'RevokeSecurityGroupIngress';
|
||||
$params['GroupName'] = $name;
|
||||
$params['SourceSecurityGroupName'] = $groupName;
|
||||
$params['SourceSecurityGroupOwnerId'] = $ownerId;
|
||||
|
||||
|
||||
$response = $this->sendRequest($params);
|
||||
$xpath = $response->getXPath();
|
||||
$success = $xpath->evaluate('string(//ec2:return/text())');
|
||||
|
||||
|
||||
return ($success === "true");
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue