mirror of https://github.com/apache/jclouds.git
JCLOUDS-496: Use the security groups options in the portable TemplateOptions
This commit is contained in:
parent
32acc35804
commit
e0a6df1544
|
@ -103,8 +103,8 @@ public class NovaComputeServiceAdapter implements
|
|||
|
||||
CreateServerOptions options = new CreateServerOptions();
|
||||
options.metadata(metadataAndTagsAsCommaDelimitedValue(template.getOptions()));
|
||||
if (templateOptions.getSecurityGroupNames().isPresent())
|
||||
options.securityGroupNames(templateOptions.getSecurityGroupNames().get());
|
||||
if (!templateOptions.getGroups().isEmpty())
|
||||
options.securityGroupNames(templateOptions.getGroups());
|
||||
options.userData(templateOptions.getUserData());
|
||||
options.diskConfig(templateOptions.getDiskConfig());
|
||||
options.configDrive(templateOptions.getConfigDrive());
|
||||
|
|
|
@ -83,7 +83,6 @@ public class NovaTemplateOptions extends TemplateOptions implements Cloneable {
|
|||
|
||||
protected boolean autoAssignFloatingIp = false;
|
||||
protected Optional<Set<String>> floatingIpPoolNames = Optional.absent();
|
||||
protected Optional<Set<String>> securityGroupNames = Optional.absent();
|
||||
protected boolean generateKeyPair = false;
|
||||
protected String keyPairName;
|
||||
protected byte[] userData;
|
||||
|
@ -100,7 +99,6 @@ public class NovaTemplateOptions extends TemplateOptions implements Cloneable {
|
|||
NovaTemplateOptions that = NovaTemplateOptions.class.cast(o);
|
||||
return super.equals(that) && equal(this.autoAssignFloatingIp, that.autoAssignFloatingIp)
|
||||
&& equal(this.floatingIpPoolNames, that.floatingIpPoolNames)
|
||||
&& equal(this.securityGroupNames, that.securityGroupNames)
|
||||
&& equal(this.generateKeyPair, that.generateKeyPair)
|
||||
&& equal(this.keyPairName, that.keyPairName)
|
||||
&& Arrays.equals(this.userData, that.userData)
|
||||
|
@ -111,7 +109,7 @@ public class NovaTemplateOptions extends TemplateOptions implements Cloneable {
|
|||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(super.hashCode(), autoAssignFloatingIp, floatingIpPoolNames, securityGroupNames, generateKeyPair, keyPairName, userData, diskConfig, configDrive, novaNetworks);
|
||||
return Objects.hashCode(super.hashCode(), autoAssignFloatingIp, floatingIpPoolNames, generateKeyPair, keyPairName, userData, diskConfig, configDrive, novaNetworks);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -121,8 +119,6 @@ public class NovaTemplateOptions extends TemplateOptions implements Cloneable {
|
|||
toString.add("autoAssignFloatingIp", autoAssignFloatingIp);
|
||||
if (floatingIpPoolNames.isPresent())
|
||||
toString.add("floatingIpPoolNames", floatingIpPoolNames.get());
|
||||
if (securityGroupNames.isPresent())
|
||||
toString.add("securityGroupNames", securityGroupNames.get());
|
||||
if (generateKeyPair)
|
||||
toString.add("generateKeyPair", generateKeyPair);
|
||||
toString.add("keyPairName", keyPairName);
|
||||
|
@ -179,18 +175,22 @@ public class NovaTemplateOptions extends TemplateOptions implements Cloneable {
|
|||
/**
|
||||
*
|
||||
* @see org.jclouds.openstack.nova.v2_0.options.CreateServerOptions#getSecurityGroupNames
|
||||
* @deprecated Use @link {@link TemplateOptions#securityGroups(String...)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public NovaTemplateOptions securityGroupNames(String... securityGroupNames) {
|
||||
return securityGroupNames(ImmutableSet.copyOf(checkNotNull(securityGroupNames, "securityGroupNames")));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.jclouds.openstack.nova.v2_0.options.CreateServerOptions#getSecurityGroupNames
|
||||
* @deprecated Use {@link TemplateOptions#securityGroups(Iterable)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public NovaTemplateOptions securityGroupNames(Iterable<String> securityGroupNames) {
|
||||
for (String groupName : checkNotNull(securityGroupNames, "securityGroupNames"))
|
||||
checkNotNull(emptyToNull(groupName), "all security groups must be non-empty");
|
||||
this.securityGroupNames = Optional.<Set<String>> of(ImmutableSet.copyOf(securityGroupNames));
|
||||
securityGroups(securityGroupNames);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -243,9 +243,11 @@ public class NovaTemplateOptions extends TemplateOptions implements Cloneable {
|
|||
* to {@link #getInboundPorts()}
|
||||
*
|
||||
* @see org.jclouds.openstack.nova.v2_0.options.CreateServerOptions#getSecurityGroupNames
|
||||
* @deprecated Use {@link TemplateOptions#getGroups()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public Optional<Set<String>> getSecurityGroupNames() {
|
||||
return securityGroupNames;
|
||||
return getGroups().isEmpty() ? Optional.<Set<String>>absent() : Optional.of(getGroups());
|
||||
}
|
||||
|
||||
public byte[] getUserData() {
|
||||
|
|
|
@ -126,20 +126,19 @@ public class ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddT
|
|||
|
||||
boolean securityGroupExtensionPresent = novaApi.getSecurityGroupExtensionForZone(zone).isPresent();
|
||||
List<Integer> inboundPorts = Ints.asList(templateOptions.getInboundPorts());
|
||||
if (templateOptions.getSecurityGroupNames().isPresent()
|
||||
&& templateOptions.getSecurityGroupNames().get().size() > 0) {
|
||||
if (!templateOptions.getGroups().isEmpty()) {
|
||||
checkArgument(securityGroupExtensionPresent,
|
||||
"Security groups are required by options, but the extension is not available! options: %s",
|
||||
templateOptions);
|
||||
} else if (securityGroupExtensionPresent) {
|
||||
if (!templateOptions.getSecurityGroupNames().isPresent() && inboundPorts.size() > 0) {
|
||||
if (templateOptions.getGroups().isEmpty() && !inboundPorts.isEmpty()) {
|
||||
String securityGroupName = namingConvention.create().sharedNameForGroup(group);
|
||||
try {
|
||||
securityGroupCache.get(new ZoneSecurityGroupNameAndPorts(zone, securityGroupName, inboundPorts));
|
||||
} catch (ExecutionException e) {
|
||||
throw Throwables.propagate(e.getCause());
|
||||
}
|
||||
templateOptions.securityGroupNames(securityGroupName);
|
||||
templateOptions.securityGroups(securityGroupName);
|
||||
}
|
||||
}
|
||||
templateOptions.userMetadata(ComputeServiceConstants.NODE_GROUP_KEY, group);
|
||||
|
|
Loading…
Reference in New Issue