This is an automated email from the ASF dual-hosted git repository.

pearl11594 pushed a commit to branch netris-integration-upstream
in repository https://gitbox.apache.org/repos/asf/cloudstack.git

commit b038bc6a65fb18ba43001ecc651ec9636afd0671
Author: Pearl Dsilva <pearl1...@gmail.com>
AuthorDate: Thu Nov 7 10:21:09 2024 -0500

    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
---
 api/src/main/java/com/cloud/event/EventTypes.java  |  2 ++
 .../cloudstack/service/NetrisApiClientImpl.java    |  8 ++++--
 .../cloudstack/service/NetrisGuestNetworkGuru.java | 32 ++++++++++++++++++++--
 .../cloudstack/service/NetrisServiceImpl.java      |  8 ++++++
 .../com/cloud/network/guru/GuestNetworkGuru.java   | 11 ++++++--
 5 files changed, 53 insertions(+), 8 deletions(-)

diff --git a/api/src/main/java/com/cloud/event/EventTypes.java 
b/api/src/main/java/com/cloud/event/EventTypes.java
index 81ed185dae5..54d97a7754a 100644
--- a/api/src/main/java/com/cloud/event/EventTypes.java
+++ b/api/src/main/java/com/cloud/event/EventTypes.java
@@ -496,6 +496,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";
diff --git 
a/plugins/network-elements/netris/src/main/java/org/apache/cloudstack/service/NetrisApiClientImpl.java
 
b/plugins/network-elements/netris/src/main/java/org/apache/cloudstack/service/NetrisApiClientImpl.java
index b61c84e0110..a140f171f64 100644
--- 
a/plugins/network-elements/netris/src/main/java/org/apache/cloudstack/service/NetrisApiClientImpl.java
+++ 
b/plugins/network-elements/netris/src/main/java/org/apache/cloudstack/service/NetrisApiClientImpl.java
@@ -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();
diff --git 
a/plugins/network-elements/netris/src/main/java/org/apache/cloudstack/service/NetrisGuestNetworkGuru.java
 
b/plugins/network-elements/netris/src/main/java/org/apache/cloudstack/service/NetrisGuestNetworkGuru.java
index 95056c95460..2a4891eb28c 100644
--- 
a/plugins/network-elements/netris/src/main/java/org/apache/cloudstack/service/NetrisGuestNetworkGuru.java
+++ 
b/plugins/network-elements/netris/src/main/java/org/apache/cloudstack/service/NetrisGuestNetworkGuru.java
@@ -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);
diff --git 
a/plugins/network-elements/netris/src/main/java/org/apache/cloudstack/service/NetrisServiceImpl.java
 
b/plugins/network-elements/netris/src/main/java/org/apache/cloudstack/service/NetrisServiceImpl.java
index eb2046718c2..90c80ddabf1 100644
--- 
a/plugins/network-elements/netris/src/main/java/org/apache/cloudstack/service/NetrisServiceImpl.java
+++ 
b/plugins/network-elements/netris/src/main/java/org/apache/cloudstack/service/NetrisServiceImpl.java
@@ -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();
     }
diff --git a/server/src/main/java/com/cloud/network/guru/GuestNetworkGuru.java 
b/server/src/main/java/com/cloud/network/guru/GuestNetworkGuru.java
index 1d7eb359a79..342d145dfbc 100644
--- a/server/src/main/java/com/cloud/network/guru/GuestNetworkGuru.java
+++ b/server/src/main/java/com/cloud/network/guru/GuestNetworkGuru.java
@@ -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;
 
@@ -524,12 +525,16 @@ 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: {}", profile);
             
_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.format("Released Zone Vnet: %s for Network: %s", 
BroadcastDomainType.getValue(profile.getBroadcastUri()), profile),
+            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);
         }
 

Reply via email to