Add global routing flag on subnet creation (#45)

This commit is contained in:
Nicolas Vazquez 2025-02-04 00:16:31 -03:00 committed by GitHub
parent f70cc1c3b7
commit 48481945d1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 30 additions and 11 deletions

View File

@ -30,7 +30,7 @@ public interface NetrisService {
boolean deleteVpcResource(long zoneId, long accountId, long domainId, Vpc vpc);
boolean createVnetResource(Long zoneId, long accountId, long domainId, String vpcName, Long vpcId, String networkName, Long networkId, String cidr);
boolean createVnetResource(Long zoneId, long accountId, long domainId, String vpcName, Long vpcId, String networkName, Long networkId, String cidr, Boolean globalRouting);
boolean deleteVnetResource(long zoneId, long accountId, long domainId, String vpcName, Long vpcId, String networkName, Long networkId, String cidr);

View File

@ -24,6 +24,7 @@ public class CreateNetrisVnetCommand extends NetrisCommand {
private String gateway;
private String netrisTag;
private String ipv6Cidr;
private Boolean globalRouting;
public CreateNetrisVnetCommand(Long zoneId, Long accountId, Long domainId, String vpcName, Long vpcId, String vNetName, Long networkId, String cidr, String gateway, boolean isVpc) {
super(zoneId, accountId, domainId, vNetName, networkId, isVpc);
@ -73,4 +74,12 @@ public class CreateNetrisVnetCommand extends NetrisCommand {
public void setIpv6Cidr(String ipv6Cidr) {
this.ipv6Cidr = ipv6Cidr;
}
public Boolean isGlobalRouting() {
return globalRouting;
}
public void setGlobalRouting(Boolean globalRouting) {
this.globalRouting = globalRouting;
}
}

View File

@ -716,6 +716,7 @@ public class NetrisApiClientImpl implements NetrisApiClient {
String netrisGateway = cmd.getGateway() + "/" + netmask;
String netrisV6Cidr = cmd.getIpv6Cidr();
boolean isVpc = cmd.isVpc();
Boolean isGlobalRouting = cmd.isGlobalRouting();
String netrisVpcName = getNetrisVpcName(cmd, vpcId, vpcName);
VPCListing associatedVpc = getNetrisVpcResource(netrisVpcName);
@ -733,7 +734,7 @@ public class NetrisApiClientImpl implements NetrisApiClient {
String netrisVnetName = NetrisResourceObjectUtils.retrieveNetrisResourceObjectName(cmd, NetrisResourceObjectUtils.NetrisObjectType.VNET, vNetName) ;
String netrisSubnetName = NetrisResourceObjectUtils.retrieveNetrisResourceObjectName(cmd, NetrisResourceObjectUtils.NetrisObjectType.IPAM_SUBNET, vnetCidr) ;
createIpamSubnetInternal(netrisSubnetName, vnetCidr, SubnetBody.PurposeEnum.COMMON, associatedVpc);
createIpamSubnetInternal(netrisSubnetName, vnetCidr, SubnetBody.PurposeEnum.COMMON, associatedVpc, isGlobalRouting);
if (Objects.nonNull(netrisV6Cidr)) {
String netrisV6IpamAllocationName = NetrisResourceObjectUtils.retrieveNetrisResourceObjectName(cmd, NetrisResourceObjectUtils.NetrisObjectType.IPAM_ALLOCATION, netrisV6Cidr);
String netrisV6SubnetName = NetrisResourceObjectUtils.retrieveNetrisResourceObjectName(cmd, NetrisResourceObjectUtils.NetrisObjectType.IPAM_SUBNET, netrisV6Cidr) ;
@ -741,7 +742,7 @@ public class NetrisApiClientImpl implements NetrisApiClient {
if (Objects.isNull(createdIpamAllocation)) {
throw new CloudRuntimeException(String.format("Failed to create Netris IPAM Allocation %s for VPC %s", netrisV6IpamAllocationName, netrisVpcName));
}
createIpamSubnetInternal(netrisV6SubnetName, netrisV6Cidr, SubnetBody.PurposeEnum.COMMON, associatedVpc);
createIpamSubnetInternal(netrisV6SubnetName, netrisV6Cidr, SubnetBody.PurposeEnum.COMMON, associatedVpc, isGlobalRouting);
}
logger.debug("Successfully created IPAM Subnet {} for network {} on Netris", netrisSubnetName, networkName);
@ -851,7 +852,7 @@ public class NetrisApiClientImpl implements NetrisApiClient {
IpTreeSubnet exactSubnet = getIpamSubnetByAllocationAndPrefixAndPurposeAndVpc(ipamAllocationId, exactCidr, IpTreeSubnet.PurposeEnum.COMMON, systemVpc);
if (exactSubnet == null) {
String ipamSubnetName = NetrisResourceObjectUtils.retrieveNetrisResourceObjectName(cmd, NetrisResourceObjectUtils.NetrisObjectType.IPAM_SUBNET, exactCidr);
createIpamSubnetInternal(ipamSubnetName, exactCidr, SubnetBody.PurposeEnum.COMMON, systemVpc);
createIpamSubnetInternal(ipamSubnetName, exactCidr, SubnetBody.PurposeEnum.COMMON, systemVpc, null);
}
} catch (ApiException e) {
String msg = String.format("Error setting up the Netris Public Range %s on super CIDR %s", exactCidr, superCidr);
@ -1000,7 +1001,7 @@ public class NetrisApiClientImpl implements NetrisApiClient {
List<IpTreeSubnet> matchedSubnets = getSubnet(vpcFilter, netrisSubnetName);
if (matchedSubnets.isEmpty()) {
VPCListing systemVpc = getSystemVpc();
createIpamSubnetInternal(natIp, natIp, SubnetBody.PurposeEnum.NAT, systemVpc);
createIpamSubnetInternal(natIp, natIp, SubnetBody.PurposeEnum.NAT, systemVpc, null);
return;
}
logger.debug("NAT subnet: {} already exists", natIp);
@ -1191,7 +1192,7 @@ public class NetrisApiClientImpl implements NetrisApiClient {
}
}
private InlineResponse2004Data createIpamSubnetInternal(String subnetName, String subnetPrefix, SubnetBody.PurposeEnum purpose, VPCListing vpc) {
private InlineResponse2004Data createIpamSubnetInternal(String subnetName, String subnetPrefix, SubnetBody.PurposeEnum purpose, VPCListing vpc, Boolean isGlobalRouting) {
logger.debug("Creating Netris IPAM Subnet {} for VPC {}", subnetPrefix, vpc.getName());
try {
@ -1215,6 +1216,9 @@ public class NetrisApiClientImpl implements NetrisApiClient {
subnetBody.setPurpose(purpose);
subnetBody.setPrefix(subnetPrefix);
if (isGlobalRouting != null) {
subnetBody.setGlobalRouting(isGlobalRouting);
}
IpamApi ipamApi = apiClient.getApiStubForMethod(IpamApi.class);
InlineResponse2004 subnetResponse = ipamApi.apiV2IpamSubnetPost(subnetBody);
if (subnetResponse == null || !subnetResponse.isIsSuccess()) {

View File

@ -286,6 +286,12 @@ public class NetrisGuestNetworkGuru extends GuestNetworkGuru implements Network
}
String vpcName = null;
Long vpcId = null;
Boolean globalRouting = null;
long networkOfferingId = networkVO.getNetworkOfferingId();
NetworkOfferingVO networkOfferingVO = networkOfferingDao.findById(networkOfferingId);
if (NetworkOffering.NetworkMode.ROUTED.equals(networkOfferingVO.getNetworkMode())) {
globalRouting = true;
}
if (nonNull(networkVO.getVpcId())) {
VpcVO vpc = _vpcDao.findById(networkVO.getVpcId());
if (isNull(vpc)) {
@ -295,8 +301,6 @@ public class NetrisGuestNetworkGuru extends GuestNetworkGuru implements Network
vpcId = vpc.getId();
} else {
logger.debug(String.format("Creating IPAM Allocation before creating IPAM Subnet", networkVO.getName()));
long networkOfferingId = networkVO.getNetworkOfferingId();
NetworkOfferingVO networkOfferingVO = networkOfferingDao.findById(networkOfferingId);
boolean isSourceNatSupported = !NetworkOffering.NetworkMode.ROUTED.equals(networkOfferingVO.getNetworkMode()) &&
networkOfferingServiceMapDao.areServicesSupportedByNetworkOffering(networkVO.getNetworkOfferingId(), Network.Service.SourceNat);
boolean result = netrisService.createVpcResource(zone.getId(), networkVO.getAccountId(), networkVO.getDomainId(),
@ -307,7 +311,8 @@ public class NetrisGuestNetworkGuru extends GuestNetworkGuru implements Network
throw new CloudRuntimeException(msg);
}
}
boolean result = netrisService.createVnetResource(zone.getId(), account.getId(), domain.getId(), vpcName, vpcId, networkVO.getName(), networkVO.getId(), networkVO.getCidr());
boolean result = netrisService.createVnetResource(zone.getId(), account.getId(), domain.getId(), vpcName, vpcId,
networkVO.getName(), networkVO.getId(), networkVO.getCidr(), globalRouting);
if (!result) {
throw new CloudRuntimeException("Failed to create Netris vNet resource for network: " + networkVO.getName());
}

View File

@ -204,13 +204,14 @@ public class NetrisServiceImpl implements NetrisService, Configurable {
}
@Override
public boolean createVnetResource(Long zoneId, long accountId, long domainId, String vpcName, Long vpcId, String networkName, Long networkId, String cidr) {
public boolean createVnetResource(Long zoneId, long accountId, long domainId, String vpcName, Long vpcId, String networkName, Long networkId, String cidr, Boolean globalRouting) {
NetworkVO network = networkDao.findById(networkId);
String vxlanId = Networks.BroadcastDomainType.getValue(network.getBroadcastUri());
CreateNetrisVnetCommand cmd = new CreateNetrisVnetCommand(zoneId, accountId, domainId, vpcName, vpcId, networkName, networkId, cidr, network.getGateway(), !Objects.isNull(vpcId));
cmd.setVxlanId(Integer.parseInt(vxlanId));
NetrisProviderVO netrisProvider = netrisProviderDao.findByZoneId(zoneId);
cmd.setNetrisTag(netrisProvider.getNetrisTag());
cmd.setGlobalRouting(globalRouting);
if (Objects.nonNull(networkId)) {
Ipv6GuestPrefixSubnetNetworkMapVO ipv6PrefixNetworkMapVO = ipv6PrefixNetworkMapDao.findByNetworkId(networkId);
if (Objects.nonNull(ipv6PrefixNetworkMapVO)) {

View File

@ -42,7 +42,7 @@ public class NetrisServiceMockTest implements NetrisService {
}
@Override
public boolean createVnetResource(Long zoneId, long accountId, long domainId, String vpcName, Long vpcId, String networkName, Long networkId, String cidr) {
public boolean createVnetResource(Long zoneId, long accountId, long domainId, String vpcName, Long vpcId, String networkName, Long networkId, String cidr, Boolean globalRouting) {
return true;
}