@Override public DeployVirtualMachineOptions apply(CloudStackTemplateOptions templateOptions, Map<String, Network> networks, String zoneId, DeployVirtualMachineOptions options) { // security groups not allowed. // at least one network must be given to CloudStack, // but jclouds will try to autodetect an appropriate network if none given. checkArgument(templateOptions.getSecurityGroupIds().isEmpty(), "security groups cannot be specified for locations (zones) that use advanced networking"); if (templateOptions.getNetworkIds().size() > 0) { options.networkIds(templateOptions.getNetworkIds()); } else if (templateOptions.getIpsToNetworks().isEmpty()) { checkArgument(!networks.isEmpty(), "please setup a network for zone: " + zoneId); Network defaultNetworkInZone = Iterables.getFirst(filter(networks.values(), and(defaultNetworkInZone(zoneId), supportsStaticNAT())), null); if(defaultNetworkInZone == null) { defaultNetworkInZone = Iterables.getFirst(filter(networks.values(), isIsolatedNetwork()), null); } if (defaultNetworkInZone == null) { throw new IllegalArgumentException("please choose a specific network in zone " + zoneId + ": " + networks); } else { options.networkId(defaultNetworkInZone.getId()); } } return options; } }
@Override public DeployVirtualMachineOptions apply(CloudStackTemplateOptions templateOptions, Map<String, Network> networks, String zoneId, DeployVirtualMachineOptions options) { // security groups not allowed. // at least one network must be given to CloudStack, // but jclouds will try to autodetect an appropriate network if none given. checkArgument(templateOptions.getSecurityGroupIds().isEmpty(), "security groups cannot be specified for locations (zones) that use advanced networking"); if (templateOptions.getNetworkIds().size() > 0) { options.networkIds(templateOptions.getNetworkIds()); } else if (templateOptions.getIpsToNetworks().isEmpty()) { checkArgument(!networks.isEmpty(), "please setup a network for zone: " + zoneId); Network defaultNetworkInZone = Iterables.getFirst(filter(networks.values(), and(defaultNetworkInZone(zoneId), supportsStaticNAT())), null); if(defaultNetworkInZone == null) { defaultNetworkInZone = Iterables.getFirst(filter(networks.values(), isIsolatedNetwork()), null); } if (defaultNetworkInZone == null) { throw new IllegalArgumentException("please choose a specific network in zone " + zoneId + ": " + networks); } else { options.networkId(defaultNetworkInZone.getId()); } } return options; } }
@Override public DeployVirtualMachineOptions apply(CloudStackTemplateOptions templateOptions, Map<String, Network> networks, String zoneId, DeployVirtualMachineOptions options) { // security groups not allowed. // at least one network must be given to CloudStack, // but jclouds will try to autodetect an appropriate network if none given. checkArgument(templateOptions.getSecurityGroupIds().isEmpty(), "security groups cannot be specified for locations (zones) that use advanced networking"); if (!templateOptions.getNetworks().isEmpty()) { options.networkIds(templateOptions.getNetworks()); } else if (templateOptions.getIpsToNetworks().isEmpty()) { checkArgument(!networks.isEmpty(), "please setup a network for zone: " + zoneId); Network defaultNetworkInZone = Iterables.getFirst(filter(networks.values(), and(defaultNetworkInZone(zoneId), supportsStaticNAT())), null); if (defaultNetworkInZone == null) { defaultNetworkInZone = Iterables.getFirst(filter(networks.values(), isIsolatedNetwork()), null); } if (defaultNetworkInZone == null) { throw new IllegalArgumentException("please choose a specific network in zone " + zoneId + ": " + networks); } else { options.networkId(defaultNetworkInZone.getId()); } } return options; } }
public void testDefaultNetworkInZone() { Network defaultInZone = Network.builder().id("42-1").isDefault(true).zoneId("42").build(); Network defaultNotInZone = Network.builder().id("200-1").isDefault(true).zoneId("200").build(); Network notDefaultInZone = Network.builder().id("42-2").isDefault(false).zoneId("42").build(); Network notDefaultNotInZone = Network.builder().id("200-2").isDefault(false).zoneId("200").build(); Predicate<Network> predicate = defaultNetworkInZone("42"); assertTrue(predicate.apply(defaultInZone)); assertFalse(predicate.apply(defaultNotInZone)); assertFalse(predicate.apply(notDefaultInZone)); assertFalse(predicate.apply(notDefaultNotInZone)); } }
public void testDefaultNetworkInZone() { Network defaultInZone = Network.builder().id("42-1").isDefault(true).zoneId("42").build(); Network defaultNotInZone = Network.builder().id("200-1").isDefault(true).zoneId("200").build(); Network notDefaultInZone = Network.builder().id("42-2").isDefault(false).zoneId("42").build(); Network notDefaultNotInZone = Network.builder().id("200-2").isDefault(false).zoneId("200").build(); Predicate<Network> predicate = defaultNetworkInZone("42"); assertTrue(predicate.apply(defaultInZone)); assertFalse(predicate.apply(defaultNotInZone)); assertFalse(predicate.apply(notDefaultInZone)); assertFalse(predicate.apply(notDefaultNotInZone)); } }