Index: aws_ec2/aws_ec2.module
===================================================================
RCS file: aws_ec2/aws_ec2.module
diff -N aws_ec2/aws_ec2.module
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ aws_ec2/aws_ec2.module	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,404 @@
+<?php
+// $Id$
+
+/**
+ * @file 
+ *   Provides easy API hook functionality for other Drupal modules
+ *   wanting to access AWS Elastic Compute Cloud (EC2)
+ */
+
+
+/* *************************  drupal functions    *****************************/ 
+
+/**
+ * Implementation of hook_perm()
+ * @return array An array of valid permissions for the aws module
+ */
+function aws_ec2_perm() {
+  return array(
+    'administer aws ec2', 
+    'access ec2 instances',
+    'create ec2 instances',
+    'change ec2 instances',
+    'delete ec2 instances',
+  );
+}
+
+/**
+ * Implementation hook_menu()
+ * @return array A menu api array for the module
+ */
+function aws_ec2_menu($may_cache) {
+  $items = array();
+  if ($may_cache) {
+    $items[] = array(
+      'path' => 'admin/settings/aws/ec2',
+      'title' => t('EC2'),
+      'description' => t('AWS Elastic Compute Cloud'),
+      'callback' => 'drupal_get_form',
+      'callback arguments' => 'aws_ec2_admin_settings',
+      'type' => MENU_LOCAL_TASK,
+      'access' => user_access('administer aws ec2')
+    );
+  }
+  return $items;
+}
+
+/**
+ * Implementation admin_settings()
+ * @return array A form api array of the admin setting
+ */
+function aws_ec2_admin_settings() {
+  $form['aws_ec2_host'] = array(
+    '#type' => 'textfield',
+    '#title' => t('EC2 Host'),
+    '#default_value' => variable_get('aws_ec2_host', 'ec2.amazonaws.com'),
+    '#size' => 30,
+    '#description' => t('AWS EC2 host. If you are unsure about this leave it set to ec2.amazonaws.com')
+  );
+  return system_settings_form($form);
+}
+
+
+/* **************************    aws functions    ****************************/
+
+/**
+ * Registers an AMI with Amazon EC2. Images must be registered before they can be launched
+ * @param location  string  Full path to your AMI manifest in Amazon S3 storage.
+ * @return std class object containing response headers & raw body
+ */
+function aws_ec2_RegisterImage($location) {
+  $host = variable_get('aws_ec2_host', 'ec2.amazonaws.com');
+  $request = array(
+    'method' => 'QUERY',
+    'Action' => 'RegisterImage',
+    'ImageLocation' => $location
+  );
+  return aws_queryRequest($host, $request);
+}
+
+/**
+ * Returns information about AMIs available to the user. This includes public AMIs available 
+ * for any user to launch, private AMIs owned by the user making the request, and private AMIs 
+ * owned by other users for which the user has explicit launch permissions.
+ * @param images  array  A list of image descriptions
+ * @param owners  array  Owners of AMIs to describe.
+ * @param users    array  Users who have access.
+ * @return object std class object containing response headers & raw body
+ */
+function aws_ec2_DescribeImages($images = array(), $owners = array(), $users = array()) {
+  $host = variable_get('aws_ec2_host', 'ec2.amazonaws.com');
+  $request = array(
+    'Action' => 'DescribeImages',
+    'Version' => variable_get('ec2_api_version', '2007-08-29'),
+  );
+  $request = array_merge($request, aws_numberKeys('ImageId', $images));
+  $request = array_merge($request, aws_numberKeys('Owner', $owners));
+  $request = array_merge($request, aws_numberKeys('ExecutableBy', $users));
+  return aws_queryRequest($host, $request);
+}
+
+/**
+ * Deregisters an AMI. Once deregistered, instances of the AMI can no longer be launched.
+ * @param imageid  string  Unique ID of a machine image, returned by a call to aws_ec2_RegisterImage or aws_ec2_DescribeImages.
+ * @return object std class object containing response headers & raw body
+ */
+function aws_ec2_DeregisterImage($imageid) {
+  $host = variable_get('aws_ec2_host', 'ec2.amazonaws.com');
+  $request = array(
+    'Action' => 'DeregisterImage',
+    'ImageId' => $imageid,
+    'Version' => variable_get('ec2_api_version', '2007-08-29'),
+  );
+  return aws_queryRequest($host, $request);
+}
+
+/**
+ * Launches a specified number of instances.
+ * @param imageid  string  ID of the AMI with which to launch instances.
+ * @param min      int      Minimum number of instances to launch.
+ * @param  max      int      Maximum number of instances to launch.
+ * @param  keyname  string  Name of the key pair with which to launch instances.
+ * @param groups  array    Names of the security groups with which to associate the instances.
+ * @param data    string  The user data available to the launched instances.
+ * @param  type    string  This specifies the instance type.  Options include m1.small, m1.large, and m1.xlarge.
+ * @return object std class object containing response headers & raw body
+ */
+function aws_ec2_RunInstances($imageid, $min, $max, $keyname = NULL, $groups = array(), $data = NULL, $type = NULL) {
+  $host = variable_get('aws_ec2_host', 'ec2.amazonaws.com');
+  $request = array(
+    'Action' => 'RunInstances',
+    'ImageId' => $imageid,
+    'MinCount' => $min,
+    'MaxCount' => $max,
+    'KeyName' => $keyname,
+    'UserData' => drupal_urlencode($data),
+    'InstanceType' => $type,
+    'Version' => variable_get('ec2_api_version', '2007-08-29'),
+  );
+  $request = array_merge($request, aws_numberKeys('SecurityGroup', $groups));
+  return aws_queryRequest($host, $request);
+}
+
+/**
+ * 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.
+ * @param instances  array  A list of instance IDs.
+ * @return object std class object containing response headers & raw body
+ */
+function aws_ec2_DescribeInstances($instances = array()) {
+  $host = variable_get('aws_ec2_host', 'ec2.amazonaws.com');
+  $request = array(
+    'Action' => 'DescribeInstances',
+    'Version' => variable_get('ec2_api_version', '2007-08-29'),
+  );
+  $request = array_merge($request, aws_numberKeys('InstanceId', $instances));
+  return aws_queryRequest($host, $request);
+}
+
+/**
+ * Shuts down one or more instances. This operation is idempotent; if you terminate an instance more than once, each call will succeed.
+ * @param instances  array  One or more instance IDs.
+ * @return object std class object containing response headers & raw body
+ */
+function aws_ec2_TerminateInstances($instances) {
+  $host = variable_get('aws_ec2_host', 'ec2.amazonaws.com');
+  $request = array(
+    'Action' => 'TerminateInstances',
+    'Version' => variable_get('ec2_api_version', '2007-08-29'),
+  );
+  $request = array_merge($request, aws_numberKeys('InstanceId', $instances));
+  return aws_queryRequest($host, $request);
+}  
+
+/**
+ * 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.  This feature is useful when an AMI owner is providing 
+ * support and wants to verify whether a user's instance is eligible.
+ * @param productcode  string  The product code to confirm.
+ * @param instanceid  int      The instance for which to confirm the product code.
+ * @return object std class object containing response headers & raw body
+ */
+function aws_ec2_ConfirmProductInstance($imageid, $min, $max, $keyname = NULL, $groups = array(), $data = NULL, $type = NULL) {
+  $host = variable_get('aws_ec2_host', 'ec2.amazonaws.com');
+  $request = array(
+    'Action' => 'ConfirmProductInstance',
+    'ProductCode' => $imageid,
+    'InstanceId' => $min,
+    'Version' => variable_get('ec2_api_version', '2007-08-29'),
+  );
+  return aws_queryRequest($host, $request);
+}  
+
+/**
+ * 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 keyname  string  A unique name for the key pair.
+ * @return object std class object containing response headers & raw body
+ */
+function aws_ec2_CreateKeyPair($keyname) {
+  $host = variable_get('aws_ec2_host', 'ec2.amazonaws.com');
+  $request = array(
+    'Action' => 'CreateKeyPair',
+    'KeyName' => $keyname,
+    'Version' => variable_get('ec2_api_version', '2007-08-29'),
+  );
+  return aws_queryRequest($host, $request);
+}  
+
+/**
+ * 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 keyname  string  Key pair IDs to describe.
+ * @return object std class object containing response headers & raw body
+ */
+function aws_ec2_DescribeKeyPairs($keyname = array()) {
+  $host = variable_get('aws_ec2_host', 'ec2.amazonaws.com');
+  $request = array(
+    'Action' => 'DescribeKeyPairs',
+    'Version' => variable_get('ec2_api_version', '2007-08-29'),
+  );
+  $request = array_merge($request, aws_numberKeys('KeyName', $keyname));
+  return aws_queryRequest($host, $request);
+}  
+
+/**
+ * Deletes a key pair.
+ * @param keyname  string  Name of the key pair to delete.
+ * @return object std class object containing response headers & raw body
+ */
+function aws_ec2_DeleteKeyPair($keyname) {
+  $host = variable_get('aws_ec2_host', 'ec2.amazonaws.com');
+  $request = array(
+    'Action' => 'DeleteKeyPair',
+    'KeyName' => $keyname,
+    'Version' => variable_get('ec2_api_version', '2007-08-29'),
+  );
+  return aws_queryRequest($host, $request);
+}  
+
+/**
+ * Modifies an attribute of an AMI.
+ * @param imageid  string  AMI ID to modify.
+ * @param attribute  string Specifies the attribute to modify. 'launchPermission' and 'productCodes' supported.
+ * @param  optype    stringSpecifies the operation to perform on the attribute. 'add' and 'remove' supported.
+ * @param  users      array  User IDs to add to or remove from the launchPermission attribute.
+ * @param groups    array  User groups to add to or remove from the launchPermission attribute. Currently, the all group is available, which will make it a public AMI.
+ * @param products  array  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.
+ * @return object std class object containing response headers & raw body
+ */
+function aws_ec2_ModifyImageAttribute($imageid, $attribute, $optype = NULL, $users = array(), $groups = array(), $products = array()) {
+  $host = variable_get('aws_ec2_host', 'ec2.amazonaws.com');
+  $request = array(
+    'Action' => 'ModifyImageAttribute',
+    'ImageId' => $imageid,
+    'Attribute' => $attribute,
+    'OperationType' => $optype,
+    'Version' => variable_get('ec2_api_version', '2007-08-29'),
+  );
+  $request = array_merge($request, aws_numberKeys('UserId', $users));
+  $request = array_merge($request, aws_numberKeys('UserGroup', $groups));
+  $request = array_merge($request, aws_numberKeys('ProductCode', $products));
+  return aws_queryRequest($host, $request);
+}  
+
+/**
+ * Returns information about an attribute of an AMI. Only one attribute can be specified per call.
+ * @param imageid  string  ID of the AMI for which an attribute will be described.
+ * @param attribute  string Specifies the attribute to describe. 'launchPermission' and 'productCodes' supported.
+ * @return object std class object containing response headers & raw body
+ */
+function aws_ec2_DescribeImageAttribute($imageid, $attribute) {
+  $host = variable_get('aws_ec2_host', 'ec2.amazonaws.com');
+  $request = array(
+    'Action' => 'DescribeImageAttribute',
+    'ImageId' => $imageid,
+    'Attribute' => $attribute,
+    'Version' => variable_get('ec2_api_version', '2007-08-29'),
+  );
+  return aws_queryRequest($host, $request);
+}  
+
+/**
+ * Resets an attribute of an AMI to its default value.  The productCodes attribute cannot be reset.
+ * @param imageid  string  ID of the AMI for which an attribute will be reset.
+ * @param attribute  string 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 object std class object containing response headers & raw body
+ */
+function aws_ec2_ResetImageAttribute($imageid, $attribute) {
+  $host = variable_get('aws_ec2_host', 'ec2.amazonaws.com');
+  $request = array(
+    'Action' => 'ResetImageAttribute',
+    'ImageId' => $imageid,
+    'Attribute' => $attribute,
+    'Version' => variable_get('ec2_api_version', '2007-08-29'),
+  );
+  return aws_queryRequest($host, $request);
+}  
+
+/**
+ * Creates a new security group.
+ * @param name  string  Name of the new security group.
+ * @param  description  string  Description of the new security group.
+ * @return object std class object containing response headers & raw body
+ */
+function aws_ec2_CreateSecurityGroup($name, $description) {
+  $host = variable_get('aws_ec2_host', 'ec2.amazonaws.com');
+  $request = array(
+    'Action' => 'CreateSecurityGroup',
+    'GroupName' => $name,
+    'GroupDescription' => $description,
+    'Version' => variable_get('ec2_api_version', '2007-08-29'),
+  );
+  return aws_queryRequest($host, $request);
+}  
+
+/**
+ * Returns information about security groups that you own.
+ * @param groups  string  List of security groups to describe.
+ * @return object std class object containing response headers & raw body
+ */
+function aws_ec2_DescribeSecurityGroups($groups) {
+  $host = variable_get('aws_ec2_host', 'ec2.amazonaws.com');
+  $request = array(
+    'Action' => 'DescribeSecurityGroups',
+    'Version' => variable_get('ec2_api_version', '2007-08-29'),
+  );
+  if (! is_array($groups)) {
+    $groups[] = $groups;
+  }
+  $request = array_merge($request, aws_numberKeys('GroupName', $groups));
+  return aws_queryRequest($host, $request);
+}  
+
+/**
+ * Deletes a security group.
+ * @param name  string  Name of the security group to delete.
+ * @return object std class object containing response headers & raw body
+ */
+function aws_ec2_DeleteSecurityGroup($name) {
+  $host = variable_get('aws_ec2_host', 'ec2.amazonaws.com');
+  $request = array(
+    'Action' => 'DeleteSecurityGroup',
+    'GroupName' => $name,
+    'Version' => variable_get('ec2_api_version', '2007-08-29'),
+  );
+  return aws_queryRequest($host, $request);
+}  
+
+/**
+ * Adds permissions to a security group.
+ * @param name  string  Name of the group to modify.
+ * @param sourcename  string  Name of security group to authorize access to when operating on a user/group pair.
+ * @param  sourceowner  string  Owner of security group to authorize access to when operating on a user/group pair.
+ * @param  proto  string  IP protocol to authorize access to when operating on a CIDR IP.  "tcp", "udp" and "icmp" allowed.
+ * @param fromport  string  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 toport  string  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  srcip  string  CIDR IP range to authorize access to when operating on a CIDR IP.
+ * @return object std class object containing response headers & raw body
+ */
+function aws_ec2_AuthorizeSecurityGroupIngress($name, $sourcename, $sourceowner, $proto = NULL, $fromport = NULL, $toport = NULL, $srcip = NULL) {
+  $host = variable_get('aws_ec2_host', 'ec2.amazonaws.com');
+  $request = array(
+    'Action' => 'AuthorizeSecurityGroupIngress',
+    'GroupName' => $name,
+    'SourceSecurityGroupName' => $sourcename,
+    'SourceSecurityGroupOwnerId' => $sourceowner,
+    'IpProtocol' => $proto,
+    'FromPort' => $fromport,
+    'ToPort' => $toport,
+    'CidrIp' => $srcip,
+    'Version' => variable_get('ec2_api_version', '2007-08-29'),
+  );
+  return aws_queryRequest($host, $request);
+}  
+
+/**
+ * Revokes permissions from a security group. The permissions used to revoke must be specified using the same values used to grant the permissions.
+ * @param name  string  Name of the group to modify.
+ * @param sourcename  string  Name of security group to revoke access to when operating on a user/group pair.
+ * @param  sourceowner  string  Owner of security group to revoke access to when operating on a user/group pair.
+ * @param  proto  string  IP protocol to revoke access to when operating on a CIDR IP.  "tcp", "udp" and "icmp" allowed.
+ * @param fromport  string  Bottom of port range to revoke access to when operating on a CIDR IP. This contains the ICMP type if ICMP is being authorized.
+ * @param toport  string  Top of port range to revoke access to when operating on a CIDR IP. This contains the ICMP code if ICMP is being authorized.
+ * @param  srcip  string  CIDR IP range to revoke access to when operating on a CIDR IP.
+ * @return object std class object containing response headers & raw body
+ */
+function aws_ec2_RevokeSecurityGroupIngress($name, $sourcename, $sourceowner, $proto = NULL, $fromport = NULL, $toport = NULL, $srcip = NULL) {
+  $host = variable_get('aws_ec2_host', 'ec2.amazonaws.com');
+  $request = array(
+    'Action' => 'RevokeSecurityGroupIngress',
+    'GroupName' => $name,
+    'SourceSecurityGroupName' => $sourcename,
+    'SourceSecurityGroupOwnerId' => $sourceowner,
+    'IpProtocol' => $proto,
+    'FromPort' => $fromport,
+    'ToPort' => $toport,
+    'CidrIp' => $srcip,
+    'Version' => variable_get('ec2_api_version', '2007-08-29'),
+  );
+  return aws_queryRequest($host, $request);
+}  
+
+?>
Index: aws_ec2/aws_ec2.info
===================================================================
RCS file: aws_ec2/aws_ec2.info
diff -N aws_ec2/aws_ec2.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ aws_ec2/aws_ec2.info	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,5 @@
+; $Id$
+name = AWS EC2 API
+description = AWS Elastic Compute Cloud API
+dependencies = aws
+package = Amazon Web Services
Index: aws_ec2/aws_ec2.install
===================================================================
RCS file: aws_ec2/aws_ec2.install
diff -N aws_ec2/aws_ec2.install
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ aws_ec2/aws_ec2.install	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,8 @@
+<?php
+// $Id$
+
+function aws_ec2_uninstall() {
+ 	variable_del('aws_ec2_host');
+}
+
+?>
Index: aws_ec2/README.txt
===================================================================
RCS file: aws_ec2/README.txt
diff -N aws_ec2/README.txt
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ aws_ec2/README.txt	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,5 @@
+The Amazon EC2 API provides a API for managing resources within Amazon's Amazon Elastic Compute Cloud.
+
+The API follows the naming conventions and parameters described in Amazon's documentation, available at:
+http://docs.amazonwebservices.com/AWSEC2/2007-08-29/DeveloperGuide/
+
