You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by hu...@apache.org on 2014/01/08 17:09:27 UTC
[06/11] git commit: updated refs/heads/master to 612a41e
Set unique gre key for every network.
Set interface id to nic uuid when creating the vif.
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/8ddcc9ba
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/8ddcc9ba
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/8ddcc9ba
Branch: refs/heads/master
Commit: 8ddcc9ba808041fbf42fc45f478574502dcad256
Parents: f3f93a9
Author: Hugo Trippaers <ht...@schubergphilis.com>
Authored: Fri Jan 3 10:49:03 2014 +0100
Committer: Hugo Trippaers <ht...@schubergphilis.com>
Committed: Wed Jan 8 16:00:59 2014 +0100
----------------------------------------------------------------------
.../hypervisor/kvm/resource/OvsVifDriver.java | 2 +-
.../agent/OpenDaylightControllerResource.java | 25 +++++++++++++++++++-
.../NeutronNetworksNorthboundAction.java | 12 ++++++----
3 files changed, 32 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8ddcc9ba/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/OvsVifDriver.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/OvsVifDriver.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/OvsVifDriver.java
index 79606b3..c64a472 100644
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/OvsVifDriver.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/OvsVifDriver.java
@@ -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");
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8ddcc9ba/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/agent/OpenDaylightControllerResource.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/agent/OpenDaylightControllerResource.java b/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/agent/OpenDaylightControllerResource.java
index 5c1e1e4..c2b7a67 100644
--- a/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/agent/OpenDaylightControllerResource.java
+++ b/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/agent/OpenDaylightControllerResource.java
@@ -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();
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8ddcc9ba/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/api/resources/NeutronNetworksNorthboundAction.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/api/resources/NeutronNetworksNorthboundAction.java b/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/api/resources/NeutronNetworksNorthboundAction.java
index 2d4f7c9..3a8c187 100644
--- a/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/api/resources/NeutronNetworksNorthboundAction.java
+++ b/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/api/resources/NeutronNetworksNorthboundAction.java
@@ -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);