diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapter.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapter.java index c068c6c726..f7b7c74e51 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapter.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapter.java @@ -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()); diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/options/NovaTemplateOptions.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/options/NovaTemplateOptions.java index 750b7c0a1a..dc1703d43e 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/options/NovaTemplateOptions.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/options/NovaTemplateOptions.java @@ -83,7 +83,6 @@ public class NovaTemplateOptions extends TemplateOptions implements Cloneable { protected boolean autoAssignFloatingIp = false; protected Optional> floatingIpPoolNames = Optional.absent(); - protected Optional> 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 securityGroupNames) { for (String groupName : checkNotNull(securityGroupNames, "securityGroupNames")) checkNotNull(emptyToNull(groupName), "all security groups must be non-empty"); - this.securityGroupNames = Optional.> 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> getSecurityGroupNames() { - return securityGroupNames; + return getGroups().isEmpty() ? Optional.>absent() : Optional.of(getGroups()); } public byte[] getUserData() { diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/strategy/ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddToSet.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/strategy/ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddToSet.java index 58f7af55b3..79bd0210e3 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/strategy/ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddToSet.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/strategy/ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddToSet.java @@ -126,20 +126,19 @@ public class ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddT boolean securityGroupExtensionPresent = novaApi.getSecurityGroupExtensionForZone(zone).isPresent(); List 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);