Pass VXLAN ID during creation of Netris vNets (#16)

* add zone params to accepts management vnet

* Release vxlan associated to the netris broadcast domain type

* handle update network broadcast uri
This commit is contained in:
Pearl Dsilva 2024-11-07 10:21:09 -05:00 committed by GitHub
parent 9b4d95780a
commit c8eb0f3779
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 52 additions and 7 deletions

View File

@ -495,6 +495,8 @@ public class EventTypes {
public static final String EVENT_ZONE_VLAN_ASSIGN = "ZONE.VLAN.ASSIGN";
public static final String EVENT_ZONE_VLAN_RELEASE = "ZONE.VLAN.RELEASE";
public static final String EVENT_ZONE_VXLAN_ASSIGN = "ZONE.VXLAN.ASSIGN";
public static final String EVENT_ZONE_VXLAN_RELEASE = "ZONE.VXLAN.RELEASE";
// Projects
public static final String EVENT_PROJECT_CREATE = "PROJECT.CREATE";

View File

@ -281,7 +281,7 @@ public class NetrisApiClientImpl implements NetrisApiClient {
List<VPCListing> vpcs = vpcListings.stream()
.filter(x -> x.getName().equals(vpcName) && x.getAdminTenant().getId().equals(tenantId))
.collect(Collectors.toList());
return vpcs.get(0);
return vpcs.isEmpty() ? null : vpcs.get(0);
} catch (Exception e) {
throw new CloudRuntimeException(String.format("Error getting VPC %s information: %s", vpcName, e.getMessage()), e);
}
@ -319,6 +319,7 @@ public class NetrisApiClientImpl implements NetrisApiClient {
String networkName = cmd.getName();
Long networkId = cmd.getId();
String vnetCidr = cmd.getCidr();
Integer vxlanId = cmd.getVxlanId();
boolean isVpc = cmd.isVpc();
String suffix = getNetrisVpcNameSuffix(vpcId, vpcName, networkId, networkName, isVpc);
@ -341,7 +342,7 @@ public class NetrisApiClientImpl implements NetrisApiClient {
createIpamSubnetInternal(netrisSubnetName, vnetCidr, SubnetBody.PurposeEnum.COMMON, associatedVpc);
logger.debug("Successfully created IPAM Subnet {} for network {} on Netris", netrisSubnetName, networkName);
VnetResAddBody vnetResponse = createVnetInternal(associatedVpc, netrisVnetName, vnetCidr);
VnetResAddBody vnetResponse = createVnetInternal(associatedVpc, netrisVnetName, vnetCidr, vxlanId);
if (vnetResponse == null || !vnetResponse.isIsSuccess()) {
String reason = vnetResponse == null ? "Empty response" : "Operation failed on Netris";
logger.debug("The Netris vNet creation {} failed: {}", vNetName, reason);
@ -535,7 +536,7 @@ public class NetrisApiClientImpl implements NetrisApiClient {
}
}
VnetResAddBody createVnetInternal(VPCListing associatedVpc, String netrisVnetName, String vNetCidr) {
VnetResAddBody createVnetInternal(VPCListing associatedVpc, String netrisVnetName, String vNetCidr, Integer vxlanId) {
logger.debug("Creating Netris VPC vNet {} for CIDR {}", netrisVnetName, vNetCidr);
try {
VnetAddBody vnetBody = new VnetAddBody();
@ -558,6 +559,7 @@ public class NetrisApiClientImpl implements NetrisApiClient {
vnetBody.setL3vpn(false);
vnetBody.setName(netrisVnetName);
vnetBody.setNativeVlan(0);
vnetBody.setVxlanID(vxlanId);
vnetBody.setPorts(new ArrayList<>());
IpTreeSubnetSites subnetSites = new IpTreeSubnetSites();

View File

@ -20,6 +20,9 @@ import com.cloud.dc.DataCenter;
import com.cloud.deploy.DeployDestination;
import com.cloud.deploy.DeploymentPlan;
import com.cloud.domain.DomainVO;
import com.cloud.event.ActionEventUtils;
import com.cloud.event.EventTypes;
import com.cloud.event.EventVO;
import com.cloud.exception.InsufficientAddressCapacityException;
import com.cloud.exception.InsufficientVirtualNetworkCapacityException;
import com.cloud.exception.InvalidParameterValueException;
@ -41,6 +44,8 @@ import com.cloud.vm.NicProfile;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
import org.apache.cloudstack.api.ApiCommandResourceType;
import org.apache.cloudstack.context.CallContext;
import javax.inject.Inject;
import java.util.Objects;
@ -132,6 +137,12 @@ public class NetrisGuestNetworkGuru extends GuestNetworkGuru implements Network
if (isNull(zone)) {
throw new CloudRuntimeException(String.format("Failed to find zone with id: %s", zoneId));
}
try {
allocateVnet(network, designedNetwork, network.getDataCenterId(), network.getPhysicalNetworkId(), network.getReservationId());
} catch (Exception e) {
throw new CloudRuntimeException(String.format("Failed to allocate VXLAN for Netris guest Network %s", network.getName()));
}
_networkDao.update(designedNetwork.getId(), designedNetwork);
createNetrisVnet(designedNetwork, zone);
} catch (Exception ex) {
throw new CloudRuntimeException("unable to create Netris network " + network.getUuid() + "due to: " + ex.getMessage());
@ -146,7 +157,7 @@ public class NetrisGuestNetworkGuru extends GuestNetworkGuru implements Network
@Override
public Network implement(Network network, NetworkOffering offering, DeployDestination dest,
ReservationContext context) {
ReservationContext context) throws InsufficientVirtualNetworkCapacityException {
NetworkVO implemented = new NetworkVO(network.getTrafficType(), network.getMode(),
network.getBroadcastDomainType(), network.getNetworkOfferingId(), Network.State.Implemented,
network.getDataCenterId(), network.getPhysicalNetworkId(), offering.isRedundantRouter());
@ -167,10 +178,27 @@ public class NetrisGuestNetworkGuru extends GuestNetworkGuru implements Network
if (network.getName() != null) {
implemented.setName(network.getName());
}
implemented.setBroadcastUri(Networks.BroadcastDomainType.Netris.toUri("netris"));
allocateVnet(network, implemented, network.getDataCenterId(), network.getPhysicalNetworkId(), network.getReservationId());
return implemented;
}
@Override
protected void allocateVnet(Network network, NetworkVO implemented, long dcId, long physicalNetworkId, String reservationId)
throws InsufficientVirtualNetworkCapacityException {
if (network.getBroadcastUri() == null) {
String vnet = _dcDao.allocateVnet(dcId, physicalNetworkId, network.getAccountId(), reservationId, UseSystemGuestVlans.valueIn(network.getAccountId()));
if (vnet == null) {
throw new InsufficientVirtualNetworkCapacityException("Unable to allocate vnet as a " + "part of network " + network + " implement ", DataCenter.class,
dcId);
}
implemented.setBroadcastUri(Networks.BroadcastDomainType.Netris.toUri(vnet));
ActionEventUtils.onCompletedActionEvent(CallContext.current().getCallingUserId(), network.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_ZONE_VXLAN_ASSIGN,
"Assigned Zone vNet: " + vnet + " Network Id: " + implemented.getId(), implemented.getId(), ApiCommandResourceType.Network.toString(), 0);
} else {
implemented.setBroadcastUri(network.getBroadcastUri());
}
}
@Override
public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
NicProfile nicProfile = super.allocate(network, nic, vm);

View File

@ -19,7 +19,10 @@ package org.apache.cloudstack.service;
import com.cloud.agent.AgentManager;
import com.cloud.agent.api.Answer;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.network.Networks;
import com.cloud.network.dao.NetrisProviderDao;
import com.cloud.network.dao.NetworkDao;
import com.cloud.network.dao.NetworkVO;
import com.cloud.network.element.NetrisProviderVO;
import com.cloud.network.netris.NetrisService;
import com.cloud.network.vpc.Vpc;
@ -44,6 +47,8 @@ public class NetrisServiceImpl implements NetrisService, Configurable {
@Inject
private NetrisProviderDao netrisProviderDao;
@Inject
private NetworkDao networkDao;
@Inject
private AgentManager agentMgr;
@Override
@ -91,7 +96,10 @@ 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) {
NetworkVO network = networkDao.findById(networkId);
String vxlanId = Networks.BroadcastDomainType.getValue(network.getBroadcastUri());
CreateNetrisVnetCommand cmd = new CreateNetrisVnetCommand(zoneId, accountId, domainId, vpcName, vpcId, networkName, networkId, cidr, !Objects.isNull(vpcId));
cmd.setVxlanId(Integer.parseInt(vxlanId));
NetrisAnswer answer = sendNetrisCommand(cmd, zoneId);
return answer.getResult();
}

View File

@ -17,6 +17,7 @@
package com.cloud.network.guru;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
@ -523,11 +524,15 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
return; // Nothing to do here if the uri is null already
}
if ((profile.getBroadcastDomainType() == BroadcastDomainType.Vlan || profile.getBroadcastDomainType() == BroadcastDomainType.Vxlan) && !offering.isSpecifyVlan()) {
if ((profile.getBroadcastDomainType() == BroadcastDomainType.Vlan || profile.getBroadcastDomainType() == BroadcastDomainType.Vxlan || profile.getBroadcastDomainType() == BroadcastDomainType.Netris) && !offering.isSpecifyVlan()) {
logger.debug("Releasing vnet for the network id=" + profile.getId());
_dcDao.releaseVnet(BroadcastDomainType.getValue(profile.getBroadcastUri()), profile.getDataCenterId(), profile.getPhysicalNetworkId(), profile.getAccountId(),
profile.getReservationId());
ActionEventUtils.onCompletedActionEvent(CallContext.current().getCallingUserId(), profile.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_ZONE_VLAN_RELEASE,
String eventType = EventTypes.EVENT_ZONE_VLAN_RELEASE;
if (Arrays.asList(BroadcastDomainType.Vxlan, BroadcastDomainType.Netris).contains(profile.getBroadcastDomainType())) {
eventType = EventTypes.EVENT_ZONE_VXLAN_RELEASE;
}
ActionEventUtils.onCompletedActionEvent(CallContext.current().getCallingUserId(), profile.getAccountId(), EventVO.LEVEL_INFO, eventType,
"Released Zone Vnet: " + BroadcastDomainType.getValue(profile.getBroadcastUri()) + " for Network: " + profile.getId(),
profile.getDataCenterId(), ApiCommandResourceType.Zone.toString(), 0);
}