cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From prachida...@apache.org
Subject [06/31] git commit: updated refs/heads/planner_reserve to db4f335
Date Thu, 16 May 2013 19:23:06 GMT
PVLAN: Add network label parameter to PvlanSetupCommand

We need it to find the real bridge/switch to program on the OVS.



Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/40386fc4
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/40386fc4
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/40386fc4

Branch: refs/heads/planner_reserve
Commit: 40386fc4cb6841c8cc6b8458c9ebd80d4c8ffb4f
Parents: 142f3b3
Author: Sheng Yang <sheng.yang@citrix.com>
Authored: Wed May 1 13:23:09 2013 -0700
Committer: Sheng Yang <sheng.yang@citrix.com>
Committed: Wed May 1 13:23:09 2013 -0700

----------------------------------------------------------------------
 api/src/com/cloud/agent/api/PvlanSetupCommand.java |   16 ++++++---
 .../xen/resource/CitrixResourceBase.java           |   19 +++++++++--
 scripts/vm/hypervisor/xenserver/ovs-get-bridge.sh  |   27 +++++++++++++++
 scripts/vm/hypervisor/xenserver/ovs-pvlan          |   13 +++++--
 scripts/vm/hypervisor/xenserver/xenserver60/patch  |    1 +
 .../router/VirtualNetworkApplianceManagerImpl.java |    4 ++-
 server/src/com/cloud/vm/UserVmManagerImpl.java     |    5 ++-
 7 files changed, 72 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/40386fc4/api/src/com/cloud/agent/api/PvlanSetupCommand.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/agent/api/PvlanSetupCommand.java b/api/src/com/cloud/agent/api/PvlanSetupCommand.java
index 0426219..ee1f046 100644
--- a/api/src/com/cloud/agent/api/PvlanSetupCommand.java
+++ b/api/src/com/cloud/agent/api/PvlanSetupCommand.java
@@ -33,29 +33,31 @@ public class PvlanSetupCommand extends Command {
 	private String dhcpMac;
 	private String dhcpIp;
 	private Type type;
+	private String networkTag;
 
 	protected PvlanSetupCommand() {}
 	
-	protected PvlanSetupCommand(Type type, String op, URI uri)
+	protected PvlanSetupCommand(Type type, String op, URI uri, String networkTag)
 	{
 		this.type = type;
 		this.op = op;
 		this.primary = NetUtils.getPrimaryPvlanFromUri(uri);
 		this.isolated = NetUtils.getIsolatedPvlanFromUri(uri);
+		this.networkTag = networkTag;
 	}
 	
-	static public PvlanSetupCommand createDhcpSetup(String op, URI uri, String dhcpName, String
dhcpMac, String dhcpIp)
+	static public PvlanSetupCommand createDhcpSetup(String op, URI uri, String networkTag, String
dhcpName, String dhcpMac, String dhcpIp)
 	{
-		PvlanSetupCommand cmd = new PvlanSetupCommand(Type.DHCP, op, uri);
+		PvlanSetupCommand cmd = new PvlanSetupCommand(Type.DHCP, op, uri, networkTag);
 		cmd.setDhcpName(dhcpName);
 		cmd.setDhcpMac(dhcpMac);
 		cmd.setDhcpIp(dhcpIp);
 		return cmd;
 	}
 	
-	static public PvlanSetupCommand createVmSetup(String op, URI uri, String vmMac)
+	static public PvlanSetupCommand createVmSetup(String op, URI uri, String networkTag, String
vmMac)
 	{
-		PvlanSetupCommand cmd = new PvlanSetupCommand(Type.VM, op, uri);
+		PvlanSetupCommand cmd = new PvlanSetupCommand(Type.VM, op, uri, networkTag);
 		cmd.setVmMac(vmMac);
 		return cmd;
 	}
@@ -112,4 +114,8 @@ public class PvlanSetupCommand extends Command {
 	public void setDhcpName(String dhcpName) {
 		this.dhcpName = dhcpName;
 	}
+
+	public String getNetworkTag() {
+		return networkTag;
+	}
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/40386fc4/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
index d25938f..d616e1b 100644
--- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
+++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
@@ -1478,11 +1478,24 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
     	String dhcpMac = cmd.getDhcpMac();
     	String dhcpIp = cmd.getDhcpIp();
     	String vmMac = cmd.getVmMac();
+    	String networkTag = cmd.getNetworkTag();
+    	
+    	XsLocalNetwork nw = null;
+    	String nwNameLabel = null;
+    	try {
+			nw = getNativeNetworkForTraffic(conn, TrafficType.Guest, networkTag);
+			nwNameLabel = nw.getNetwork().getNameLabel(conn);
+		} catch (XenAPIException e) {
+			s_logger.warn("Fail to get network", e);
+    		return new Answer(cmd, false, e.toString());
+		} catch (XmlRpcException e) {
+			s_logger.warn("Fail to get network", e);
+    		return new Answer(cmd, false, e.toString());
+		}
     	
-    	String bridge = "xenbr0";
     	String result = null;
     	if (cmd.getType() == PvlanSetupCommand.Type.DHCP) {
-    		result = callHostPlugin(conn, "ovs-pvlan", "setup-pvlan-dhcp", "op", op, "bridge",
bridge,
+    		result = callHostPlugin(conn, "ovs-pvlan", "setup-pvlan-dhcp", "op", op, "nw-label",
nwNameLabel,
     				"primary-pvlan", primaryPvlan, "isolated-pvlan", isolatedPvlan, "dhcp-name", dhcpName,
     				"dhcp-ip", dhcpIp, "dhcp-mac", dhcpMac);
     		if (result == null || result.isEmpty() || !Boolean.parseBoolean(result)) {
@@ -1492,7 +1505,7 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
     			s_logger.info("Programmed pvlan for dhcp server with mac " + dhcpMac);
     		}
     	} else if (cmd.getType() == PvlanSetupCommand.Type.VM) {
-    		result = callHostPlugin(conn, "ovs-pvlan", "setup-pvlan-vm", "op", op, "bridge", bridge,
+    		result = callHostPlugin(conn, "ovs-pvlan", "setup-pvlan-vm", "op", op, "nw-label",
nwNameLabel,
     				"primary-pvlan", primaryPvlan, "isolated-pvlan", isolatedPvlan, "vm-mac", vmMac);
     		if (result == null || result.isEmpty() || !Boolean.parseBoolean(result)) {
     			s_logger.warn("Failed to program pvlan for vm with mac " + vmMac);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/40386fc4/scripts/vm/hypervisor/xenserver/ovs-get-bridge.sh
----------------------------------------------------------------------
diff --git a/scripts/vm/hypervisor/xenserver/ovs-get-bridge.sh b/scripts/vm/hypervisor/xenserver/ovs-get-bridge.sh
new file mode 100755
index 0000000..f56ddf9
--- /dev/null
+++ b/scripts/vm/hypervisor/xenserver/ovs-get-bridge.sh
@@ -0,0 +1,27 @@
+#!/bin/bash
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+nw_label=$1
+br=`xe network-list name-label="$nw_label" params=bridge |cut -d ':' -f 2 |tr -d ' ' `
+pbr=`ovs-vsctl br-to-parent $br`
+while [ "$br" != "$pbr" ]
+do
+    br=$pbr
+    pbr=`ovs-vsctl br-to-parent $br`
+done
+echo $pbr

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/40386fc4/scripts/vm/hypervisor/xenserver/ovs-get-dhcp-port.sh
----------------------------------------------------------------------
diff --git a/scripts/vm/hypervisor/xenserver/ovs-get-dhcp-port.sh b/scripts/vm/hypervisor/xenserver/ovs-get-dhcp-port.sh
old mode 100644
new mode 100755

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/40386fc4/scripts/vm/hypervisor/xenserver/ovs-pvlan
----------------------------------------------------------------------
diff --git a/scripts/vm/hypervisor/xenserver/ovs-pvlan b/scripts/vm/hypervisor/xenserver/ovs-pvlan
index 372d3c8..956ea6d 100755
--- a/scripts/vm/hypervisor/xenserver/ovs-pvlan
+++ b/scripts/vm/hypervisor/xenserver/ovs-pvlan
@@ -36,6 +36,7 @@ dhcpSetupPath = "/opt/xensource/bin/ovs-pvlan-dhcp-host.sh"
 vmSetupPath = "/opt/xensource/bin/ovs-pvlan-vm.sh"
 getDhcpPortPath = "/opt/xensource/bin/ovs-get-dhcp-port.sh"
 pvlanCleanupPath = "/opt/xensource/bin/ovs-pvlan-cleanup.sh"
+getBridgePath = "/opt/xensource/bin/ovs-get-bridge.sh"
 
 def echo(fn):
     def wrapped(*v, **k):
@@ -46,11 +47,10 @@ def echo(fn):
         return res
     return wrapped
 
-
 @echo
 def setup_pvlan_dhcp(session, args):
     op = args.pop("op")
-    bridge = args.pop("bridge")
+    nw_label = args.pop("nw-label")
     primary = args.pop("primary-pvlan")
     isolated = args.pop("isolated-pvlan")
     dhcp_name = args.pop("dhcp-name")
@@ -61,6 +61,10 @@ def setup_pvlan_dhcp(session, args):
     if res != "SUCCESS":
         return "FAILURE:%s" % res
 
+    logging.debug("Network is:%s" % (nw_label))
+    bridge = lib.do_cmd([getBridgePath, nw_label])
+    logging.debug("Determine bridge/switch is :%s" % (bridge))
+
     if op == "add":
         logging.debug("Try to get dhcp vm %s port on the switch:%s" % (dhcp_name, bridge))
         dhcp_port = lib.do_cmd([getDhcpPortPath, bridge, dhcp_name])
@@ -88,7 +92,7 @@ def setup_pvlan_dhcp(session, args):
 @echo
 def setup_pvlan_vm(session, args):
     op = args.pop("op")
-    bridge = args.pop("bridge")
+    nw_label = args.pop("nw-label")
     primary = args.pop("primary-pvlan")
     isolated = args.pop("isolated-pvlan")
     vm_mac = args.pop("vm-mac")
@@ -98,6 +102,9 @@ def setup_pvlan_vm(session, args):
     if res != "SUCCESS":
         return "FAILURE:%s" % res
 
+    bridge = lib.do_cmd([getBridgePath, nw_label])
+    logging.debug("Determine bridge/switch is :%s" % (bridge))
+
     if op == "add":
         logging.debug("About to setup vm on the switch:%s" % bridge)
         res = lib.do_cmd([vmSetupPath, "-A", "-b", bridge, "-p", primary, "-i", isolated,
"-v", vm_mac])

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/40386fc4/scripts/vm/hypervisor/xenserver/xenserver60/patch
----------------------------------------------------------------------
diff --git a/scripts/vm/hypervisor/xenserver/xenserver60/patch b/scripts/vm/hypervisor/xenserver/xenserver60/patch
index 9759519..fe36ba9 100644
--- a/scripts/vm/hypervisor/xenserver/xenserver60/patch
+++ b/scripts/vm/hypervisor/xenserver/xenserver60/patch
@@ -72,3 +72,4 @@ ovs-pvlan-dhcp-host.sh=../../../network,0755,/opt/xensource/bin
 ovs-pvlan-vm.sh=../../../network,0755,/opt/xensource/bin
 ovs-pvlan-cleanup.sh=../../../network,0755,/opt/xensource/bin
 ovs-get-dhcp-port.sh=..,0755,/opt/xensource/bin
+ovs-get-bridge.sh=..,0755,/opt/xensource/bin

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/40386fc4/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
index 59a9f05..a5098ae 100755
--- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
@@ -2219,7 +2219,9 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase
implements V
     	if (!add) {
     		op = "delete";
     	}
-    	PvlanSetupCommand cmd = PvlanSetupCommand.createDhcpSetup(op, nic.getBroadcastUri(),
router.getInstanceName(), nic.getMacAddress(), nic.getIp4Address());
+    	Network network = _networkDao.findById(nic.getNetworkId());
+    	String networkTag = _networkModel.getNetworkTag(router.getHypervisorType(), network);
+    	PvlanSetupCommand cmd = PvlanSetupCommand.createDhcpSetup(op, nic.getBroadcastUri(),
networkTag, router.getInstanceName(), nic.getMacAddress(), nic.getIp4Address());
     	Commands cmds = new Commands(cmd);
     	// In fact we send command to the host of router, we're not programming router but the
host
     	try {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/40386fc4/server/src/com/cloud/vm/UserVmManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java
index 6ea2952..683f0da 100755
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@ -2761,7 +2761,10 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager,
Use
         	// "delete" would remove all the rules(if using ovs) related to this vm
         	op = "delete";
         }
-    	PvlanSetupCommand cmd = PvlanSetupCommand.createVmSetup(op, nic.getBroadcastUri(), nic.getMacAddress());
+        Network network = _networkDao.findById(nic.getNetworkId());
+        Host host = _hostDao.findById(hostId);
+        String networkTag = _networkModel.getNetworkTag(host.getHypervisorType(), network);
+    	PvlanSetupCommand cmd = PvlanSetupCommand.createVmSetup(op, nic.getBroadcastUri(), networkTag,
nic.getMacAddress());
         Answer answer = null;
         try {
             answer = _agentMgr.send(hostId, cmd);


Mime
View raw message