Skip to content

Commit 98cd1fc

Browse files
committed
CLOUDSTACK-9074: Support Shared Networks in NiciraNVP Plugin
1 parent e6eec13 commit 98cd1fc

File tree

10 files changed

+450
-51
lines changed

10 files changed

+450
-51
lines changed

engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4575,7 +4575,13 @@ private Pair<JobInfo.Status, String> orchestrateStart(final VmWorkStart work) th
45754575
}
45764576
assert vm != null;
45774577

4578-
orchestrateStart(vm.getUuid(), work.getParams(), work.getPlan(), _dpMgr.getDeploymentPlannerByName(work.getDeploymentPlanner()));
4578+
try{
4579+
orchestrateStart(vm.getUuid(), work.getParams(), work.getPlan(), _dpMgr.getDeploymentPlannerByName(work.getDeploymentPlanner()));
4580+
}
4581+
catch (CloudRuntimeException e){
4582+
s_logger.info("[NSX_PLUGIN_LOG] Caught CloudRuntimeException, returning job failed");
4583+
return new Pair<JobInfo.Status, String>(JobInfo.Status.FAILED, null);
4584+
}
45794585
return new Pair<JobInfo.Status, String>(JobInfo.Status.SUCCEEDED, null);
45804586
}
45814587

engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java

Lines changed: 77 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
import com.cloud.network.element.StaticNatServiceProvider;
142142
import com.cloud.network.element.UserDataServiceProvider;
143143
import com.cloud.network.guru.NetworkGuru;
144+
import com.cloud.network.guru.NetworkGuruAdditionalFunctions;
144145
import com.cloud.network.lb.LoadBalancingRulesManager;
145146
import com.cloud.network.rules.FirewallManager;
146147
import com.cloud.network.rules.FirewallRule;
@@ -169,6 +170,7 @@
169170
import com.cloud.user.User;
170171
import com.cloud.user.dao.AccountDao;
171172
import com.cloud.utils.Pair;
173+
import com.cloud.utils.UuidUtils;
172174
import com.cloud.utils.component.AdapterBase;
173175
import com.cloud.utils.component.ManagerBase;
174176
import com.cloud.utils.concurrency.NamedThreadFactory;
@@ -671,8 +673,14 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
671673
vpcId, offering.getRedundantRouter());
672674
vo.setDisplayNetwork(isDisplayNetworkEnabled == null ? true : isDisplayNetworkEnabled);
673675
vo.setStrechedL2Network(offering.getSupportsStrechedL2());
674-
networks.add(_networksDao.persist(vo, vo.getGuestType() == Network.GuestType.Isolated,
675-
finalizeServicesAndProvidersForNetwork(offering, plan.getPhysicalNetworkId())));
676+
NetworkVO networkPersisted = _networksDao.persist(vo, vo.getGuestType() == Network.GuestType.Isolated,
677+
finalizeServicesAndProvidersForNetwork(offering, plan.getPhysicalNetworkId()));
678+
networks.add(networkPersisted);
679+
680+
if (predefined instanceof NetworkVO && guru instanceof NetworkGuruAdditionalFunctions){
681+
NetworkGuruAdditionalFunctions functions = (NetworkGuruAdditionalFunctions) guru;
682+
functions.finalizeNetworkDesign(networkPersisted.getId(), ((NetworkVO)predefined).getVlanIdAsUUID());
683+
}
676684

677685
if (domainId != null && aclType == ACLType.Domain) {
678686
_networksDao.addDomainToNetwork(id, domainId, subdomainAccess == null ? true : subdomainAccess);
@@ -1021,6 +1029,9 @@ public Pair<NetworkGuru, NetworkVO> implementNetwork(long networkId, DeployDesti
10211029
} catch (NoTransitionException e) {
10221030
s_logger.error(e.getMessage());
10231031
return null;
1032+
} catch (CloudRuntimeException e) {
1033+
s_logger.error("Caught exception: " + e.getMessage());
1034+
return null;
10241035
} finally {
10251036
if (implemented.first() == null) {
10261037
s_logger.debug("Cleaning up because we're unable to implement the network " + network);
@@ -1912,43 +1923,45 @@ public Network createGuestNetwork(long networkOfferingId, final String name, fin
19121923
throw new InvalidParameterValueException("The VLAN tag " + vlanId + " is already being used for dynamic vlan allocation for the guest network in zone "
19131924
+ zone.getName());
19141925
}
1915-
String uri = BroadcastDomainType.fromString(vlanId).toString();
1916-
// For Isolated networks, don't allow to create network with vlan that already exists in the zone
1917-
if (ntwkOff.getGuestType() == GuestType.Isolated) {
1918-
if (_networksDao.countByZoneAndUri(zoneId, uri) > 0) {
1919-
throw new InvalidParameterValueException("Network with vlan " + vlanId + " already exists in zone " + zoneId);
1920-
} else {
1921-
List<DataCenterVnetVO> dcVnets = _datacenterVnetDao.findVnet(zoneId, vlanId.toString());
1922-
//for the network that is created as part of private gateway,
1923-
//the vnet is not coming from the data center vnet table, so the list can be empty
1924-
if (!dcVnets.isEmpty()) {
1925-
DataCenterVnetVO dcVnet = dcVnets.get(0);
1926-
// Fail network creation if specified vlan is dedicated to a different account
1927-
if (dcVnet.getAccountGuestVlanMapId() != null) {
1928-
Long accountGuestVlanMapId = dcVnet.getAccountGuestVlanMapId();
1929-
AccountGuestVlanMapVO map = _accountGuestVlanMapDao.findById(accountGuestVlanMapId);
1930-
if (map.getAccountId() != owner.getAccountId()) {
1931-
throw new InvalidParameterValueException("Vlan " + vlanId + " is dedicated to a different account");
1932-
}
1933-
// Fail network creation if owner has a dedicated range of vlans but the specified vlan belongs to the system pool
1934-
} else {
1935-
List<AccountGuestVlanMapVO> maps = _accountGuestVlanMapDao.listAccountGuestVlanMapsByAccount(owner.getAccountId());
1936-
if (maps != null && !maps.isEmpty()) {
1937-
int vnetsAllocatedToAccount = _datacenterVnetDao.countVnetsAllocatedToAccount(zoneId, owner.getAccountId());
1938-
int vnetsDedicatedToAccount = _datacenterVnetDao.countVnetsDedicatedToAccount(zoneId, owner.getAccountId());
1939-
if (vnetsAllocatedToAccount < vnetsDedicatedToAccount) {
1940-
throw new InvalidParameterValueException("Specified vlan " + vlanId + " doesn't belong" + " to the vlan range dedicated to the owner "
1941-
+ owner.getAccountName());
1926+
if (! UuidUtils.validateUUID(vlanId)){
1927+
String uri = BroadcastDomainType.fromString(vlanId).toString();
1928+
// For Isolated networks, don't allow to create network with vlan that already exists in the zone
1929+
if (ntwkOff.getGuestType() == GuestType.Isolated) {
1930+
if (_networksDao.countByZoneAndUri(zoneId, uri) > 0) {
1931+
throw new InvalidParameterValueException("Network with vlan " + vlanId + " already exists in zone " + zoneId);
1932+
} else {
1933+
List<DataCenterVnetVO> dcVnets = _datacenterVnetDao.findVnet(zoneId, vlanId.toString());
1934+
//for the network that is created as part of private gateway,
1935+
//the vnet is not coming from the data center vnet table, so the list can be empty
1936+
if (!dcVnets.isEmpty()) {
1937+
DataCenterVnetVO dcVnet = dcVnets.get(0);
1938+
// Fail network creation if specified vlan is dedicated to a different account
1939+
if (dcVnet.getAccountGuestVlanMapId() != null) {
1940+
Long accountGuestVlanMapId = dcVnet.getAccountGuestVlanMapId();
1941+
AccountGuestVlanMapVO map = _accountGuestVlanMapDao.findById(accountGuestVlanMapId);
1942+
if (map.getAccountId() != owner.getAccountId()) {
1943+
throw new InvalidParameterValueException("Vlan " + vlanId + " is dedicated to a different account");
1944+
}
1945+
// Fail network creation if owner has a dedicated range of vlans but the specified vlan belongs to the system pool
1946+
} else {
1947+
List<AccountGuestVlanMapVO> maps = _accountGuestVlanMapDao.listAccountGuestVlanMapsByAccount(owner.getAccountId());
1948+
if (maps != null && !maps.isEmpty()) {
1949+
int vnetsAllocatedToAccount = _datacenterVnetDao.countVnetsAllocatedToAccount(zoneId, owner.getAccountId());
1950+
int vnetsDedicatedToAccount = _datacenterVnetDao.countVnetsDedicatedToAccount(zoneId, owner.getAccountId());
1951+
if (vnetsAllocatedToAccount < vnetsDedicatedToAccount) {
1952+
throw new InvalidParameterValueException("Specified vlan " + vlanId + " doesn't belong" + " to the vlan range dedicated to the owner "
1953+
+ owner.getAccountName());
1954+
}
19421955
}
19431956
}
19441957
}
19451958
}
1946-
}
1947-
} else {
1948-
// don't allow to creating shared network with given Vlan ID, if there already exists a isolated network or
1949-
// shared network with same Vlan ID in the zone
1950-
if (_networksDao.countByZoneUriAndGuestType(zoneId, uri, GuestType.Isolated) > 0 ) {
1951-
throw new InvalidParameterValueException("There is a isolated/shared network with vlan id: " + vlanId + " already exists " + "in zone " + zoneId);
1959+
} else {
1960+
// don't allow to creating shared network with given Vlan ID, if there already exists a isolated network or
1961+
// shared network with same Vlan ID in the zone
1962+
if (_networksDao.countByZoneUriAndGuestType(zoneId, uri, GuestType.Isolated) > 0 ) {
1963+
throw new InvalidParameterValueException("There is a isolated/shared network with vlan id: " + vlanId + " already exists " + "in zone " + zoneId);
1964+
}
19521965
}
19531966
}
19541967

@@ -2039,7 +2052,14 @@ public Network doInTransaction(TransactionStatus status) {
20392052

20402053
if (vlanIdFinal != null) {
20412054
if (isolatedPvlan == null) {
2042-
URI uri = BroadcastDomainType.fromString(vlanIdFinal);
2055+
URI uri = null;
2056+
if (UuidUtils.validateUUID(vlanIdFinal)){
2057+
//Logical router's UUID provided as VLAN_ID
2058+
userNetwork.setVlanIdAsUUID(vlanIdFinal); //Set transient field
2059+
}
2060+
else {
2061+
uri = BroadcastDomainType.fromString(vlanIdFinal);
2062+
}
20432063
userNetwork.setBroadcastUri(uri);
20442064
if (!vlanIdFinal.equalsIgnoreCase(Vlan.UNTAGGED)) {
20452065
userNetwork.setBroadcastDomainType(BroadcastDomainType.Vlan);
@@ -2648,6 +2668,27 @@ public List<? extends Nic> listVmNics(long vmId, Long nicId, Long networkId) {
26482668
} else {
26492669
result = _nicDao.listByVmIdAndNicIdAndNtwkId(vmId, nicId, networkId);
26502670
}
2671+
2672+
for (NicVO nic : result) {
2673+
if (_networkModel.isProviderForNetwork(Provider.NiciraNvp, nic.getNetworkId())) {
2674+
//For NSX Based networks, add nsxlogicalswitch, nsxlogicalswitchport to each result
2675+
s_logger.info("Listing NSX logical switch and logical switch por for each nic");
2676+
NetworkVO network = _networksDao.findById(nic.getNetworkId());
2677+
NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName());
2678+
NetworkGuruAdditionalFunctions guruFunctions = (NetworkGuruAdditionalFunctions) guru;
2679+
2680+
Map<String, ? extends Object> nsxParams = guruFunctions.listAdditionalNicParams(nic.getUuid());
2681+
if (nsxParams != null){
2682+
String lswitchUuuid = (nsxParams.containsKey(NetworkGuruAdditionalFunctions.NSX_LSWITCH_UUID))
2683+
? (String) nsxParams.get(NetworkGuruAdditionalFunctions.NSX_LSWITCH_UUID) : null;
2684+
String lswitchPortUuuid = (nsxParams.containsKey(NetworkGuruAdditionalFunctions.NSX_LSWITCHPORT_UUID))
2685+
? (String) nsxParams.get(NetworkGuruAdditionalFunctions.NSX_LSWITCHPORT_UUID) : null;
2686+
nic.setNsxLogicalSwitchUuid(lswitchUuuid);
2687+
nic.setNsxLogicalSwitchPortUuid(lswitchPortUuuid);
2688+
}
2689+
}
2690+
}
2691+
26512692
return result;
26522693
}
26532694

engine/schema/src/com/cloud/network/dao/NetworkVO.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,17 @@ public class NetworkVO implements Network {
172172
@Column(name = "streched_l2")
173173
boolean strechedL2Network = false;
174174

175+
@Transient
176+
transient String vlanIdAsUUID;
177+
178+
public String getVlanIdAsUUID() {
179+
return vlanIdAsUUID;
180+
}
181+
182+
public void setVlanIdAsUUID(String vlanIdAsUUID) {
183+
this.vlanIdAsUUID = vlanIdAsUUID;
184+
}
185+
175186
public NetworkVO() {
176187
uuid = UUID.randomUUID().toString();
177188
}

plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/dao/NiciraNvpRouterMappingDao.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@
2525
public interface NiciraNvpRouterMappingDao extends GenericDao<NiciraNvpRouterMappingVO, Long> {
2626

2727
public NiciraNvpRouterMappingVO findByNetworkId(long id);
28+
29+
public boolean existsMappingForNetworkId(long id);
2830
}

plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/dao/NiciraNvpRouterMappingDaoImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package com.cloud.network.dao;
2121

22+
import java.util.List;
2223

2324
import org.springframework.stereotype.Component;
2425

@@ -46,4 +47,12 @@ public NiciraNvpRouterMappingVO findByNetworkId(final long id) {
4647
return findOneBy(sc);
4748
}
4849

50+
@Override
51+
public boolean existsMappingForNetworkId(long id) {
52+
SearchCriteria<NiciraNvpRouterMappingVO> sc = networkSearch.create();
53+
sc.setParameters("network_id", id);
54+
List<NiciraNvpRouterMappingVO> mappings = search(sc, null);
55+
return mappings.size() > 0;
56+
}
57+
4958
}

0 commit comments

Comments
 (0)