Skip to content

Commit 2250dff

Browse files
committed
1) Removed tags from the network object
2) Get hypervisor tags from the physical network instead.
1 parent da78937 commit 2250dff

22 files changed

Lines changed: 147 additions & 282 deletions

api/src/com/cloud/api/commands/CreateNetworkCmd.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,6 @@ public Long getZoneId() {
163163
return zoneId;
164164
}
165165

166-
public List<String> getTags() {
167-
//FIXME - remove this method
168-
return null;
169-
}
170-
171166
public Long getPhysicalNetworkId() {
172167
NetworkOffering offering = _configService.getNetworkOffering(networkOfferingId);
173168
if (offering == null) {

api/src/com/cloud/api/response/NetworkResponse.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,6 @@ public class NetworkResponse extends BaseResponse implements ControlledEntityRes
120120
@SerializedName(ApiConstants.NETWORK_DOMAIN) @Param(description="the network domain")
121121
private String networkDomain;
122122

123-
@SerializedName(ApiConstants.TAGS) @Param(description="comma separated tag")
124-
private String tags;
125-
126123
@SerializedName(ApiConstants.PHYSICAL_NETWORK_ID) @Param(description="the physical network id")
127124
private Long physicalNetworkId;
128125

@@ -243,19 +240,6 @@ public void setNetworkDomain(String networkDomain) {
243240
this.networkDomain = networkDomain;
244241
}
245242

246-
public void setTags(List<String> tags) {
247-
if (tags == null || tags.size() == 0) {
248-
return;
249-
}
250-
251-
StringBuilder buf = new StringBuilder();
252-
for (String tag : tags) {
253-
buf.append(tag).append(",");
254-
}
255-
256-
this.tags = buf.delete(buf.length()-1, buf.length()).toString();
257-
}
258-
259243
@Override
260244
public void setProjectId(Long projectId) {
261245
this.projectId = projectId;

api/src/com/cloud/hypervisor/Hypervisor.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public class Hypervisor {
2121

2222
public static enum HypervisorType {
2323
None, //for storage hosts
24-
Xen,
2524
XenServer,
2625
KVM,
2726
VMware,
@@ -38,10 +37,7 @@ public static HypervisorType getType(String hypervisor) {
3837
if (hypervisor == null) {
3938
return HypervisorType.None;
4039
}
41-
42-
if (hypervisor.equalsIgnoreCase("Xen")) {
43-
return HypervisorType.Xen;
44-
} else if (hypervisor.equalsIgnoreCase("XenServer")) {
40+
if (hypervisor.equalsIgnoreCase("XenServer")) {
4541
return HypervisorType.XenServer;
4642
} else if (hypervisor.equalsIgnoreCase("KVM")) {
4743
return HypervisorType.KVM;

api/src/com/cloud/network/Network.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,6 @@ private State(String description) {
269269

270270
String getNetworkDomain();
271271

272-
List<String> getTags();
273-
274272
GuestType getGuestType();
275273

276274
boolean getIsShared();

api/src/com/cloud/network/NetworkProfile.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package com.cloud.network;
2020

2121
import java.net.URI;
22-
import java.util.List;
2322

2423
import com.cloud.network.Networks.BroadcastDomainType;
2524
import com.cloud.network.Networks.Mode;
@@ -47,7 +46,6 @@ public class NetworkProfile implements Network {
4746
private String reservationId;
4847
private boolean isDefault;
4948
private String networkDomain;
50-
private List<String> tags;
5149
private Network.GuestType guestType;
5250
private boolean isShared;
5351
private Long physicalNetworkId;
@@ -76,11 +74,6 @@ public NetworkProfile(Network network) {
7674
this.physicalNetworkId = network.getPhysicalNetworkId();
7775
}
7876

79-
@Override
80-
public List<String> getTags() {
81-
return tags;
82-
}
83-
8477
public String getDns1() {
8578
return dns1;
8679
}

api/src/com/cloud/vm/NicProfile.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public ReservationStrategy getStrategy() {
213213
return strategy;
214214
}
215215

216-
public NicProfile(Nic nic, Network network, URI broadcastUri, URI isolationUri, Integer networkRate, boolean isSecurityGroupEnabled) {
216+
public NicProfile(Nic nic, Network network, URI broadcastUri, URI isolationUri, Integer networkRate, boolean isSecurityGroupEnabled, List<String> tags) {
217217
this.id = nic.getId();
218218
this.networkId = network.getId();
219219
this.gateway = nic.getGateway();
@@ -233,7 +233,7 @@ public NicProfile(Nic nic, Network network, URI broadcastUri, URI isolationUri,
233233
this.netmask = nic.getNetmask();
234234
this.isSecurityGroupEnabled = isSecurityGroupEnabled;
235235
this.vmId = nic.getInstanceId();
236-
this.tags = network.getTags();
236+
this.tags = tags;
237237

238238
if (networkRate != null) {
239239
this.networkRate = networkRate;

server/src/com/cloud/api/ApiResponseHelper.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,9 +2192,6 @@ public NetworkResponse createNetworkResponse(Network network) {
21922192

21932193
response.setDns1(profile.getDns1());
21942194
response.setDns2(profile.getDns2());
2195-
2196-
response.setTags(network.getTags());
2197-
21982195
// populate capability
21992196
Map<Service, Map<Capability, String>> serviceCapabilitiesMap = ApiDBUtils.getNetworkCapabilities(networkOffering.getId(), network.getDataCenterId());
22002197
List<ServiceResponse> serviceResponses = new ArrayList<ServiceResponse>();

server/src/com/cloud/configuration/ConfigurationManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1412,7 +1412,7 @@ public void createDefaultNetworks(long zoneId, boolean isSecurityGroupEnabled) t
14121412
}
14131413
userNetwork.setBroadcastDomainType(broadcastDomainType);
14141414
userNetwork.setNetworkDomain(networkDomain);
1415-
_networkMgr.setupNetwork(systemAccount, offering, userNetwork, plan, null, null, isNetworkDefault, false, null, null, true);
1415+
_networkMgr.setupNetwork(systemAccount, offering, userNetwork, plan, null, null, isNetworkDefault, false, null, true);
14161416
}
14171417
}
14181418
}

server/src/com/cloud/network/NetworkManager.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.cloud.exception.InsufficientAddressCapacityException;
2929
import com.cloud.exception.InsufficientCapacityException;
3030
import com.cloud.exception.ResourceUnavailableException;
31+
import com.cloud.hypervisor.Hypervisor.HypervisorType;
3132
import com.cloud.network.Network.Capability;
3233
import com.cloud.network.Network.Provider;
3334
import com.cloud.network.Network.Service;
@@ -110,7 +111,7 @@ List<NetworkVO> setupNetwork(Account owner, NetworkOfferingVO offering, Deployme
110111
throws ConcurrentOperationException;
111112

112113
List<NetworkVO> setupNetwork(Account owner, NetworkOfferingVO offering, Network predefined, DeploymentPlan plan, String name, String displayText, boolean isDefault, boolean errorIfAlreadySetup,
113-
Long domainId, List<String> tags, boolean isShared) throws ConcurrentOperationException;
114+
Long domainId, boolean isShared) throws ConcurrentOperationException;
114115

115116
List<NetworkOfferingVO> getSystemAccountNetworkOfferings(String... offeringNames);
116117

@@ -151,7 +152,7 @@ Pair<NetworkGuru, NetworkVO> implementNetwork(long networkId, DeployDestination
151152
boolean destroyNetwork(long networkId, ReservationContext context);
152153

153154
Network createNetwork(long networkOfferingId, String name, String displayText, Boolean isDefault, String gateway, String cidr, String vlanId, String networkDomain, Account owner, boolean isSecurityGroupEnabled,
154-
Long domainId, List<String> tags, Boolean isShared, PhysicalNetwork physicalNetwork, long zoneId) throws ConcurrentOperationException, InsufficientCapacityException;
155+
Long domainId, Boolean isShared, PhysicalNetwork physicalNetwork, long zoneId) throws ConcurrentOperationException, InsufficientCapacityException;
155156

156157
/**
157158
* @throws InsufficientCapacityException
@@ -228,4 +229,6 @@ boolean associateIpAddressListToAccount(long userId, long accountId, long zoneId
228229

229230
boolean isServiceEnabled(Long physicalNetworkId, long networkOfferingId, Service service);
230231

232+
List<String> getNetworkTags(HypervisorType hType, Network network);
233+
231234
}

server/src/com/cloud/network/NetworkManagerImpl.java

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
import com.cloud.exception.ResourceAllocationException;
8787
import com.cloud.exception.ResourceUnavailableException;
8888
import com.cloud.exception.UnsupportedServiceException;
89+
import com.cloud.hypervisor.Hypervisor.HypervisorType;
8990
import com.cloud.network.IpAddress.State;
9091
import com.cloud.network.Network.Capability;
9192
import 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

Comments
 (0)