mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Set unique gre key for every network.
Set interface id to nic uuid when creating the vif.
This commit is contained in:
parent
f3f93a96f5
commit
8ddcc9ba80
@ -83,7 +83,7 @@ public class OvsVifDriver extends VifDriverBase {
|
||||
intf.defBridgeNet(_pifs.get("private"), null, nic.getMac(), getGuestNicModel(guestOsType), networkRateKBps);
|
||||
intf.setVlanTag(Integer.parseInt(vlanId));
|
||||
}
|
||||
} else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Lswitch) {
|
||||
} else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Lswitch || nic.getBroadcastType() == Networks.BroadcastDomainType.OpenDaylight) {
|
||||
s_logger.debug("nic " + nic + " needs to be connected to LogicalSwitch " + logicalSwitchUuid);
|
||||
intf.setVirtualPortInterfaceId(nic.getUuid());
|
||||
String brName = (trafficLabel != null && !trafficLabel.isEmpty()) ? _pifs.get(trafficLabel) : _pifs.get("private");
|
||||
|
||||
@ -26,6 +26,7 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.naming.ConfigurationException;
|
||||
@ -46,6 +47,7 @@ import org.apache.cloudstack.network.opendaylight.agent.responses.DestroyPortAns
|
||||
import org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException;
|
||||
import org.apache.cloudstack.network.opendaylight.api.model.NeutronNetwork;
|
||||
import org.apache.cloudstack.network.opendaylight.api.model.NeutronNetworkWrapper;
|
||||
import org.apache.cloudstack.network.opendaylight.api.model.NeutronNetworksList;
|
||||
import org.apache.cloudstack.network.opendaylight.api.model.NeutronNode;
|
||||
import org.apache.cloudstack.network.opendaylight.api.model.NeutronNodeWrapper;
|
||||
import org.apache.cloudstack.network.opendaylight.api.model.NeutronNodesList;
|
||||
@ -206,6 +208,27 @@ public class OpenDaylightControllerResource implements ServerResource {
|
||||
|
||||
private Answer executeRequest(ConfigureNetworkCommand cmd) {
|
||||
NeutronNetworksNorthboundAction configureNetwork = new NeutronNetworksNorthboundAction(controllerUrl, controllerUsername, controllerPassword);
|
||||
|
||||
// Find free gre key
|
||||
int gre_key = -1;
|
||||
Random keyGenerator = new Random(System.currentTimeMillis());
|
||||
try {
|
||||
NeutronNetworksList<NeutronNetwork> networks = configureNetwork.listAllNetworks();
|
||||
while (true) {
|
||||
int i = keyGenerator.nextInt();
|
||||
for (NeutronNetwork network : networks.getNetworks()) {
|
||||
if (network.getSegmentationId() == i) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
gre_key = i;
|
||||
break;
|
||||
}
|
||||
} catch (NeutronRestApiException e) {
|
||||
s_logger.error("Failed to list existing networks on the ODL Controller", e);
|
||||
return new ConfigureNetworkAnswer(cmd, e);
|
||||
}
|
||||
|
||||
NeutronNetwork newNetwork = new NeutronNetwork();
|
||||
|
||||
// Configuration from the command
|
||||
@ -215,7 +238,7 @@ public class OpenDaylightControllerResource implements ServerResource {
|
||||
// Static configuation
|
||||
newNetwork.setNetworkType("gre");
|
||||
newNetwork.setShared(false);
|
||||
newNetwork.setSegmentationId(100);
|
||||
newNetwork.setSegmentationId(gre_key);
|
||||
newNetwork.setId(UUID.randomUUID());
|
||||
|
||||
NeutronNetworkWrapper wrapper = new NeutronNetworkWrapper();
|
||||
|
||||
@ -25,10 +25,6 @@ import java.net.URL;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException;
|
||||
import org.apache.cloudstack.network.opendaylight.api.enums.NeutronNorthboundEnum;
|
||||
import org.apache.cloudstack.network.opendaylight.api.model.NeutronNetworkWrapper;
|
||||
import org.apache.cloudstack.network.opendaylight.api.model.NeutronNetworksList;
|
||||
import org.apache.commons.httpclient.methods.StringRequestEntity;
|
||||
|
||||
import com.google.gson.FieldNamingPolicy;
|
||||
@ -36,6 +32,12 @@ import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException;
|
||||
import org.apache.cloudstack.network.opendaylight.api.enums.NeutronNorthboundEnum;
|
||||
import org.apache.cloudstack.network.opendaylight.api.model.NeutronNetwork;
|
||||
import org.apache.cloudstack.network.opendaylight.api.model.NeutronNetworkWrapper;
|
||||
import org.apache.cloudstack.network.opendaylight.api.model.NeutronNetworksList;
|
||||
|
||||
public class NeutronNetworksNorthboundAction extends Action {
|
||||
|
||||
private final Gson gsonNeutronNetwork;
|
||||
@ -50,7 +52,7 @@ public class NeutronNetworksNorthboundAction extends Action {
|
||||
String uri = NeutronNorthboundEnum.NETWORKS_URI.getUri();
|
||||
String bodystring = executeGet(uri, Collections.<String, String> emptyMap());
|
||||
|
||||
Type returnType = new TypeToken<NeutronNetworksList<NeutronNetworkWrapper>>() {
|
||||
Type returnType = new TypeToken<NeutronNetworksList<NeutronNetwork>>() {
|
||||
}.getType();
|
||||
|
||||
T returnValue = (T) gsonNeutronNetwork.fromJson(bodystring, returnType);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user