Skip to content

Commit 5a606c5

Browse files
committed
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
1 parent a27eca3 commit 5a606c5

File tree

5 files changed

+53
-8
lines changed

5 files changed

+53
-8
lines changed

api/src/main/java/com/cloud/event/EventTypes.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,8 @@ public class EventTypes {
496496

497497
public static final String EVENT_ZONE_VLAN_ASSIGN = "ZONE.VLAN.ASSIGN";
498498
public static final String EVENT_ZONE_VLAN_RELEASE = "ZONE.VLAN.RELEASE";
499+
public static final String EVENT_ZONE_VXLAN_ASSIGN = "ZONE.VXLAN.ASSIGN";
500+
public static final String EVENT_ZONE_VXLAN_RELEASE = "ZONE.VXLAN.RELEASE";
499501

500502
// Projects
501503
public static final String EVENT_PROJECT_CREATE = "PROJECT.CREATE";

plugins/network-elements/netris/src/main/java/org/apache/cloudstack/service/NetrisApiClientImpl.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ private VPCListing getVpcByNameAndTenant(String vpcName) {
281281
List<VPCListing> vpcs = vpcListings.stream()
282282
.filter(x -> x.getName().equals(vpcName) && x.getAdminTenant().getId().equals(tenantId))
283283
.collect(Collectors.toList());
284-
return vpcs.get(0);
284+
return vpcs.isEmpty() ? null : vpcs.get(0);
285285
} catch (Exception e) {
286286
throw new CloudRuntimeException(String.format("Error getting VPC %s information: %s", vpcName, e.getMessage()), e);
287287
}
@@ -319,6 +319,7 @@ public boolean createVnet(CreateNetrisVnetCommand cmd) {
319319
String networkName = cmd.getName();
320320
Long networkId = cmd.getId();
321321
String vnetCidr = cmd.getCidr();
322+
Integer vxlanId = cmd.getVxlanId();
322323
boolean isVpc = cmd.isVpc();
323324

324325
String suffix = getNetrisVpcNameSuffix(vpcId, vpcName, networkId, networkName, isVpc);
@@ -341,7 +342,7 @@ public boolean createVnet(CreateNetrisVnetCommand cmd) {
341342
createIpamSubnetInternal(netrisSubnetName, vnetCidr, SubnetBody.PurposeEnum.COMMON, associatedVpc);
342343
logger.debug("Successfully created IPAM Subnet {} for network {} on Netris", netrisSubnetName, networkName);
343344

344-
VnetResAddBody vnetResponse = createVnetInternal(associatedVpc, netrisVnetName, vnetCidr);
345+
VnetResAddBody vnetResponse = createVnetInternal(associatedVpc, netrisVnetName, vnetCidr, vxlanId);
345346
if (vnetResponse == null || !vnetResponse.isIsSuccess()) {
346347
String reason = vnetResponse == null ? "Empty response" : "Operation failed on Netris";
347348
logger.debug("The Netris vNet creation {} failed: {}", vNetName, reason);
@@ -535,7 +536,7 @@ private InlineResponse2004Data createIpamSubnetInternal(String subnetName, Strin
535536
}
536537
}
537538

538-
VnetResAddBody createVnetInternal(VPCListing associatedVpc, String netrisVnetName, String vNetCidr) {
539+
VnetResAddBody createVnetInternal(VPCListing associatedVpc, String netrisVnetName, String vNetCidr, Integer vxlanId) {
539540
logger.debug("Creating Netris VPC vNet {} for CIDR {}", netrisVnetName, vNetCidr);
540541
try {
541542
VnetAddBody vnetBody = new VnetAddBody();
@@ -558,6 +559,7 @@ VnetResAddBody createVnetInternal(VPCListing associatedVpc, String netrisVnetNam
558559
vnetBody.setL3vpn(false);
559560
vnetBody.setName(netrisVnetName);
560561
vnetBody.setNativeVlan(0);
562+
vnetBody.setVxlanID(vxlanId);
561563
vnetBody.setPorts(new ArrayList<>());
562564

563565
IpTreeSubnetSites subnetSites = new IpTreeSubnetSites();

plugins/network-elements/netris/src/main/java/org/apache/cloudstack/service/NetrisGuestNetworkGuru.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
import com.cloud.deploy.DeployDestination;
2121
import com.cloud.deploy.DeploymentPlan;
2222
import com.cloud.domain.DomainVO;
23+
import com.cloud.event.ActionEventUtils;
24+
import com.cloud.event.EventTypes;
25+
import com.cloud.event.EventVO;
2326
import com.cloud.exception.InsufficientAddressCapacityException;
2427
import com.cloud.exception.InsufficientVirtualNetworkCapacityException;
2528
import com.cloud.exception.InvalidParameterValueException;
@@ -41,6 +44,8 @@
4144
import com.cloud.vm.ReservationContext;
4245
import com.cloud.vm.VirtualMachine;
4346
import com.cloud.vm.VirtualMachineProfile;
47+
import org.apache.cloudstack.api.ApiCommandResourceType;
48+
import org.apache.cloudstack.context.CallContext;
4449

4550
import javax.inject.Inject;
4651
import java.util.Objects;
@@ -132,6 +137,12 @@ public void setup(Network network, long networkId) {
132137
if (isNull(zone)) {
133138
throw new CloudRuntimeException(String.format("Failed to find zone with id: %s", zoneId));
134139
}
140+
try {
141+
allocateVnet(network, designedNetwork, network.getDataCenterId(), network.getPhysicalNetworkId(), network.getReservationId());
142+
} catch (Exception e) {
143+
throw new CloudRuntimeException(String.format("Failed to allocate VXLAN for Netris guest Network %s", network.getName()));
144+
}
145+
_networkDao.update(designedNetwork.getId(), designedNetwork);
135146
createNetrisVnet(designedNetwork, zone);
136147
} catch (Exception ex) {
137148
throw new CloudRuntimeException("unable to create Netris network " + network.getUuid() + "due to: " + ex.getMessage());
@@ -146,7 +157,7 @@ public void deallocate(Network config, NicProfile nic, VirtualMachineProfile vm)
146157

147158
@Override
148159
public Network implement(Network network, NetworkOffering offering, DeployDestination dest,
149-
ReservationContext context) {
160+
ReservationContext context) throws InsufficientVirtualNetworkCapacityException {
150161
NetworkVO implemented = new NetworkVO(network.getTrafficType(), network.getMode(),
151162
network.getBroadcastDomainType(), network.getNetworkOfferingId(), Network.State.Implemented,
152163
network.getDataCenterId(), network.getPhysicalNetworkId(), offering.isRedundantRouter());
@@ -167,10 +178,27 @@ public Network implement(Network network, NetworkOffering offering, DeployDestin
167178
if (network.getName() != null) {
168179
implemented.setName(network.getName());
169180
}
170-
implemented.setBroadcastUri(Networks.BroadcastDomainType.Netris.toUri("netris"));
181+
allocateVnet(network, implemented, network.getDataCenterId(), network.getPhysicalNetworkId(), network.getReservationId());
171182
return implemented;
172183
}
173184

185+
@Override
186+
protected void allocateVnet(Network network, NetworkVO implemented, long dcId, long physicalNetworkId, String reservationId)
187+
throws InsufficientVirtualNetworkCapacityException {
188+
if (network.getBroadcastUri() == null) {
189+
String vnet = _dcDao.allocateVnet(dcId, physicalNetworkId, network.getAccountId(), reservationId, UseSystemGuestVlans.valueIn(network.getAccountId()));
190+
if (vnet == null) {
191+
throw new InsufficientVirtualNetworkCapacityException("Unable to allocate vnet as a " + "part of network " + network + " implement ", DataCenter.class,
192+
dcId);
193+
}
194+
implemented.setBroadcastUri(Networks.BroadcastDomainType.Netris.toUri(vnet));
195+
ActionEventUtils.onCompletedActionEvent(CallContext.current().getCallingUserId(), network.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_ZONE_VXLAN_ASSIGN,
196+
"Assigned Zone vNet: " + vnet + " Network Id: " + implemented.getId(), implemented.getId(), ApiCommandResourceType.Network.toString(), 0);
197+
} else {
198+
implemented.setBroadcastUri(network.getBroadcastUri());
199+
}
200+
}
201+
174202
@Override
175203
public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
176204
NicProfile nicProfile = super.allocate(network, nic, vm);

plugins/network-elements/netris/src/main/java/org/apache/cloudstack/service/NetrisServiceImpl.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
import com.cloud.agent.AgentManager;
2020
import com.cloud.agent.api.Answer;
2121
import com.cloud.exception.InvalidParameterValueException;
22+
import com.cloud.network.Networks;
2223
import com.cloud.network.dao.NetrisProviderDao;
24+
import com.cloud.network.dao.NetworkDao;
25+
import com.cloud.network.dao.NetworkVO;
2326
import com.cloud.network.element.NetrisProviderVO;
2427
import com.cloud.network.netris.NetrisService;
2528
import com.cloud.network.vpc.Vpc;
@@ -44,6 +47,8 @@ public class NetrisServiceImpl implements NetrisService, Configurable {
4447
@Inject
4548
private NetrisProviderDao netrisProviderDao;
4649
@Inject
50+
private NetworkDao networkDao;
51+
@Inject
4752
private AgentManager agentMgr;
4853

4954
@Override
@@ -91,7 +96,10 @@ public boolean deleteVpcResource(long zoneId, long accountId, long domainId, Vpc
9196

9297
@Override
9398
public boolean createVnetResource(Long zoneId, long accountId, long domainId, String vpcName, Long vpcId, String networkName, Long networkId, String cidr) {
99+
NetworkVO network = networkDao.findById(networkId);
100+
String vxlanId = Networks.BroadcastDomainType.getValue(network.getBroadcastUri());
94101
CreateNetrisVnetCommand cmd = new CreateNetrisVnetCommand(zoneId, accountId, domainId, vpcName, vpcId, networkName, networkId, cidr, !Objects.isNull(vpcId));
102+
cmd.setVxlanId(Integer.parseInt(vxlanId));
95103
NetrisAnswer answer = sendNetrisCommand(cmd, zoneId);
96104
return answer.getResult();
97105
}

server/src/main/java/com/cloud/network/guru/GuestNetworkGuru.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.cloud.network.guru;
1818

1919
import java.util.ArrayList;
20+
import java.util.Arrays;
2021
import java.util.List;
2122
import java.util.Random;
2223

@@ -524,12 +525,16 @@ public void shutdown(final NetworkProfile profile, final NetworkOffering offerin
524525
return; // Nothing to do here if the uri is null already
525526
}
526527

527-
if ((profile.getBroadcastDomainType() == BroadcastDomainType.Vlan || profile.getBroadcastDomainType() == BroadcastDomainType.Vxlan) && !offering.isSpecifyVlan()) {
528+
if ((profile.getBroadcastDomainType() == BroadcastDomainType.Vlan || profile.getBroadcastDomainType() == BroadcastDomainType.Vxlan || profile.getBroadcastDomainType() == BroadcastDomainType.Netris) && !offering.isSpecifyVlan()) {
528529
logger.debug("Releasing vnet for the network: {}", profile);
529530
_dcDao.releaseVnet(BroadcastDomainType.getValue(profile.getBroadcastUri()), profile.getDataCenterId(), profile.getPhysicalNetworkId(), profile.getAccountId(),
530531
profile.getReservationId());
531-
ActionEventUtils.onCompletedActionEvent(CallContext.current().getCallingUserId(), profile.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_ZONE_VLAN_RELEASE,
532-
String.format("Released Zone Vnet: %s for Network: %s", BroadcastDomainType.getValue(profile.getBroadcastUri()), profile),
532+
String eventType = EventTypes.EVENT_ZONE_VLAN_RELEASE;
533+
if (Arrays.asList(BroadcastDomainType.Vxlan, BroadcastDomainType.Netris).contains(profile.getBroadcastDomainType())) {
534+
eventType = EventTypes.EVENT_ZONE_VXLAN_RELEASE;
535+
}
536+
ActionEventUtils.onCompletedActionEvent(CallContext.current().getCallingUserId(), profile.getAccountId(), EventVO.LEVEL_INFO, eventType,
537+
"Released Zone Vnet: " + BroadcastDomainType.getValue(profile.getBroadcastUri()) + " for Network: " + profile.getId(),
533538
profile.getDataCenterId(), ApiCommandResourceType.Zone.toString(), 0);
534539
}
535540

0 commit comments

Comments
 (0)