You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by wo...@apache.org on 2010/10/05 20:30:38 UTC

svn commit: r1004763 - in /incubator/libcloud/sandbox/java/trunk/src/libcloud: DriverFactory.java providers/amazon/EC2Connection.java providers/amazon/EC2Driver.java providers/amazon/EucalyptusDriver.java

Author: woodser
Date: Tue Oct  5 18:30:38 2010
New Revision: 1004763

URL: http://svn.apache.org/viewvc?rev=1004763&view=rev
Log:
Added support for Eucalyptus.  Thanks Davanum Srinivas.

JIRA ticket: https://issues.apache.org/jira/browse/LIBCLOUD-56

Added:
    incubator/libcloud/sandbox/java/trunk/src/libcloud/providers/amazon/EucalyptusDriver.java
Modified:
    incubator/libcloud/sandbox/java/trunk/src/libcloud/DriverFactory.java
    incubator/libcloud/sandbox/java/trunk/src/libcloud/providers/amazon/EC2Connection.java
    incubator/libcloud/sandbox/java/trunk/src/libcloud/providers/amazon/EC2Driver.java

Modified: incubator/libcloud/sandbox/java/trunk/src/libcloud/DriverFactory.java
URL: http://svn.apache.org/viewvc/incubator/libcloud/sandbox/java/trunk/src/libcloud/DriverFactory.java?rev=1004763&r1=1004762&r2=1004763&view=diff
==============================================================================
--- incubator/libcloud/sandbox/java/trunk/src/libcloud/DriverFactory.java (original)
+++ incubator/libcloud/sandbox/java/trunk/src/libcloud/DriverFactory.java Tue Oct  5 18:30:38 2010
@@ -61,7 +61,7 @@ public class DriverFactory {
 		providerMap.put(Provider.RIMUHOSTING, "");
 		providerMap.put(Provider.VOXEL, "");
 		providerMap.put(Provider.SOFTLAYER, "");
-		providerMap.put(Provider.EUCALYPTUS, "");
+		providerMap.put(Provider.EUCALYPTUS, "libcloud.providers.amazon.EucalyptusDriver");
 		providerMap.put(Provider.OPENNEBULA, "");
 		providerMap.put(Provider.DREAMHOST, "");
 	}

Modified: incubator/libcloud/sandbox/java/trunk/src/libcloud/providers/amazon/EC2Connection.java
URL: http://svn.apache.org/viewvc/incubator/libcloud/sandbox/java/trunk/src/libcloud/providers/amazon/EC2Connection.java?rev=1004763&r1=1004762&r2=1004763&view=diff
==============================================================================
--- incubator/libcloud/sandbox/java/trunk/src/libcloud/providers/amazon/EC2Connection.java (original)
+++ incubator/libcloud/sandbox/java/trunk/src/libcloud/providers/amazon/EC2Connection.java Tue Oct  5 18:30:38 2010
@@ -29,6 +29,11 @@ public class EC2Connection extends Conne
 		super(accessId, accessKey, DEFAULT_SECURE, host, driver);
 	}
 	
+    public EC2Connection(String accessId, String accessKey, String host, int port, boolean isSecure,
+            Driver driver) {
+        super(accessId, accessKey, isSecure, host, port, driver);
+    }
+
 	protected Map<String, String> addDefaultParams(Map<String, String> params) {
 		params.put("SignatureVersion", "2");
 		params.put("SignatureMethod", "HmacSHA256");

Modified: incubator/libcloud/sandbox/java/trunk/src/libcloud/providers/amazon/EC2Driver.java
URL: http://svn.apache.org/viewvc/incubator/libcloud/sandbox/java/trunk/src/libcloud/providers/amazon/EC2Driver.java?rev=1004763&r1=1004762&r2=1004763&view=diff
==============================================================================
--- incubator/libcloud/sandbox/java/trunk/src/libcloud/providers/amazon/EC2Driver.java (original)
+++ incubator/libcloud/sandbox/java/trunk/src/libcloud/providers/amazon/EC2Driver.java Tue Oct  5 18:30:38 2010
@@ -40,6 +40,8 @@ public abstract class EC2Driver extends 
 	private static final Map<String, NodeSize> NODE_SIZES = initNodeSizes();
 	private static final Map<String, NodeState> NODE_STATE_MAP = new HashMap<String, NodeState>();
 	
+    protected String REST_BASE = "/";
+	
 	/*
 	 * Constructs the base driver for location-specific drivers to subclass.
 	 * 
@@ -47,7 +49,11 @@ public abstract class EC2Driver extends 
 	 * @param accessKey is the user's Amazon secret key
 	 */
 	public EC2Driver(String accessId, String accessKey, String host) {
-		connection = new EC2Connection(accessId, accessKey, host, this);
+        this(accessId, accessKey, host, 80, true);
+	}
+
+    public EC2Driver(String accessId, String accessKey, String host, int port, boolean isSecure) {
+        connection = new EC2Connection(accessId, accessKey, host, port, isSecure, this);
 		xpath = XPathFactory.newInstance().newXPath();
 		
 		// Map Amazon EC2 instance states to libcloud
@@ -120,7 +126,7 @@ public abstract class EC2Driver extends 
 		}
 		
 		// Send & process request
-		IResponse response = connection.request("GET", "/", null, params, null);
+		IResponse response = connection.request("GET", REST_BASE, null, params, null);
 		EC2Handler handler = new EC2Handler(response);
 		return parseNodes(((Document)handler.getParsedObject()).getDocumentElement(), "instancesSet/item", null).get(0);
 	}
@@ -130,7 +136,7 @@ public abstract class EC2Driver extends 
 		params.put("Action", "TerminateInstances");
 		String[] values = {node.getId()};
 		params.putAll(pathList("InstanceId", values));
-		IResponse response = connection.request("GET", "/", null, params, null);
+		IResponse response = connection.request("GET", REST_BASE, null, params, null);
 		EC2Handler handler = new EC2Handler(response);
 		return parseTerminateBoolean((Document)handler.getParsedObject());
 	}
@@ -140,7 +146,7 @@ public abstract class EC2Driver extends 
 		params.put("Action", "RebootInstances");
 		String[] values = {node.getId()};
 		params.putAll(pathList("InstanceId", values));
-		IResponse response = connection.request("GET", "/", null, params, null);
+		IResponse response = connection.request("GET", REST_BASE, null, params, null);
 		EC2Handler handler = new EC2Handler(response);
 		return parseRebootBoolean(((Document)handler.getParsedObject()));
 	}
@@ -148,7 +154,7 @@ public abstract class EC2Driver extends 
 	public List<INode> listNodes() {
 		Map<String, String> params = new HashMap<String, String>();
 		params.put("Action", "DescribeInstances");
-		IResponse response = connection.request("GET", "/", null, params, null);
+		IResponse response = connection.request("GET", REST_BASE, null, params, null);
 		EC2Handler handler = new EC2Handler(response);
 		return parseNodesByGroup(((Document)handler.getParsedObject()).getDocumentElement());
 	}
@@ -156,7 +162,7 @@ public abstract class EC2Driver extends 
 	public List<NodeImage> listImages() {
 		Map<String, String> params = new HashMap<String, String>();
 		params.put("Action", "DescribeImages");
-		IResponse response = connection.request("GET", "/", null, params, null);
+		IResponse response = connection.request("GET", REST_BASE, null, params, null);
 		EC2Handler handler = new EC2Handler(response);
 		return parseImages((Document)handler.getParsedObject());
 	}
@@ -187,7 +193,7 @@ public abstract class EC2Driver extends 
 		params.put("Action", "CreateSecurityGroup");
 		params.put("GroupName", name);
 		params.put("GroupDescription", description);
-		IResponse response = connection.request("GET", "/", null, params, null);
+		IResponse response = connection.request("GET", REST_BASE, null, params, null);
 		EC2Handler handler = new EC2Handler(response);
 		return handler.getParsedObject();
 	}
@@ -215,7 +221,7 @@ public abstract class EC2Driver extends 
 		params.put("ToPort", "65535");
 		params.put("CidrIp", "0.0.0.0/0");
 		try {
-			IResponse response = connection.request("GET", "/", null, params, null);
+			IResponse response = connection.request("GET", REST_BASE, null, params, null);
 			EC2Handler handler = new EC2Handler(response);
 			results.add(handler.getParsedObject());
 		} catch(Exception e) {
@@ -227,7 +233,7 @@ public abstract class EC2Driver extends 
 		// Request 2
 		params.put("IpProtocol", "udo");
 		try {
-			IResponse response = connection.request("GET", "/", null, params, null);
+			IResponse response = connection.request("GET", REST_BASE, null, params, null);
 			EC2Handler handler = new EC2Handler(response);
 			results.add(handler.getParsedObject());
 		} catch(Exception e) {
@@ -241,7 +247,7 @@ public abstract class EC2Driver extends 
 		params.put("FromPort", "-1");
 		params.put("ToPort", "-1");
 		try {
-			IResponse response = connection.request("GET", "/", null, params, null);
+			IResponse response = connection.request("GET", REST_BASE, null, params, null);
 			EC2Handler handler = new EC2Handler(response);
 			results.add(handler.getParsedObject());
 		} catch(Exception e) {

Added: incubator/libcloud/sandbox/java/trunk/src/libcloud/providers/amazon/EucalyptusDriver.java
URL: http://svn.apache.org/viewvc/incubator/libcloud/sandbox/java/trunk/src/libcloud/providers/amazon/EucalyptusDriver.java?rev=1004763&view=auto
==============================================================================
--- incubator/libcloud/sandbox/java/trunk/src/libcloud/providers/amazon/EucalyptusDriver.java (added)
+++ incubator/libcloud/sandbox/java/trunk/src/libcloud/providers/amazon/EucalyptusDriver.java Tue Oct  5 18:30:38 2010
@@ -0,0 +1,45 @@
+package libcloud.providers.amazon;
+
+import libcloud.data.NodeLocation;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class EucalyptusDriver extends EC2Driver {
+
+    private static final Map<String, Float> EUCALYPTUS_PRICES = initNodePrices();
+
+	public EucalyptusDriver(String accessId, String accessKey, String host, String port, String basePath) {
+		super(accessId, accessKey, host, Integer.parseInt(port), false);
+        REST_BASE = basePath;
+	}
+
+	public List<NodeLocation> listLocations() {
+        List<NodeLocation> locations = new ArrayList<NodeLocation>();
+        locations.add(new NodeLocation("0", "Eucalyptus", "US", this));
+        return locations;
+	}
+
+	public String getName() {
+		return "Eucalyptus";
+	}
+
+    protected float getPrice(String sizeId) {
+        return EUCALYPTUS_PRICES.get(sizeId);
+    }
+
+    private static Map<String, Float> initNodePrices() {
+        Map<String, Float> prices = new HashMap<String, Float>();
+        prices.put("m1.small", .095f);
+        prices.put("m1.large", .38f);
+        prices.put("m1.xlarge", .76f);
+        prices.put("c1.medium", .19f);
+        prices.put("c1.xlarge", .76f);
+        prices.put("m2.xlarge", .57f);
+        prices.put("m2.2xlarge", 1.14f);
+        prices.put("m2.4xlarge", 2.28f);
+        return prices;
+    }
+}
\ No newline at end of file