1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.jclouds.aws.ec2;
20
21 import static org.jclouds.Constants.PROPERTY_ENDPOINT;
22 import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_AMI_QUERY;
23 import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_CC_AMI_QUERY;
24 import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_CC_AMIs;
25 import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_CC_REGIONS;
26 import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_GENERATE_INSTANCE_NAMES;
27 import static org.jclouds.compute.reference.ComputeServiceConstants.PROPERTY_TIMEOUT_NODE_SUSPENDED;
28 import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS;
29
30 import java.util.Properties;
31 import java.util.logging.Logger;
32
33 import org.jclouds.aws.domain.Region;
34
35
36
37
38
39
40 public class AWSEC2PropertiesBuilder extends org.jclouds.ec2.EC2PropertiesBuilder {
41 @Override
42 protected Properties defaultProperties() {
43 Properties properties = super.defaultProperties();
44
45
46
47 properties.setProperty(PROPERTY_TIMEOUT_NODE_SUSPENDED, 120 * 1000 + "");
48
49
50 properties.setProperty("jclouds.ssh.max-retries", "7");
51 properties.setProperty("jclouds.ssh.retry-auth", "true");
52 properties.setProperty(PROPERTY_ENDPOINT, "https://ec2.us-east-1.amazonaws.com");
53 properties.setProperty(PROPERTY_EC2_GENERATE_INSTANCE_NAMES, "true");
54 properties.putAll(Region.regionProperties());
55 properties.remove(PROPERTY_EC2_AMI_OWNERS);
56
57 properties.setProperty(PROPERTY_EC2_AMI_QUERY,
58 "owner-id=137112412989,063491364108,099720109477,411009282317;state=available;image-type=machine");
59
60 properties.setProperty(PROPERTY_EC2_CC_REGIONS, Region.US_EAST_1);
61 properties
62 .setProperty(
63 PROPERTY_EC2_CC_AMI_QUERY,
64 "virtualization-type=hvm;architecture=x86_64;owner-id=137112412989,099720109477;hypervisor=xen;state=available;image-type=machine;root-device-type=ebs");
65 return properties;
66 }
67
68 public AWSEC2PropertiesBuilder() {
69 super();
70 }
71
72 public AWSEC2PropertiesBuilder(Properties properties) {
73 super(properties);
74 }
75
76 @Override
77 public Properties build() {
78 Properties props = super.build();
79 warnAndReplaceIfUsingOldImageKey(props);
80 warnAndReplaceIfUsingOldCCImageKey(props);
81 return props;
82 }
83
84 protected void warnAndReplaceIfUsingOldImageKey(Properties props) {
85 if (props.containsKey(PROPERTY_EC2_AMI_OWNERS)) {
86 StringBuilder query = new StringBuilder();
87 String owners = properties.remove(PROPERTY_EC2_AMI_OWNERS).toString();
88 if ("*".equals(owners))
89 query.append("state=available;image-type=machine");
90 else if (!"".equals(owners))
91 query.append("owner-id=").append(owners).append(";state=available;image-type=machine");
92 else if ("".equals(owners))
93 query = new StringBuilder();
94 props.setProperty(PROPERTY_EC2_AMI_QUERY, query.toString());
95 Logger.getAnonymousLogger().warning(
96 String.format("Property %s is deprecated, please use new syntax: %s=%s", PROPERTY_EC2_AMI_OWNERS,
97 PROPERTY_EC2_AMI_QUERY, query.toString()));
98 }
99 }
100
101 protected void warnAndReplaceIfUsingOldCCImageKey(Properties props) {
102 if (props.containsKey(PROPERTY_EC2_CC_AMIs)) {
103 String amis = properties.remove(PROPERTY_EC2_CC_AMIs).toString();
104 String value = ("".equals(amis)) ? "" : "image-id=" + amis.replace("us-east-1/", "");
105 props.setProperty(PROPERTY_EC2_CC_AMI_QUERY, value);
106 Logger.getAnonymousLogger().warning(
107 String.format("Property %s is deprecated, please use new syntax: %s=%s", PROPERTY_EC2_CC_AMIs,
108 PROPERTY_EC2_CC_AMI_QUERY, value));
109 }
110 }
111
112 }