### Eclipse Workspace Patch 1.0
#P aws
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,437 @@
+<?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')
+		);
+		// Test driver
+		$items[] = array(
+			'path' => 'aws/ec2',
+			'callback' => 'aws_ec2_test',
+			'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);
+}
+
+
+function aws_ec2_test() {
+  $images = array('aki-3fde3b56', 'aki-a9d732c0');
+  $result = aws_ec2_DescribeImages($images);
+  print_r($result);
+  
+}
+
+/* **************************    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) {
+  // Required parameters
+  $request = array(
+  	'method' => 'QUERY',
+		'Action' => 'RegisterImage',
+    'ImageLocation' => $location
+	);
+	return aws_request($request, $headers);
+}
+
+/**
+ * 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()) {
+  $headers = array(
+    'host' => variable_get('aws_ec2_host', 'ec2.amazonaws.com'),
+	);
+	$request = array(
+	  'Action' => 'DescribeImages',
+  );
+	$request = array_merge($request, aws_arraytorequest('ImageId', $images));
+	$request = array_merge($request, aws_arraytorequest('Owner', $owners));
+	$request = array_merge($request, aws_arraytorequest('ExecutableBy', $users));
+	return aws_request($request, $headers);
+}
+
+/**
+ * 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) {
+  $headers = array(
+    'host' => variable_get('aws_ec2_host', 'ec2.amazonaws.com'),
+	);
+	$request = array(
+	  'Action' => 'DeregisterImage',
+	  'ImageId' => $imageid,
+  );
+	return aws_request($request, $headers);
+}
+
+/**
+ * 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) {
+  $headers = array(
+    '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,
+  );
+	$request = array_merge($request, aws_arraytorequest('SecurityGroup', $groups));
+	return aws_request($request, $headers);
+}
+
+/**
+ * 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()) {
+  $headers = array(
+    'host' => variable_get('aws_ec2_host', 'ec2.amazonaws.com'),
+	);
+	$request = array(
+	  'Action' => 'DescribeInstances',
+	);
+	$request = array_merge($request, aws_arraytorequest('InstanceId', $instances));
+	return aws_request($request, $headers);
+}
+
+/**
+ * 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) {
+  $headers = array(
+    'host' => variable_get('aws_ec2_host', 'ec2.amazonaws.com'),
+	);
+	$request = array(
+	  'Action' => 'TerminateInstances',
+  );
+  if (! is_array($instances)) {
+    $instances[] = $instances;
+  }
+	$request = array_merge($request, aws_arraytorequest('InstanceId', $instances));
+	return aws_request($request, $headers);
+}	
+
+/**
+ * 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) {
+  $headers = array(
+    'host' => variable_get('aws_ec2_host', 'ec2.amazonaws.com'),
+	);
+	$request = array(
+	  'Action' => 'ConfirmProductInstance',
+	  'ProductCode' => $imageid,
+	  'InstanceId' => $min,
+  );
+	return aws_request($request, $headers);
+}	
+
+/**
+ * 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) {
+  $headers = array(
+    'host' => variable_get('aws_ec2_host', 'ec2.amazonaws.com'),
+	);
+	$request = array(
+	  'Action' => 'CreateKeyPair',
+	  'KeyName' => $keyname,
+  );
+	return aws_request($request, $headers);
+}	
+
+/**
+ * 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()) {
+  $headers = array(
+    'host' => variable_get('aws_ec2_host', 'ec2.amazonaws.com'),
+	);
+	$request = array(
+	  'Action' => 'DescribeKeyPairs',
+  );
+	$request = array_merge($request, aws_arraytorequest('KeyName', $keyname));
+	return aws_request($request, $headers);
+}	
+
+/**
+ * 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) {
+  $headers = array(
+    'host' => variable_get('aws_ec2_host', 'ec2.amazonaws.com'),
+	);
+	$request = array(
+	  'Action' => 'DeleteKeyPair',
+	  'KeyName' => $keyname,
+  );
+	return aws_request($request, $headers);
+}	
+
+/**
+ * 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()) {
+  $headers = array(
+    'host' => variable_get('aws_ec2_host', 'ec2.amazonaws.com'),
+	);
+	$request = array(
+	  'Action' => 'ModifyImageAttribute',
+	  'ImageId' => $imageid,
+	  'Attribute' => $attribute,
+	  'OperationType' => $optype,
+  );
+	$request = array_merge($request, aws_arraytorequest('UserId', $users));
+	$request = array_merge($request, aws_arraytorequest('UserGroup', $groups));
+	$request = array_merge($request, aws_arraytorequest('ProductCode', $products));
+	return aws_request($request, $headers);
+}	
+
+/**
+ * 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) {
+  $headers = array(
+    'host' => variable_get('aws_ec2_host', 'ec2.amazonaws.com'),
+	);
+	$request = array(
+	  'Action' => 'DescribeImageAttribute',
+	  'ImageId' => $imageid,
+	  'Attribute' => $attribute,
+  );
+	return aws_request($request, $headers);
+}	
+
+/**
+ * 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) {
+  $headers = array(
+    'host' => variable_get('aws_ec2_host', 'ec2.amazonaws.com'),
+	);
+	$request = array(
+	  'Action' => 'ResetImageAttribute',
+	  'ImageId' => $imageid,
+	  'Attribute' => $attribute,
+  );
+	return aws_request($request, $headers);
+}	
+
+/**
+ * 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) {
+  $headers = array(
+    'host' => variable_get('aws_ec2_host', 'ec2.amazonaws.com'),
+	);
+	$request = array(
+	  'Action' => 'CreateSecurityGroup',
+	  'GroupName' => $name,
+	  'GroupDescription' => $description,
+  );
+	return aws_request($request, $headers);
+}	
+
+/**
+ * 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) {
+  $headers = array(
+    'host' => variable_get('aws_ec2_host', 'ec2.amazonaws.com'),
+	);
+	$request = array(
+	  'Action' => 'DescribeSecurityGroups',
+  );
+  if (! is_array($groups)) {
+    $groups[] = $groups;
+  }
+	$request = array_merge($request, aws_arraytorequest('GroupName', $groups));
+	return aws_request($request, $headers);
+}	
+
+/**
+ * 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) {
+  $headers = array(
+    'host' => variable_get('aws_ec2_host', 'ec2.amazonaws.com'),
+	);
+	$request = array(
+	  'Action' => 'DeleteSecurityGroup',
+	  'GroupName' => $name,
+  );
+	return aws_request($request, $headers);
+}	
+
+/**
+ * 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) {
+  $headers = array(
+    '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,
+  );
+	return aws_request($request, $headers);
+}	
+
+/**
+ * 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) {
+  $headers = array(
+    '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,
+  );
+	return aws_request($request, $headers);
+}	
+
+?>
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,17 @@
+<?php
+// $Id: aws_s3.install,v 1.1 2008/01/06 20:06:31 dragonwize Exp $
+
+function aws_ec2_install() {
+//	$host = variable_get('aws_s3_host', 's3.amazonaws.com');
+//	variable_set('aws_s3_host', $host);
+//	$bucket = variable_get('aws_s3_default_bucket', 'drupal-aws-s3');
+//	variable_set('aws_s3_default_bucket', $bucket);
+}
+
+
+function aws_ec2_uninstall() {
+// 	variable_del('aws_s3_host');
+// 	variable_del('aws_s3_default_bucket');
+}
+
+?>
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,2 @@
+This module is still in development but if you want to get your hands dirty check 
+out the docs in aws_ec2.module.
