Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ env:
smoke/test_affinity_groups_projects
smoke/test_async_job
smoke/test_create_list_domain_account_project
smoke/test_create_network
smoke/test_deploy_vgpu_enabled_vm
smoke/test_deploy_vm_iso
smoke/test_deploy_vm_root_resize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,6 @@ public interface NetworkDao extends GenericDao<NetworkVO, Long>, StateDao<State,
int getNonSystemNetworkCountByVpcId(long vpcId);

List<NetworkVO> listNetworkVO(List<Long> idset);

List<NetworkVO> listByAccountIdNetworkName(long accountId, String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public NetworkDaoImpl() {
@PostConstruct
protected void init() {
AllFieldsSearch = createSearchBuilder();
AllFieldsSearch.and("name", AllFieldsSearch.entity().getName(), Op.EQ);
AllFieldsSearch.and("trafficType", AllFieldsSearch.entity().getTrafficType(), Op.EQ);
AllFieldsSearch.and("cidr", AllFieldsSearch.entity().getCidr(), Op.EQ);
AllFieldsSearch.and("broadcastType", AllFieldsSearch.entity().getBroadcastDomainType(), Op.EQ);
Expand Down Expand Up @@ -697,4 +698,13 @@ public List<NetworkVO> listNetworkVO(List<Long> idset) {
sc_2.addAnd("removed", SearchCriteria.Op.EQ, null);
return this.search(sc_2, searchFilter_2);
}

@Override
public List<NetworkVO> listByAccountIdNetworkName(final long accountId, final String name) {
final SearchCriteria<NetworkVO> sc = AllFieldsSearch.create();
sc.setParameters("account", accountId);
sc.setParameters("name", name);

return listBy(sc, null);
}
}
43 changes: 42 additions & 1 deletion server/src/main/java/com/cloud/network/NetworkServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
import org.apache.cloudstack.api.response.AcquirePodIpCmdResponse;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.framework.config.Configurable;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.framework.messagebus.MessageBus;
import org.apache.cloudstack.framework.messagebus.PublishScope;
Expand Down Expand Up @@ -107,6 +109,7 @@
import com.cloud.network.dao.IPAddressDao;
import com.cloud.network.dao.IPAddressVO;
import com.cloud.network.dao.LoadBalancerDao;
import com.cloud.network.dao.NetworkAccountDao;
import com.cloud.network.dao.NetworkDao;
import com.cloud.network.dao.NetworkDetailVO;
import com.cloud.network.dao.NetworkDetailsDao;
Expand Down Expand Up @@ -200,9 +203,14 @@
/**
* NetworkServiceImpl implements NetworkService.
*/
public class NetworkServiceImpl extends ManagerBase implements NetworkService {
public class NetworkServiceImpl extends ManagerBase implements NetworkService, Configurable {
private static final Logger s_logger = Logger.getLogger(NetworkServiceImpl.class);

private static final ConfigKey<Boolean> AllowDuplicateNetworkName = new ConfigKey<Boolean>("Advanced", Boolean.class,
"allow.duplicate.networkname", "true", "Allow creating networks with same name in account", true, ConfigKey.Scope.Account);
private static final ConfigKey<Boolean> AllowEmptyStartEndIpAddress = new ConfigKey<Boolean>("Advanced", Boolean.class,
"allow.empty.start.end.ipaddress", "true", "Allow creating network without mentioning start and end IP address",
true, ConfigKey.Scope.Account);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ravening for backward compatibility, should this be false?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rhtyd In the current/default behavior we can create network without mentioning the start and end IP address. So the default value is "true". If the default value is "false" then it means we cant create a network with an empty start and end IP address which is not backward compatible.

private static final long MIN_VLAN_ID = 0L;
private static final long MAX_VLAN_ID = 4095L; // 2^12 - 1
private static final long MIN_GRE_KEY = 0L;
Expand Down Expand Up @@ -313,6 +321,8 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
VpcOfferingDao _vpcOfferingDao;
@Inject
AccountService _accountService;
@Inject
NetworkAccountDao _networkAccountDao;

int _cidrLimit;
boolean _allowSubdomainNetworkAccess;
Expand Down Expand Up @@ -1164,6 +1174,18 @@ public Network createGuestNetwork(CreateNetworkCmd cmd) throws InsufficientCapac
throw new InvalidParameterValueException("Parameter subDomainAccess can be specified only with aclType=Domain");
}

if (aclType == ACLType.Domain) {
owner = _accountDao.findById(Account.ACCOUNT_ID_SYSTEM);
}

// The network name is unique under the account
if (!AllowDuplicateNetworkName.valueIn(owner.getAccountId())) {
List<NetworkVO> existingNetwork = _networksDao.listByAccountIdNetworkName(owner.getId(), name);
if (!existingNetwork.isEmpty()) {
throw new InvalidParameterValueException("Another network with same name already exists within account: " + owner.getAccountName());
}
}

boolean ipv4 = true, ipv6 = false;
if (startIP != null) {
ipv4 = true;
Expand All @@ -1188,6 +1210,15 @@ public Network createGuestNetwork(CreateNetworkCmd cmd) throws InsufficientCapac
}
}

// Start and end IP address are mandatory for shared networks.
if (ntwkOff.getGuestType() == GuestType.Shared && vpcId == null) {
if (!AllowEmptyStartEndIpAddress.valueIn(owner.getAccountId()) &&
(startIP == null && endIP == null) &&
(startIPv6 == null && endIPv6 == null)) {
throw new InvalidParameterValueException("Either IPv4 or IPv6 start and end address are mandatory");
}
}

String cidr = null;
if (ipv4) {
// if end ip is not specified, default it to startIp
Expand Down Expand Up @@ -4534,4 +4565,14 @@ public boolean releasePodIp(ReleasePodIpCmdByAdmin ip) throws CloudRuntimeExcept
return true;
}

@Override
public String getConfigComponentName() {
return NetworkService.class.getSimpleName();
}

@Override
public ConfigKey<?>[] getConfigKeys() {
return new ConfigKey<?>[] {AllowDuplicateNetworkName, AllowEmptyStartEndIpAddress};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,9 @@ public int getNonSystemNetworkCountByVpcId(final long vpcId) {
public List<NetworkVO> listNetworkVO(List<Long> idset) {
return null;
}

@Override
public List<NetworkVO> listByAccountIdNetworkName(final long accountId, final String name) {
return null;
}
}
Loading