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