Skip to content

Commit ea422af

Browse files
author
frank
committed
Bug 12777 - Add storage network configuration into CloudStack
Let StorageGuru inherit PodBaseNetworkGuru
1 parent cb60589 commit ea422af

7 files changed

Lines changed: 60 additions & 23 deletions

File tree

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,17 @@ public static boolean isSystemNetwork(TrafficType trafficType) {
117117
}
118118

119119
public static TrafficType getTrafficType(String type) {
120-
if (type.equals("Public")) {
120+
if ("Public".equals(type)) {
121121
return Public;
122-
} else if (type.endsWith("Guest")) {
122+
} else if ("Guest".equals(type)) {
123123
return Guest;
124-
} else if (type.endsWith("Storage")) {
124+
} else if ("Storage".equals(type)) {
125125
return Storage;
126-
} else if (type.endsWith("Management")) {
126+
} else if ("Management".equals(type)) {
127127
return Management;
128-
} else if (type.endsWith("Control")) {
128+
} else if ("Control".equals(type)) {
129129
return Control;
130-
} else if (type.endsWith("Vpn")) {
130+
} else if ("Vpn".equals(type)) {
131131
return Vpn;
132132
} else {
133133
return None;

client/tomcatconf/components.xml.in

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,33 @@
5252
<adapter name="Balance" class="com.cloud.consoleproxy.ConsoleProxyBalanceAllocator"/>
5353
</adapters>
5454
<adapters key="com.cloud.network.guru.NetworkGuru">
55+
<!--
56+
NOTE: The order of those gurus implicates priority of network traffic types the guru implements.
57+
The upper the higher priority. It effects listTafficTypeImplementors API which returns impelmentor
58+
of a specific network traffic.
59+
A fair question is, if two gurus implement the same two network traffic types, but these traffic types
60+
have cross priority, how to rank them? For example:
61+
GuruA (TrafficTypeA, TrafficTypeB)
62+
GuruB (TrafficTypeA, TrafficTypeB)
63+
we want GuruB.TrafficTypeB > GuruA.TrafficTypeB and GuruB.TrafficTypeA < GuruA.TrafficTypeA. As the priority
64+
implicated by order can not map to multiple traffic type, you have to do implement GuruC which inherits GuruB
65+
for TrafficTypeB. Then ranking them in order of:
66+
GuruC (TrafficTypeB)
67+
GuruA (TrafficTypeA, TrafficTypeB)
68+
GuruB (TrafficTypeA, TrafficTypeB)
69+
now GuruC represents TrafficTypeB with highest priority while GuruA represents TrafficTypeA with highest pirority.
70+
71+
However, above case barely happens.
72+
-->
73+
74+
<adapter name="StorageNetworkGuru" class="com.cloud.network.guru.StorageNetworkGuru"/>
5575
<adapter name="ExternalGuestNetworkGuru" class="com.cloud.network.guru.ExternalGuestNetworkGuru"/>
56-
<adapter name="OvsGuestNetworkGuru" class="com.cloud.network.guru.OvsGuestNetworkGuru"/>
5776
<adapter name="PublicNetworkGuru" class="com.cloud.network.guru.PublicNetworkGuru"/>
5877
<adapter name="PodBasedNetworkGuru" class="com.cloud.network.guru.PodBasedNetworkGuru"/>
5978
<adapter name="ControlNetworkGuru" class="com.cloud.network.guru.ControlNetworkGuru"/>
6079
<adapter name="DirectNetworkGuru" class="com.cloud.network.guru.DirectNetworkGuru"/>
6180
<adapter name="DirectPodBasedNetworkGuru" class="com.cloud.network.guru.DirectPodBasedNetworkGuru"/>
62-
<adapter name="StorageNetworkGuru" class="com.cloud.network.guru.StorageNetworkGuru"/>
81+
<adapter name="OvsGuestNetworkGuru" class="com.cloud.network.guru.OvsGuestNetworkGuru"/>
6382
</adapters>
6483
<adapters key="com.cloud.cluster.ClusterServiceAdapter">
6584
<adapter name="ClusterService" class="com.cloud.cluster.ClusterServiceServletAdapter"/>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ public enum Config {
235235

236236
// XenServer
237237
XenPublicNetwork("Network", ManagementServer.class, String.class, "xen.public.network.device", null, "[ONLY IF THE PUBLIC NETWORK IS ON A DEDICATED NIC]:The network name label of the physical device dedicated to the public network on a XenServer host", null),
238-
XenStorageNetwork1("Network", ManagementServer.class, String.class, "xen.storage.network.device1", "cloud-stor1", "Specify when there are storage networks", null),
239-
XenStorageNetwork2("Network", ManagementServer.class, String.class, "xen.storage.network.device2", "cloud-stor2", "Specify when there are storage networks", null),
238+
XenStorageNetwork1("Network", ManagementServer.class, String.class, "xen.storage.network.device1", null, "Specify when there are storage networks", null),
239+
XenStorageNetwork2("Network", ManagementServer.class, String.class, "xen.storage.network.device2", null, "Specify when there are storage networks", null),
240240
XenPrivateNetwork("Network", ManagementServer.class, String.class, "xen.private.network.device", null, "Specify when the private network name is different", null),
241241
NetworkGuestCidrLimit("Network", NetworkManager.class, Integer.class, "network.guest.cidr.limit", "22", "size limit for guest cidr; can't be less than this value", null),
242242
XenSetupMultipath("Advanced", ManagementServer.class, String.class, "xen.setup.multipath", "false", "Setup the host to do multipath", null),

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

100644100755
File mode changed.

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5661,7 +5661,10 @@ public List<Pair<TrafficType, String>> listTrafficTypeImplementor(ListTafficType
56615661
}
56625662
} else {
56635663
for (NetworkGuru guru : _networkGurus) {
5664-
results.add(new Pair<TrafficType, String>(TrafficType.getTrafficType(type), guru.getName()));
5664+
TrafficType[] allTypes = guru.getSupportedTrafficType();
5665+
for (TrafficType t : allTypes) {
5666+
results.add(new Pair<TrafficType, String>(t, guru.getName()));
5667+
}
56655668
}
56665669
}
56675670

server/src/com/cloud/network/guru/PodBasedNetworkGuru.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@
3636
import com.cloud.network.Network;
3737
import com.cloud.network.NetworkProfile;
3838
import com.cloud.network.NetworkVO;
39+
import com.cloud.network.StorageNetworkManager;
3940
import com.cloud.network.Networks.AddressFormat;
4041
import com.cloud.network.Networks.BroadcastDomainType;
4142
import com.cloud.network.Networks.Mode;
4243
import com.cloud.network.Networks.TrafficType;
43-
import com.cloud.network.StorageNetworkManager;
4444
import com.cloud.offering.NetworkOffering;
4545
import com.cloud.user.Account;
4646
import com.cloud.utils.Pair;
@@ -88,10 +88,10 @@ public Network design(NetworkOffering offering, DeploymentPlan plan, Network use
8888
}
8989

9090
if (type == TrafficType.Storage && _sNwMgr.isStorageIpRangeAvailable()) {
91-
s_logger.debug("There is some storage ip available, let StorageNetworkGuru to handle storage traffic type, not me");
91+
s_logger.debug("There is an storage network ip range, let StorageNetworkGuru to handle TrafficType.Storage");
9292
return null;
9393
}
94-
94+
9595
NetworkVO config = new NetworkVO(type, Mode.Static, BroadcastDomainType.Native, offering.getId(), Network.State.Setup, plan.getDataCenterId(), plan.getPhysicalNetworkId());
9696
return config;
9797
}

server/src/com/cloud/network/guru/StorageNetworkGuru.java

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import com.cloud.vm.Nic.ReservationStrategy;
3333

3434
@Local(value = NetworkGuru.class)
35-
public class StorageNetworkGuru extends AdapterBase implements NetworkGuru {
35+
public class StorageNetworkGuru extends PodBasedNetworkGuru implements NetworkGuru {
3636
private static final Logger s_logger = Logger.getLogger(StorageNetworkGuru.class);
3737
@Inject StorageNetworkManager _sNwMgr;
3838

@@ -59,12 +59,7 @@ public TrafficType[] getSupportedTrafficType() {
5959

6060
protected boolean canHandle(NetworkOffering offering) {
6161
if (isMyTrafficType(offering.getTrafficType()) && offering.isSystemOnly()) {
62-
if (_sNwMgr.isStorageIpRangeAvailable()) {
63-
return true;
64-
} else {
65-
s_logger.debug("No storage network ip range availabe, let PodBasedNetworkGuru to handle storage traffic type, not me");
66-
return false;
67-
}
62+
return true;
6863
} else {
6964
s_logger.trace("It's not storage network offering, skip it.");
7065
return false;
@@ -77,6 +72,10 @@ public Network design(NetworkOffering offering, DeploymentPlan plan, Network use
7772
return null;
7873
}
7974

75+
if (!_sNwMgr.isStorageIpRangeAvailable()) {
76+
return super.design(offering, plan, userSpecified, owner);
77+
}
78+
8079
NetworkVO config = new NetworkVO(offering.getTrafficType(), Mode.Static, BroadcastDomainType.Native, offering.getId(), Network.State.Setup,
8180
plan.getDataCenterId(), plan.getPhysicalNetworkId());
8281
return config;
@@ -86,13 +85,20 @@ public Network design(NetworkOffering offering, DeploymentPlan plan, Network use
8685
public Network implement(Network network, NetworkOffering offering, DeployDestination destination, ReservationContext context)
8786
throws InsufficientVirtualNetworkCapcityException {
8887
assert network.getTrafficType() == TrafficType.Storage : "Why are you sending this configuration to me " + network;
88+
if (!_sNwMgr.isStorageIpRangeAvailable()) {
89+
return super.implement(network, offering, destination, context);
90+
}
8991
return network;
9092
}
9193

9294
@Override
9395
public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm)
94-
throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException {
96+
throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException {
9597
assert network.getTrafficType() == TrafficType.Storage : "Well, I can't take care of this config now can I? " + network;
98+
if (!_sNwMgr.isStorageIpRangeAvailable()) {
99+
return super.allocate(network, nic, vm);
100+
}
101+
96102
return new NicProfile(ReservationStrategy.Start, null, null, null, null);
97103
}
98104

@@ -110,7 +116,12 @@ public boolean releaseIp4Address(Network network, String reservationId) {
110116

111117
@Override
112118
public void reserve(NicProfile nic, Network network, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context)
113-
throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException {
119+
throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException {
120+
if (!_sNwMgr.isStorageIpRangeAvailable()) {
121+
super.reserve(nic, network, vm, dest, context);
122+
return;
123+
}
124+
114125
Pod pod = dest.getPod();
115126
Integer vlan = null;
116127

@@ -136,6 +147,10 @@ public void reserve(NicProfile nic, Network network, VirtualMachineProfile<? ext
136147

137148
@Override
138149
public boolean release(NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, String reservationId) {
150+
if (!_sNwMgr.isStorageIpRangeAvailable()) {
151+
return super.release(nic, vm, reservationId);
152+
}
153+
139154
_sNwMgr.releaseIpAddress(nic.getIp4Address());
140155
s_logger.debug("Release an storage ip " + nic.getIp4Address());
141156
nic.deallocate();

0 commit comments

Comments
 (0)