* @return
* @throws Exception
*/
private CloudStackNetwork getNetworksWithoutSecurityGroupEnabled(String zoneId) throws Exception {
// grab current account
CloudStackAccount caller = getCurrentAccount();
//check if account has any networks in the system
List<CloudStackNetwork> networks = getApi().listNetworks(caller.getName(), caller.getDomainId(), null, true, null, null, null, null, null, zoneId);
//listRequired offerings in the system - the network created from this offering has to be specified in deployVm command
List<CloudStackNetworkOffering> reuquiredOfferings = getApi().listNetworkOfferings("Required", null, null, null, true, null, null, null, null, null, zoneId);
if (reuquiredOfferings != null && !reuquiredOfferings.isEmpty()) {
if (networks != null && !networks.isEmpty()) {
//pick up the first required network from the network list
for (CloudStackNetwork network : networks) {
for (CloudStackNetworkOffering requiredOffering : reuquiredOfferings) {
logger.debug("[reqd/virtual} offering: " + requiredOffering.getId() + " network " + network.getNetworkOfferingId());
if (network.getNetworkOfferingId().equals(requiredOffering.getId())) {
return network;
}
}
}
} else {
//create new network and return it
return createDefaultGuestNetwork(zoneId, reuquiredOfferings.get(0), caller);
}
} else {
//find all optional network offerings in the system
List<CloudStackNetworkOffering> optionalOfferings = getApi().listNetworkOfferings("Optional", null, null, null, true, null, null, null, null, null, zoneId);
if (optionalOfferings != null && !optionalOfferings.isEmpty()) {
if (networks != null && !networks.isEmpty()) {
for (CloudStackNetwork network : networks) {
for (CloudStackNetworkOffering optionalOffering : optionalOfferings) {
logger.debug("[optional] offering: " + optionalOffering.getId() + " network " + network.getNetworkOfferingId());
if (network.getNetworkOfferingId().equals(optionalOffering.getId())) {
return network;
}
}
}
}
}
}
// if we get this far and haven't returned already return an error
throw new EC2ServiceException(ServerError.InternalError, "Unable to find an appropriate network for account " + caller.getName());
}