|
141 | 141 | import com.cloud.network.element.StaticNatServiceProvider; |
142 | 142 | import com.cloud.network.element.UserDataServiceProvider; |
143 | 143 | import com.cloud.network.guru.NetworkGuru; |
| 144 | +import com.cloud.network.guru.NetworkGuruAdditionalFunctions; |
144 | 145 | import com.cloud.network.lb.LoadBalancingRulesManager; |
145 | 146 | import com.cloud.network.rules.FirewallManager; |
146 | 147 | import com.cloud.network.rules.FirewallRule; |
|
169 | 170 | import com.cloud.user.User; |
170 | 171 | import com.cloud.user.dao.AccountDao; |
171 | 172 | import com.cloud.utils.Pair; |
| 173 | +import com.cloud.utils.UuidUtils; |
172 | 174 | import com.cloud.utils.component.AdapterBase; |
173 | 175 | import com.cloud.utils.component.ManagerBase; |
174 | 176 | import com.cloud.utils.concurrency.NamedThreadFactory; |
@@ -671,8 +673,14 @@ public void doInTransactionWithoutResult(TransactionStatus status) { |
671 | 673 | vpcId, offering.getRedundantRouter()); |
672 | 674 | vo.setDisplayNetwork(isDisplayNetworkEnabled == null ? true : isDisplayNetworkEnabled); |
673 | 675 | 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 | + } |
676 | 684 |
|
677 | 685 | if (domainId != null && aclType == ACLType.Domain) { |
678 | 686 | _networksDao.addDomainToNetwork(id, domainId, subdomainAccess == null ? true : subdomainAccess); |
@@ -1021,6 +1029,9 @@ public Pair<NetworkGuru, NetworkVO> implementNetwork(long networkId, DeployDesti |
1021 | 1029 | } catch (NoTransitionException e) { |
1022 | 1030 | s_logger.error(e.getMessage()); |
1023 | 1031 | return null; |
| 1032 | + } catch (CloudRuntimeException e) { |
| 1033 | + s_logger.error("Caught exception: " + e.getMessage()); |
| 1034 | + return null; |
1024 | 1035 | } finally { |
1025 | 1036 | if (implemented.first() == null) { |
1026 | 1037 | 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 |
1912 | 1923 | throw new InvalidParameterValueException("The VLAN tag " + vlanId + " is already being used for dynamic vlan allocation for the guest network in zone " |
1913 | 1924 | + zone.getName()); |
1914 | 1925 | } |
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 | + } |
1942 | 1955 | } |
1943 | 1956 | } |
1944 | 1957 | } |
1945 | 1958 | } |
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 | + } |
1952 | 1965 | } |
1953 | 1966 | } |
1954 | 1967 |
|
@@ -2039,7 +2052,14 @@ public Network doInTransaction(TransactionStatus status) { |
2039 | 2052 |
|
2040 | 2053 | if (vlanIdFinal != null) { |
2041 | 2054 | 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 | + } |
2043 | 2063 | userNetwork.setBroadcastUri(uri); |
2044 | 2064 | if (!vlanIdFinal.equalsIgnoreCase(Vlan.UNTAGGED)) { |
2045 | 2065 | userNetwork.setBroadcastDomainType(BroadcastDomainType.Vlan); |
@@ -2648,6 +2668,27 @@ public List<? extends Nic> listVmNics(long vmId, Long nicId, Long networkId) { |
2648 | 2668 | } else { |
2649 | 2669 | result = _nicDao.listByVmIdAndNicIdAndNtwkId(vmId, nicId, networkId); |
2650 | 2670 | } |
| 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 | + |
2651 | 2692 | return result; |
2652 | 2693 | } |
2653 | 2694 |
|
|
0 commit comments