Skip to content

Commit 1b63881

Browse files
committed
Prepend vpc name to vpc tier network name based on global setting
1 parent d6181d5 commit 1b63881

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

engine/components-api/src/main/java/com/cloud/network/vpc/VpcManager.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,26 @@
3737
import com.cloud.network.addr.PublicIp;
3838
import com.cloud.offering.NetworkOffering;
3939
import com.cloud.user.Account;
40+
import org.apache.cloudstack.framework.config.ConfigKey;
4041

4142
public interface VpcManager {
43+
ConfigKey<Boolean> VpcTierNamePrepend = new ConfigKey<>(Boolean.class,
44+
"vpc.tier.name.prepend",
45+
"Advanced",
46+
"false",
47+
"Whether to prepend the VPC name to the VPC tier network name",
48+
true,
49+
ConfigKey.Scope.Global,
50+
null);
51+
ConfigKey<String> VpcTierNamePrependDelimiter = new ConfigKey<>(String.class,
52+
"vpc.tier.name.prepend.delimiter",
53+
"Advanced",
54+
" ",
55+
"Delimiter string to use between the VPC and the VPC tier name",
56+
true,
57+
ConfigKey.Scope.Global,
58+
null);
59+
4260
/**
4361
* Returns all the Guest networks that are part of VPC
4462
*

server/src/main/java/com/cloud/network/NetworkServiceImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,6 +1788,15 @@ public Network createGuestNetwork(CreateNetworkCmd cmd) throws InsufficientCapac
17881788

17891789
checkNetworkDns(ipv6, ntwkOff, vpcId, ip4Dns1, ip4Dns2, ip6Dns1, ip6Dns2);
17901790

1791+
if (vpcId != null && VpcManager.VpcTierNamePrepend.value()) {
1792+
final String connector = VpcManager.VpcTierNamePrependDelimiter.value();
1793+
Vpc vpc = _vpcDao.findById(vpcId);
1794+
if (vpc == null) {
1795+
throw new CloudRuntimeException(String.format("VPC with id %s not found", vpcId));
1796+
}
1797+
name = vpc.getName() + connector + name;
1798+
}
1799+
17911800
Network network = commitNetwork(networkOfferingId, gateway, startIP, endIP, netmask, networkDomain, vlanId, bypassVlanOverlapCheck, name, displayText, caller, physicalNetworkId, zone.getId(),
17921801
domainId, isDomainSpecific, subdomainAccess, vpcId, startIPv6, endIPv6, ip6Gateway, ip6Cidr, displayNetwork, aclId, secondaryVlanId, privateVlanType, ntwkOff, pNtwk, aclType, owner, cidr, createVlan,
17931802
externalId, routerIPv4, routerIPv6, associatedNetwork, ip4Dns1, ip4Dns2, ip6Dns1, ip6Dns2, interfaceMTUs, networkCidrSize);

server/src/main/java/com/cloud/network/vpc/VpcManagerImpl.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171
import org.apache.cloudstack.api.command.user.vpc.UpdateVPCCmd;
7272
import org.apache.cloudstack.context.CallContext;
7373
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
74+
import org.apache.cloudstack.framework.config.ConfigKey;
75+
import org.apache.cloudstack.framework.config.Configurable;
7476
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
7577
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
7678
import org.apache.cloudstack.network.Ipv4GuestSubnetNetworkMap;
@@ -195,7 +197,7 @@
195197

196198
import static com.cloud.offering.NetworkOffering.RoutingMode.Dynamic;
197199

198-
public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvisioningService, VpcService {
200+
public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvisioningService, VpcService, Configurable {
199201

200202
public static final String SERVICE = "service";
201203
public static final String CAPABILITYTYPE = "capabilitytype";
@@ -3115,6 +3117,19 @@ protected void markStaticRouteForRevoke(final StaticRouteVO route, final Account
31153117
}
31163118
}
31173119

3120+
@Override
3121+
public String getConfigComponentName() {
3122+
return VpcManager.class.getSimpleName();
3123+
}
3124+
3125+
@Override
3126+
public ConfigKey<?>[] getConfigKeys() {
3127+
return new ConfigKey<?>[]{
3128+
VpcTierNamePrepend,
3129+
VpcTierNamePrependDelimiter
3130+
};
3131+
}
3132+
31183133
protected class VpcCleanupTask extends ManagedContextRunnable {
31193134
@Override
31203135
protected void runInContext() {

0 commit comments

Comments
 (0)