Skip to content
Browse files

Merge pull request #58 from ColbyDyess/master

  • Loading branch information...
francisu committed Aug 4, 2013
2 parents 238903d + 42648e5 commit 98a36f1f251220869c0de90080710d3baa835ee9
@@ -58,30 +58,24 @@
* @author Kohsuke Kawaguchi
public class Eucalyptus extends EC2Cloud {
private transient Metadata metadata;

public final URL url;
public final URL ec2endpoint;
public final URL s3endpoint;

public Eucalyptus(URL url, String accessId, String secretKey, String privateKey, String instanceCapStr, List<SlaveTemplate> templates) throws IOException {
public Eucalyptus(URL ec2endpoint, URL s3endpoint, String accessId, String secretKey, String privateKey, String instanceCapStr, List<SlaveTemplate> templates) throws IOException {
super("eucalyptus", accessId, secretKey, privateKey, instanceCapStr, templates);
this.url = url;

private Metadata getMetadata() throws IOException {
if (metadata==null)
metadata = new Metadata(url);
return metadata;
this.ec2endpoint = ec2endpoint;
this.s3endpoint = s3endpoint;

public URL getEc2EndpointUrl() throws IOException {
return getMetadata().ec2endpoint;
return this.ec2endpoint;

public URL getS3EndpointUrl() throws IOException {
return getMetadata().s3endpoint;
return this.s3endpoint;

@@ -93,111 +87,17 @@ public String getDisplayName() {

public FormValidation doTestConnection(
@QueryParameter URL url,
@QueryParameter URL ec2endpoint,
@QueryParameter String accessId,
@QueryParameter String secretKey,
@QueryParameter String privateKey) throws IOException, ServletException {
return super.doTestConnection(new Metadata(url).ec2endpoint,accessId,secretKey,privateKey);
return super.doTestConnection(ec2endpoint,accessId,secretKey,privateKey);

public FormValidation doGenerateKey(
StaplerResponse rsp, @QueryParameter URL url, @QueryParameter String accessId, @QueryParameter String secretKey) throws IOException, ServletException {
return super.doGenerateKey(rsp, new Metadata(url).ec2endpoint, accessId,secretKey);

* Eucalyptus service endpoint metadata.
static class Metadata {
final URL ec2endpoint,s3endpoint;

Metadata(URL eucalyptus) throws IOException {
if (!eucalyptus.getProtocol().equals("https"))
throw new IOException("Expecting an HTTPS URL but got "+eucalyptus);
URL metadataUrl = new URL(eucalyptus, "/register");
try {
HttpsURLConnection con = (HttpsURLConnection)metadataUrl.openConnection();
Document metadata = new SAXReader().read(con.getInputStream());
Metadata, as of Eucalyptus 1.5.2, looks like this:
<SignatureValue>62595777525d7dbba4b5f361b3e9041d3d37e92611684557e67e85a9222a3ffb </SignatureValue>
<Services type="array">
<Resources type="array">
<Resources type="array">
<id>a002c56e-b994-4ed8-956b-b30eda9b6153</id> <CloudType>eucalyptus</CloudType>
<Description>Public cloud in the new cluster</Description>

this.ec2endpoint = readURLFromMetadata(metadata, "ec2");
this.s3endpoint = readURLFromMetadata(metadata, "s3");
} catch (DocumentException e) {
throw new IOException2("Failed to parse Eucalyptus metadata at "+metadataUrl,e);
} catch (IOException e) {
throw new IOException2("Failed to parse Eucalyptus metadata at "+metadataUrl,e);
} catch (GeneralSecurityException e) {
throw new IOException2("Failed to parse Eucalyptus metadata at "+metadataUrl,e);

* Configures the given {@link HttpsURLConnection} so that it'll ignore all the HTTPS certificate checks,
* as typical Eucalyptus implementation doesn't come with a valid certificate.
private void makeIgnoreCertificate(HttpsURLConnection con) throws NoSuchAlgorithmException, KeyManagementException {
SSLContext sc = SSLContext.getInstance("SSL");
TrustManager[] tma = {new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return null;

public void checkClientTrusted(X509Certificate[] certs, String authType) {

public void checkServerTrusted(X509Certificate[] certs, String authType) {
sc.init(null, tma, null);

con.setHostnameVerifier(new HostnameVerifier() {
public boolean verify(String s, SSLSession sslSession) {
return true; // everything goes

private URL readURLFromMetadata(Document metadata, String serviceName) throws MalformedURLException {
Element e = (Element)metadata.selectSingleNode("//Service[Name/text()='" + serviceName + "']/EndpointUrl");
if (e==null)
throw new IllegalStateException("Service metadata didn't contain "+serviceName);
return new URL(e.getTextTrim());
return super.doGenerateKey(rsp, url, accessId,secretKey);
@@ -38,6 +38,7 @@

import java.util.*;

import javax.servlet.ServletException;
@@ -674,11 +675,16 @@ public String getHelpFile(String fieldName) {
public FormValidation doValidateAmi(
@QueryParameter String accessId, @QueryParameter String secretKey,
@QueryParameter String region,
@QueryParameter String ec2endpoint, @QueryParameter String region,
final @QueryParameter String ami) throws IOException, ServletException {
AmazonEC2 ec2 = EC2Cloud.connect(accessId, secretKey, AmazonEC2Cloud.getEc2EndpointUrl(region));
AmazonEC2 ec2;
if (region != null) {
ec2 = EC2Cloud.connect(accessId, secretKey, AmazonEC2Cloud.getEc2EndpointUrl(region));
} else {
ec2 = EC2Cloud.connect(accessId, secretKey, new URL(ec2endpoint));
if(ec2!=null) {
try {
try {
List<String> images = new LinkedList<String>();
List<String> owners = new LinkedList<String>();
@@ -697,7 +703,7 @@ public FormValidation doValidateAmi(
return FormValidation.ok(img.get(0).getImageLocation() +
(ownerAlias != null ? " by " + ownerAlias : ""));
} catch (AmazonClientException e) {
return FormValidation.error(e.getMessage());
return FormValidation.error(e.getMessage());
} else
return FormValidation.ok(); // can't test
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<f:entry title="${%Eucalyptus URL}" field="url">
<f:entry title="${%Eucalyptus EC2 URL}" field="ec2endpoint">
<f:textbox />
<f:entry title="${%Eucalyptus S3 URL}" field="s3endpoint">
<f:textbox />
<f:entry title="${%Access ID}" field="accessId">
@@ -39,6 +42,6 @@ THE SOFTWARE.
<f:textbox />
<f:validateButton title="${%Generate Key}" progress="${%Generate...}" method="generateKey" with="url,secretKey,accessId" />
<f:validateButton title="${%Test Connection}" progress="${%Testing...}" method="testConnection" with="url,secretKey,accessId,privateKey" />
<f:validateButton title="${%Generate Key}" progress="${%Generate...}" method="generateKey" with="ec2endpoint,secretKey,accessId" />
<f:validateButton title="${%Test Connection}" progress="${%Testing...}" method="testConnection" with="ec2endpoint,secretKey,accessId,privateKey" />
@@ -32,7 +32,7 @@ THE SOFTWARE.
<f:textbox />

<f:validateButton title="${%Check AMI}" progress="${%Checking...}" method="validateAmi" with="secretKey,accessId,region,ami" />
<f:validateButton title="${%Check AMI}" progress="${%Checking...}" method="validateAmi" with="secretKey,accessId,region,ec2endpoint,ami" />

<f:entry title="${%Instance Type}" field="type">

0 comments on commit 98a36f1

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.