mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Prepend VPC name to VPC network tier name (#9780)
* Fix `updateTemplatePermission` when the UI is set to a language other than English (#9766) * Fix updateTemplatePermission UI in non-english language * Improve fix --------- Co-authored-by: Lucas Martins <lucas.martins@scclouds.com.br> * Prepend vpc name to vpc tier network name based on global setting * Added UT for createVpcGuestNetwork * rename connector to delimiter and add configKey.Category.Network * Move setting the name to a new method --------- Co-authored-by: Daan Hoogland <daan@onecht.net> Co-authored-by: Lucas Martins <56271185+lucas-a-martins@users.noreply.github.com> Co-authored-by: Lucas Martins <lucas.martins@scclouds.com.br>
This commit is contained in:
parent
546ef31aed
commit
ef6c0c443d
@ -37,8 +37,26 @@ import com.cloud.network.PhysicalNetwork;
|
||||
import com.cloud.network.addr.PublicIp;
|
||||
import com.cloud.offering.NetworkOffering;
|
||||
import com.cloud.user.Account;
|
||||
import org.apache.cloudstack.framework.config.ConfigKey;
|
||||
|
||||
public interface VpcManager {
|
||||
ConfigKey<Boolean> VpcTierNamePrepend = new ConfigKey<>(Boolean.class,
|
||||
"vpc.tier.name.prepend",
|
||||
ConfigKey.CATEGORY_NETWORK,
|
||||
"false",
|
||||
"Whether to prepend the VPC name to the VPC tier network name",
|
||||
true,
|
||||
ConfigKey.Scope.Global,
|
||||
null);
|
||||
ConfigKey<String> VpcTierNamePrependDelimiter = new ConfigKey<>(String.class,
|
||||
"vpc.tier.name.prepend.delimiter",
|
||||
ConfigKey.CATEGORY_NETWORK,
|
||||
" ",
|
||||
"Delimiter string to use between the VPC and the VPC tier name",
|
||||
true,
|
||||
ConfigKey.Scope.Global,
|
||||
null);
|
||||
|
||||
/**
|
||||
* Returns all the Guest networks that are part of VPC
|
||||
*
|
||||
|
||||
@ -1476,6 +1476,11 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService, C
|
||||
}
|
||||
}
|
||||
|
||||
private String getVpcPrependedNetworkName(String networkName, Vpc vpc) {
|
||||
final String delimiter = VpcManager.VpcTierNamePrependDelimiter.value();
|
||||
return vpc.getName() + delimiter + networkName;
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB
|
||||
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_CREATE, eventDescription = "creating network")
|
||||
@ -1788,6 +1793,13 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService, C
|
||||
|
||||
checkNetworkDns(ipv6, ntwkOff, vpcId, ip4Dns1, ip4Dns2, ip6Dns1, ip6Dns2);
|
||||
|
||||
if (vpcId != null && VpcManager.VpcTierNamePrepend.value()) {
|
||||
Vpc vpc = _vpcDao.findById(vpcId);
|
||||
if (vpc != null) {
|
||||
name = getVpcPrependedNetworkName(name, vpc);
|
||||
}
|
||||
}
|
||||
|
||||
Network network = commitNetwork(networkOfferingId, gateway, startIP, endIP, netmask, networkDomain, vlanId, bypassVlanOverlapCheck, name, displayText, caller, physicalNetworkId, zone.getId(),
|
||||
domainId, isDomainSpecific, subdomainAccess, vpcId, startIPv6, endIPv6, ip6Gateway, ip6Cidr, displayNetwork, aclId, secondaryVlanId, privateVlanType, ntwkOff, pNtwk, aclType, owner, cidr, createVlan,
|
||||
externalId, routerIPv4, routerIPv6, associatedNetwork, ip4Dns1, ip4Dns2, ip6Dns1, ip6Dns2, interfaceMTUs, networkCidrSize);
|
||||
|
||||
@ -71,6 +71,8 @@ import org.apache.cloudstack.api.command.user.vpc.RestartVPCCmd;
|
||||
import org.apache.cloudstack.api.command.user.vpc.UpdateVPCCmd;
|
||||
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.managed.context.ManagedContextRunnable;
|
||||
import org.apache.cloudstack.network.Ipv4GuestSubnetNetworkMap;
|
||||
@ -195,7 +197,7 @@ import com.cloud.vm.dao.NicDao;
|
||||
|
||||
import static com.cloud.offering.NetworkOffering.RoutingMode.Dynamic;
|
||||
|
||||
public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvisioningService, VpcService {
|
||||
public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvisioningService, VpcService, Configurable {
|
||||
|
||||
public static final String SERVICE = "service";
|
||||
public static final String CAPABILITYTYPE = "capabilitytype";
|
||||
@ -3115,6 +3117,19 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConfigComponentName() {
|
||||
return VpcManager.class.getSimpleName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigKey<?>[] getConfigKeys() {
|
||||
return new ConfigKey<?>[]{
|
||||
VpcTierNamePrepend,
|
||||
VpcTierNamePrependDelimiter
|
||||
};
|
||||
}
|
||||
|
||||
protected class VpcCleanupTask extends ManagedContextRunnable {
|
||||
@Override
|
||||
protected void runInContext() {
|
||||
|
||||
@ -777,6 +777,41 @@ public class NetworkServiceImplTest {
|
||||
Mockito.verify(routedIpv4Manager).assignIpv4SubnetToNetwork(nullable(Network.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateVpcTier() throws InsufficientCapacityException, ResourceAllocationException, NoSuchFieldException, IllegalAccessException {
|
||||
Integer privateMtu = 1200;
|
||||
Long networkOfferingId = 1L;
|
||||
Long vpcId = 2L;
|
||||
|
||||
ReflectionTestUtils.setField(createNetworkCmd, "name", "testNetwork");
|
||||
ReflectionTestUtils.setField(createNetworkCmd, "displayText", "Test Network");
|
||||
ReflectionTestUtils.setField(createNetworkCmd, "networkOfferingId", networkOfferingId);
|
||||
ReflectionTestUtils.setField(createNetworkCmd, "zoneId", zoneId);
|
||||
ReflectionTestUtils.setField(createNetworkCmd, "privateMtu", privateMtu);
|
||||
ReflectionTestUtils.setField(createNetworkCmd, "vpcId", vpcId);
|
||||
|
||||
dc = Mockito.mock(DataCenterVO.class);
|
||||
Mockito.when(dcDao.findById(zoneId)).thenReturn(dc);
|
||||
Mockito.when(dc.getId()).thenReturn(zoneId);
|
||||
vpc = Mockito.mock(VpcVO.class);
|
||||
Mockito.when(vpc.getName()).thenReturn("Vpc 1");
|
||||
Mockito.when(vpcDao.findById(vpcId)).thenReturn(vpc);
|
||||
networkOfferingVO = Mockito.mock(NetworkOfferingVO.class);
|
||||
Mockito.when(networkOfferingDao.findById(networkOfferingId)).thenReturn(networkOfferingVO);
|
||||
Mockito.when(configMgr.isOfferingForVpc(networkOfferingVO)).thenReturn(true);
|
||||
|
||||
overrideDefaultConfigValue(VpcManager.VpcTierNamePrepend, "_defaultValue", "true");
|
||||
overrideDefaultConfigValue(VpcManager.VpcTierNamePrependDelimiter, "_defaultValue", " -- ");
|
||||
|
||||
service.createGuestNetwork(createNetworkCmd);
|
||||
|
||||
overrideDefaultConfigValue(VpcManager.VpcTierNamePrepend, "_defaultValue", "false");
|
||||
|
||||
Mockito.verify(vpcMgr, times(1)).createVpcGuestNetwork(networkOfferingId, "Vpc 1 -- testNetwork", "Test Network", null, null,
|
||||
null, null, accountMock, null, phyNet, zoneId, null, null, vpcId, null, accountMock, true,
|
||||
null, null, null, null, null, null, null, new Pair<>(0, privateMtu), null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckAndUpdateNetworkResetSuccess() {
|
||||
NetworkVO networkVO = new NetworkVO();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user