8686import com .cloud .exception .ResourceAllocationException ;
8787import com .cloud .exception .ResourceUnavailableException ;
8888import com .cloud .exception .UnsupportedServiceException ;
89+ import com .cloud .hypervisor .Hypervisor .HypervisorType ;
8990import com .cloud .network .IpAddress .State ;
9091import com .cloud .network .Network .Capability ;
9192import com .cloud .network .Network .GuestType ;
@@ -999,13 +1000,13 @@ public List<IPAddressVO> listPublicIpAddressesInVirtualNetwork(long accountId, l
9991000 @ Override
10001001 public List <NetworkVO > setupNetwork (Account owner , NetworkOfferingVO offering , DeploymentPlan plan , String name , String displayText , boolean isDefault , boolean isShared )
10011002 throws ConcurrentOperationException {
1002- return setupNetwork (owner , offering , null , plan , name , displayText , isDefault , false , null , null , isShared );
1003+ return setupNetwork (owner , offering , null , plan , name , displayText , isDefault , false , null , isShared );
10031004 }
10041005
10051006 @ Override
10061007 @ DB
10071008 public List <NetworkVO > setupNetwork (Account owner , NetworkOfferingVO offering , Network predefined , DeploymentPlan plan , String name , String displayText , boolean isDefault , boolean errorIfAlreadySetup ,
1008- Long domainId , List < String > tags , boolean isShared ) throws ConcurrentOperationException {
1009+ Long domainId , boolean isShared ) throws ConcurrentOperationException {
10091010 Account locked = _accountDao .acquireInLockTable (owner .getId ());
10101011 if (locked == null ) {
10111012 throw new ConcurrentOperationException ("Unable to acquire lock on " + owner );
@@ -1066,7 +1067,6 @@ public List<NetworkVO> setupNetwork(Account owner, NetworkOfferingVO offering, N
10661067
10671068 NetworkVO vo = new NetworkVO (id , network , offering .getId (), guru .getName (), owner .getDomainId (), owner .getId (), related , name , displayText , isDefault ,
10681069 (domainId != null ), predefined .getNetworkDomain (), offering .getGuestType (), isShared , plan .getDataCenterId (), plan .getPhysicalNetworkId ());
1069- vo .setTags (tags );
10701070 networks .add (_networksDao .persist (vo , vo .getGuestType () == Network .GuestType .Isolated ));
10711071
10721072 if (domainId != null ) {
@@ -1164,7 +1164,7 @@ public void allocate(VirtualMachineProfile<? extends VMInstanceVO> vm, List<Pair
11641164 nics .add (vo );
11651165
11661166 Integer networkRate = getNetworkRate (config .getId (), vm .getId ());
1167- vm .addNic (new NicProfile (vo , network .first (), vo .getBroadcastUri (), vo .getIsolationUri (), networkRate , isSecurityGroupSupportedInNetwork (network .first ())));
1167+ vm .addNic (new NicProfile (vo , network .first (), vo .getBroadcastUri (), vo .getIsolationUri (), networkRate , isSecurityGroupSupportedInNetwork (network .first ()), getNetworkTags ( vm . getHypervisorType (), network . first ()) ));
11681168 }
11691169
11701170 if (nics .size () != networks .size ()) {
@@ -1414,7 +1414,7 @@ public int compare(NicVO nic1, NicVO nic2) {
14141414
14151415 URI isolationUri = nic .getIsolationUri ();
14161416
1417- profile = new NicProfile (nic , network , broadcastUri , isolationUri , networkRate , isSecurityGroupSupportedInNetwork (network ));
1417+ profile = new NicProfile (nic , network , broadcastUri , isolationUri , networkRate , isSecurityGroupSupportedInNetwork (network ), getNetworkTags ( vmProfile . getHypervisorType (), network ) );
14181418 guru .reserve (profile , network , vmProfile , dest , context );
14191419 nic .setIp4Address (profile .getIp4Address ());
14201420 nic .setAddressFormat (profile .getFormat ());
@@ -1433,7 +1433,7 @@ public int compare(NicVO nic1, NicVO nic2) {
14331433
14341434 updateNic (nic , network .getId (), 1 );
14351435 } else {
1436- profile = new NicProfile (nic , network , nic .getBroadcastUri (), nic .getIsolationUri (), networkRate , isSecurityGroupSupportedInNetwork (network ));
1436+ profile = new NicProfile (nic , network , nic .getBroadcastUri (), nic .getIsolationUri (), networkRate , isSecurityGroupSupportedInNetwork (network ), getNetworkTags ( vmProfile . getHypervisorType (), network ) );
14371437 guru .updateNicProfile (profile , network );
14381438 nic .setState (Nic .State .Reserved );
14391439 updateNic (nic , network .getId (), 1 );
@@ -1460,7 +1460,7 @@ public <T extends VMInstanceVO> void prepareNicForMigration(VirtualMachineProfil
14601460 Integer networkRate = getNetworkRate (network .getId (), vm .getId ());
14611461
14621462 NetworkGuru guru = _networkGurus .get (network .getGuruName ());
1463- NicProfile profile = new NicProfile (nic , network , nic .getBroadcastUri (), nic .getIsolationUri (), networkRate , isSecurityGroupSupportedInNetwork (network ));
1463+ NicProfile profile = new NicProfile (nic , network , nic .getBroadcastUri (), nic .getIsolationUri (), networkRate , isSecurityGroupSupportedInNetwork (network ), getNetworkTags ( vm . getHypervisorType (), network ) );
14641464 guru .updateNicProfile (profile , network );
14651465 vm .addNic (profile );
14661466 }
@@ -1477,7 +1477,7 @@ public void release(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, boo
14771477 NetworkGuru guru = _networkGurus .get (network .getGuruName ());
14781478 nic .setState (Nic .State .Releasing );
14791479 _nicDao .update (nic .getId (), nic );
1480- NicProfile profile = new NicProfile (nic , network , nic .getBroadcastUri (), nic .getIsolationUri (), null , isSecurityGroupSupportedInNetwork (network ));
1480+ NicProfile profile = new NicProfile (nic , network , nic .getBroadcastUri (), nic .getIsolationUri (), null , isSecurityGroupSupportedInNetwork (network ), getNetworkTags ( vmProfile . getHypervisorType (), network ) );
14811481 if (guru .release (profile , vmProfile , nic .getReservationId ())) {
14821482 applyProfileToNicForRelease (nic , profile );
14831483 nic .setState (Nic .State .Allocated );
@@ -1511,7 +1511,7 @@ public List<NicProfile> getNicProfiles(VirtualMachine vm) {
15111511 Integer networkRate = getNetworkRate (network .getId (), vm .getId ());
15121512
15131513 NetworkGuru guru = _networkGurus .get (network .getGuruName ());
1514- NicProfile profile = new NicProfile (nic , network , nic .getBroadcastUri (), nic .getIsolationUri (), networkRate , isSecurityGroupSupportedInNetwork (network ));
1514+ NicProfile profile = new NicProfile (nic , network , nic .getBroadcastUri (), nic .getIsolationUri (), networkRate , isSecurityGroupSupportedInNetwork (network ), getNetworkTags ( vm . getHypervisorType (), network ) );
15151515 guru .updateNicProfile (profile , network );
15161516 profiles .add (profile );
15171517 }
@@ -1613,7 +1613,7 @@ public void cleanupNics(VirtualMachineProfile<? extends VMInstanceVO> vm) {
16131613 nic .setState (Nic .State .Deallocating );
16141614 _nicDao .update (nic .getId (), nic );
16151615 NetworkVO network = _networksDao .findById (nic .getNetworkId ());
1616- NicProfile profile = new NicProfile (nic , network , null , null , null , isSecurityGroupSupportedInNetwork (network ));
1616+ NicProfile profile = new NicProfile (nic , network , null , null , null , isSecurityGroupSupportedInNetwork (network ), getNetworkTags ( vm . getHypervisorType (), network ) );
16171617 NetworkGuru guru = _networkGurus .get (network .getGuruName ());
16181618 guru .deallocate (network , profile , vm );
16191619 _nicDao .remove (nic .getId ());
@@ -1644,16 +1644,11 @@ public Network createNetwork(CreateNetworkCmd cmd) throws InsufficientCapacityEx
16441644 Boolean isDefault = cmd .isDefault ();
16451645 Long userId = UserContext .current ().getCallerUserId ();
16461646 Account caller = UserContext .current ().getCaller ();
1647- List <String > tags = cmd .getTags ();
16481647 boolean isDomainSpecific = false ;
16491648 Boolean isShared = cmd .getIsShared ();
16501649 Long physicalNetworkId = cmd .getPhysicalNetworkId ();
16511650 Long zoneId = cmd .getZoneId ();
16521651
1653- if (tags != null && tags .size () > 1 ) {
1654- throw new InvalidParameterException ("Only one tag can be specified for a network at this time" );
1655- }
1656-
16571652 Transaction txn = Transaction .currentTxn ();
16581653
16591654 // Check if network offering exists
@@ -1780,7 +1775,7 @@ public Network createNetwork(CreateNetworkCmd cmd) throws InsufficientCapacityEx
17801775 domainId = cmd .getDomainId ();
17811776 }
17821777
1783- Network network = createNetwork (networkOfferingId , name , displayText , isDefault , gateway , cidr , vlanId , networkDomain , owner , false , domainId , tags , isShared , pNtwk , zoneId );
1778+ Network network = createNetwork (networkOfferingId , name , displayText , isDefault , gateway , cidr , vlanId , networkDomain , owner , false , domainId , isShared , pNtwk , zoneId );
17841779
17851780 // Don't pass owner to create vlan when network offering is of type Shared - done to prevent accountVlanMap entry
17861781 // creation when vlan is mapped to network
@@ -1801,7 +1796,7 @@ public Network createNetwork(CreateNetworkCmd cmd) throws InsufficientCapacityEx
18011796 @ Override
18021797 @ DB
18031798 public Network createNetwork (long networkOfferingId , String name , String displayText , Boolean isDefault , String gateway , String cidr , String vlanId , String networkDomain , Account owner ,
1804- boolean isSecurityGroupEnabled , Long domainId , List < String > tags , Boolean isShared , PhysicalNetwork pNtwk , long zoneId ) throws ConcurrentOperationException , InsufficientCapacityException {
1799+ boolean isSecurityGroupEnabled , Long domainId , Boolean isShared , PhysicalNetwork pNtwk , long zoneId ) throws ConcurrentOperationException , InsufficientCapacityException {
18051800
18061801 NetworkOfferingVO networkOffering = _networkOfferingDao .findById (networkOfferingId );
18071802 DataCenterVO zone = _dcDao .findById (zoneId );
@@ -1920,7 +1915,7 @@ public Network createNetwork(long networkOfferingId, String name, String display
19201915 }
19211916 }
19221917
1923- List <NetworkVO > networks = setupNetwork (owner , networkOffering , userNetwork , plan , name , displayText , isDefault , true , domainId , tags , isShared );
1918+ List <NetworkVO > networks = setupNetwork (owner , networkOffering , userNetwork , plan , name , displayText , isDefault , true , domainId , isShared );
19241919
19251920 Network network = null ;
19261921 if (networks == null || networks .isEmpty ()) {
@@ -2820,7 +2815,7 @@ public boolean associateIpAddressListToAccount(long userId, long accountId, long
28202815 if (createNetwork ) {
28212816 List <? extends NetworkOffering > offerings = _configMgr .listNetworkOfferings (TrafficType .Guest , false );
28222817 PhysicalNetwork physicalNetwork = translateZoneIdToPhysicalNetwork (zoneId );
2823- network = createNetwork (offerings .get (0 ).getId (), owner .getAccountName () + "-network" , owner .getAccountName () + "-network" , null , null , null , null , null , owner , false , null , null , false , physicalNetwork , zoneId );
2818+ network = createNetwork (offerings .get (0 ).getId (), owner .getAccountName () + "-network" , owner .getAccountName () + "-network" , null , null , null , null , null , owner , false , null , false , physicalNetwork , zoneId );
28242819
28252820 if (network == null ) {
28262821 s_logger .warn ("Failed to create default Virtual network for the account " + accountId + "in zone " + zoneId );
@@ -4451,4 +4446,34 @@ public boolean isServiceEnabled(Long physicalNetworkId, long networkOfferingId,
44514446 return true ;
44524447 }
44534448
4449+
4450+ @ Override
4451+ public List <String > getNetworkTags (HypervisorType hType , Network network ) {
4452+ Long physicalNetworkId = network .getPhysicalNetworkId ();
4453+
4454+ if (physicalNetworkId != null ) {
4455+ String networkTag = _pNTrafficTypeDao .getNetworkTag (physicalNetworkId , network .getTrafficType (), hType );
4456+ if (networkTag != null ) {
4457+ return new ArrayList <String >(Collections .singletonList (networkTag ));
4458+ }
4459+ } else {
4460+ List <PhysicalNetworkVO > pNtwks = _physicalNetworkDao .listByZone (network .getDataCenterId ());
4461+ if (pNtwks .size () == 1 ) {
4462+ physicalNetworkId = pNtwks .get (0 ).getId ();
4463+ } else {
4464+ //locate physicalNetwork with supported traffic type
4465+ //We can make this assumptions based on the fact that Public/Management/Control traffic types are supported only in one physical network in the zone in 3.0
4466+ for (PhysicalNetworkVO pNtwk : pNtwks ) {
4467+ if (_pNTrafficTypeDao .isTrafficTypeSupported (pNtwk .getId (), network .getTrafficType ())) {
4468+ physicalNetworkId = pNtwk .getId ();
4469+ break ;
4470+ }
4471+ }
4472+ }
4473+ }
4474+
4475+ //in all other cases return empty list
4476+ return new ArrayList <String >();
4477+ }
4478+
44544479}
0 commit comments