mirror of https://github.com/apache/jclouds.git
Address review comments: use guava checkArgument(), and use switch instead of if for zone network type
This commit is contained in:
parent
1b80b28613
commit
8991d8e512
|
@ -126,35 +126,40 @@ public class CloudStackComputeServiceAdapter implements
|
||||||
CloudStackTemplateOptions templateOptions = template.getOptions().as(CloudStackTemplateOptions.class);
|
CloudStackTemplateOptions templateOptions = template.getOptions().as(CloudStackTemplateOptions.class);
|
||||||
|
|
||||||
DeployVirtualMachineOptions options = displayName(name).name(name);
|
DeployVirtualMachineOptions options = displayName(name).name(name);
|
||||||
if (zone.getNetworkType() == NetworkType.ADVANCED) {
|
switch(zone.getNetworkType()) {
|
||||||
// security groups not allowed.
|
|
||||||
// at least one network must be given to CloudStack,
|
case BASIC:
|
||||||
// but jclouds will try to autodetect an appropriate network if none given.
|
// both security groups and networks are optional, and CloudStack will
|
||||||
if (templateOptions.getSecurityGroupIds().size() > 0) {
|
// use the zone/user's default network/security group if none given
|
||||||
throw new IllegalArgumentException("security groups cannot be specified for locations (zones) that use advanced networking");
|
if (templateOptions.getSecurityGroupIds().size() > 0) {
|
||||||
}
|
options.securityGroupIds(templateOptions.getSecurityGroupIds());
|
||||||
if (templateOptions.getNetworkIds().size() > 0) {
|
|
||||||
options.networkIds(templateOptions.getNetworkIds());
|
|
||||||
} else {
|
|
||||||
if (networks.size() == 0) {
|
|
||||||
throw new IllegalArgumentException("please setup a network for zone: " + zoneId);
|
|
||||||
}
|
}
|
||||||
Network defaultNetworkInZone = Iterables.getFirst(filter(networks.values(), and(defaultNetworkInZone(zoneId), supportsStaticNAT())), null);
|
if (templateOptions.getNetworkIds().size() > 0) {
|
||||||
if(defaultNetworkInZone == null) {
|
options.networkIds(templateOptions.getNetworkIds());
|
||||||
throw new IllegalArgumentException("please choose a specific network in zone " + zoneId + ": " + networks);
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ADVANCED:
|
||||||
|
// 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 {
|
} else {
|
||||||
options.networkId(defaultNetworkInZone.getId());
|
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) {
|
||||||
|
throw new IllegalArgumentException("please choose a specific network in zone " + zoneId + ": " + networks);
|
||||||
|
} else {
|
||||||
|
options.networkId(defaultNetworkInZone.getId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
} else if(zone.getNetworkType() == NetworkType.BASIC) {
|
|
||||||
// both security groups and networks are optional, and CloudStack will
|
default:
|
||||||
// use the zone/user's default network/security group if none given
|
throw new IllegalStateException("Zone networking type is unrecognized");
|
||||||
if (templateOptions.getSecurityGroupIds().size() > 0) {
|
|
||||||
options.securityGroupIds(templateOptions.getSecurityGroupIds());
|
|
||||||
}
|
|
||||||
if (templateOptions.getNetworkIds().size() > 0) {
|
|
||||||
options.networkIds(templateOptions.getNetworkIds());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (templateOptions.getIpOnDefaultNetwork() != null) {
|
if (templateOptions.getIpOnDefaultNetwork() != null) {
|
||||||
|
|
Loading…
Reference in New Issue