PVLAN: PvlanSetupCommand for KVM support


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

Branch: refs/heads/ui-vpc-redesign
Commit: 3c3d67769b9b82c04ed670754fda8e36b7afc66a
Parents: 40386fc
Author: Sheng Yang <[email protected]>
Authored: Wed May 1 13:23:09 2013 -0700
Committer: Sheng Yang <[email protected]>
Committed: Wed May 1 13:23:09 2013 -0700

----------------------------------------------------------------------
 .../kvm/resource/LibvirtComputingResource.java     |   76 +++++++++++++++
 .../hypervisor/kvm/resource/OvsVifDriver.java      |    2 +-
 .../vm/hypervisor/xenserver/ovs-get-dhcp-iface.sh  |   25 +++++
 .../vm/hypervisor/xenserver/ovs-get-dhcp-port.sh   |   26 -----
 scripts/vm/hypervisor/xenserver/ovs-pvlan          |    6 +-
 scripts/vm/hypervisor/xenserver/xenserver60/patch  |    2 +-
 scripts/vm/network/ovs-pvlan-dhcp-host.sh          |   15 ++--
 7 files changed, 113 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3c3d6776/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
----------------------------------------------------------------------
diff --git 
a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
 
b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
index 0064edf..dc8bf9d 100755
--- 
a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
+++ 
b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
@@ -125,6 +125,7 @@ import com.cloud.agent.api.PlugNicAnswer;
 import com.cloud.agent.api.PlugNicCommand;
 import com.cloud.agent.api.PrepareForMigrationAnswer;
 import com.cloud.agent.api.PrepareForMigrationCommand;
+import com.cloud.agent.api.PvlanSetupCommand;
 import com.cloud.agent.api.ReadyAnswer;
 import com.cloud.agent.api.ReadyCommand;
 import com.cloud.agent.api.RebootAnswer;
@@ -267,6 +268,8 @@ ServerResource {
     private String _createTmplPath;
     private String _heartBeatPath;
     private String _securityGroupPath;
+    private String _ovsPvlanDhcpHostPath;
+    private String _ovsPvlanVmPath;
     private String _routerProxyPath;
     private String _host;
     private String _dcId;
@@ -587,6 +590,18 @@ ServerResource {
                     "Unable to find the router_proxy.sh");
         }
 
+        _ovsPvlanDhcpHostPath = Script.findScript(networkScriptsDir, 
"ovs-pvlan-dhcp-host.sh");
+        if ( _ovsPvlanDhcpHostPath == null) {
+            throw new ConfigurationException(
+                    "Unable to find the ovs-pvlan-dhcp-host.sh");
+        }
+        
+        _ovsPvlanVmPath = Script.findScript(networkScriptsDir, 
"ovs-pvlan-vm.sh");
+        if ( _ovsPvlanVmPath == null) {
+            throw new ConfigurationException(
+                    "Unable to find the ovs-pvlan-vm.sh");
+        }
+        
         String value = (String) params.get("developer");
         boolean isDeveloper = Boolean.parseBoolean(value);
 
@@ -1202,6 +1217,8 @@ ServerResource {
                 return execute((CheckNetworkCommand) cmd);
             } else if (cmd instanceof NetworkRulesVmSecondaryIpCommand) {
                 return execute((NetworkRulesVmSecondaryIpCommand) cmd);
+            } else if (cmd instanceof PvlanSetupCommand) {
+                return execute((PvlanSetupCommand) cmd);
             } else {
                 s_logger.warn("Unsupported command ");
                 return Answer.createUnsupportedCommandAnswer(cmd);
@@ -1517,6 +1534,65 @@ ServerResource {
         }
     }
 
+    private Answer execute(PvlanSetupCommand cmd) {
+       String primaryPvlan = cmd.getPrimary();
+       String isolatedPvlan = cmd.getIsolated();
+       String op = cmd.getOp();
+       String dhcpName = cmd.getDhcpName();
+       String dhcpMac = cmd.getDhcpMac();
+       String dhcpIp = cmd.getDhcpIp();
+       String vmMac = cmd.getVmMac();
+       boolean add = true;
+       
+       String opr = "-A";
+       if (op.equals("delete"))  {
+               opr = "-D";
+               add = false;
+       }
+       
+       String result = null;
+        Connect conn;
+               try {
+                       if (cmd.getType() == PvlanSetupCommand.Type.DHCP) {
+                               Script script = new 
Script(_ovsPvlanDhcpHostPath, _timeout, s_logger);
+                               if (add) {
+                                       conn = 
LibvirtConnection.getConnectionByVmName(dhcpName);
+                                       List<InterfaceDef> ifaces = 
getInterfaces(conn, dhcpName);
+                                       InterfaceDef guestNic = ifaces.get(0);
+                                       script.add(opr, "-b", _guestBridgeName,
+                                               "-p", primaryPvlan, "-i", 
isolatedPvlan, "-n", dhcpName,
+                                               "-d", dhcpIp, "-m", dhcpMac, 
"-I", guestNic.getDevName());
+                               } else {
+                                       script.add(opr, "-b", _guestBridgeName,
+                                               "-p", primaryPvlan, "-i", 
isolatedPvlan, "-n", dhcpName,
+                                               "-d", dhcpIp, "-m", dhcpMac);
+                               }
+                               result = script.execute();
+                               if (result != null) {
+                                       s_logger.warn("Failed to program pvlan 
for dhcp server with mac " + dhcpMac);
+                                       return new Answer(cmd, false, result);
+                               } else {
+                                       s_logger.info("Programmed pvlan for 
dhcp server with mac " + dhcpMac);
+                               }
+                       } else if (cmd.getType() == PvlanSetupCommand.Type.VM) {
+                               Script script = new Script(_ovsPvlanVmPath, 
_timeout, s_logger);
+                               script.add(opr, "-b", _guestBridgeName,
+                                               "-p", primaryPvlan, "-i", 
isolatedPvlan, "-v", vmMac);
+                               result = script.execute();
+                               if (result != null) {
+                                       s_logger.warn("Failed to program pvlan 
for vm with mac " + vmMac);
+                                       return new Answer(cmd, false, result);
+                               } else {
+                                       s_logger.info("Programmed pvlan for vm 
with mac " + vmMac);
+                               }
+                       }
+               } catch (LibvirtException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               }
+       return new Answer(cmd, true, result);
+    }
+
     private void VifHotPlug(Connect conn, String vmName, String vlanId,
             String macAddr) throws InternalErrorException, LibvirtException {
         NicTO nicTO = new NicTO();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3c3d6776/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 37761aa..ac226e2 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
@@ -79,7 +79,7 @@ public class OvsVifDriver extends VifDriverBase {
         }
         String trafficLabel = nic.getName();
         if (nic.getType() == Networks.TrafficType.Guest) {
-            if (nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan
+            if ((nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan 
|| nic.getBroadcastType() == Networks.BroadcastDomainType.Pvlan)
                     && !vlanId.equalsIgnoreCase("untagged")) {
                 if(trafficLabel != null && !trafficLabel.isEmpty()) {
                     s_logger.debug("creating a vlan dev and bridge for guest 
traffic per traffic label " + trafficLabel);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3c3d6776/scripts/vm/hypervisor/xenserver/ovs-get-dhcp-iface.sh
----------------------------------------------------------------------
diff --git a/scripts/vm/hypervisor/xenserver/ovs-get-dhcp-iface.sh 
b/scripts/vm/hypervisor/xenserver/ovs-get-dhcp-iface.sh
new file mode 100755
index 0000000..6b30ee6
--- /dev/null
+++ b/scripts/vm/hypervisor/xenserver/ovs-get-dhcp-iface.sh
@@ -0,0 +1,25 @@
+#!/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.
+
+#!/bin/bash
+
+bridge=$1
+dhcp_name=$2
+dom_id=`xe vm-list is-control-domain=false power-state=running params=dom-id 
name-label=$dhcp_name|cut -d ':' -f 2 |tr -d ' ' `
+iface="vif${dom_id}.0"
+echo $iface

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3c3d6776/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
deleted file mode 100755
index a30b180..0000000
--- a/scripts/vm/hypervisor/xenserver/ovs-get-dhcp-port.sh
+++ /dev/null
@@ -1,26 +0,0 @@
-#!/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.
-
-#!/bin/bash
-
-bridge=$1
-dhcp_name=$2
-dom_id=`xe vm-list is-control-domain=false power-state=running params=dom-id 
name-label=$dhcp_name|cut -d ':' -f 2 |tr -d ' ' `
-iface="vif${dom_id}.0"
-port=`ovs-ofctl show $bridge|grep $iface|cut -d '(' -f 1|tr -d ' '`
-echo $port

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3c3d6776/scripts/vm/hypervisor/xenserver/ovs-pvlan
----------------------------------------------------------------------
diff --git a/scripts/vm/hypervisor/xenserver/ovs-pvlan 
b/scripts/vm/hypervisor/xenserver/ovs-pvlan
index 956ea6d..c821870 100755
--- a/scripts/vm/hypervisor/xenserver/ovs-pvlan
+++ b/scripts/vm/hypervisor/xenserver/ovs-pvlan
@@ -34,7 +34,7 @@ xePath = "/opt/xensource/bin/xe"
 lib.setup_logging("/var/log/ovs-pvlan.log")
 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"
+getDhcpIfacePath = "/opt/xensource/bin/ovs-get-dhcp-iface.sh"
 pvlanCleanupPath = "/opt/xensource/bin/ovs-pvlan-cleanup.sh"
 getBridgePath = "/opt/xensource/bin/ovs-get-bridge.sh"
 
@@ -67,11 +67,11 @@ def setup_pvlan_dhcp(session, args):
 
     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])
+        dhcp_iface = lib.do_cmd([getDhcpIfacePath, bridge, dhcp_name])
         logging.debug("About to setup dhcp vm on the switch:%s" % bridge)
         res = lib.do_cmd([dhcpSetupPath, "-A", "-b", bridge, "-p", primary,
             "-i", isolated, "-n", dhcp_name, "-d", dhcp_ip, "-m", dhcp_mac,
-            "-P", dhcp_port])
+            "-I", dhcp_iface])
        if res:
            result = "FAILURE:%s" % res
            return result;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3c3d6776/scripts/vm/hypervisor/xenserver/xenserver60/patch
----------------------------------------------------------------------
diff --git a/scripts/vm/hypervisor/xenserver/xenserver60/patch 
b/scripts/vm/hypervisor/xenserver/xenserver60/patch
index fe36ba9..9af32b1 100644
--- a/scripts/vm/hypervisor/xenserver/xenserver60/patch
+++ b/scripts/vm/hypervisor/xenserver/xenserver60/patch
@@ -71,5 +71,5 @@ ovs-pvlan=..,0755,/etc/xapi.d/plugins
 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-dhcp-iface.sh=..,0755,/opt/xensource/bin
 ovs-get-bridge.sh=..,0755,/opt/xensource/bin

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3c3d6776/scripts/vm/network/ovs-pvlan-dhcp-host.sh
----------------------------------------------------------------------
diff --git a/scripts/vm/network/ovs-pvlan-dhcp-host.sh 
b/scripts/vm/network/ovs-pvlan-dhcp-host.sh
index 93f5653..73d735f 100755
--- a/scripts/vm/network/ovs-pvlan-dhcp-host.sh
+++ b/scripts/vm/network/ovs-pvlan-dhcp-host.sh
@@ -18,10 +18,8 @@
 
 #!/bin/bash
 
-source ovs-func.sh
-
 usage() {
-  printf "Usage: %s: (-A|-D) -b <bridge/switch> -p <primary vlan> -i 
<secondary isolated vlan> -n <DHCP server name> -d <DHCP server IP> -m <DHCP 
server MAC> -P <DHCP on OVS port> -v <VM MAC> -h \n" $(basename $0) >&2
+  printf "Usage: %s: (-A|-D) -b <bridge/switch> -p <primary vlan> -i 
<secondary isolated vlan> -n <DHCP server name> -d <DHCP server IP> -m <DHCP 
server MAC> -I <interface> -v <VM MAC> -h \n" $(basename $0) >&2
   exit 2
 }
 
@@ -31,11 +29,11 @@ sec_iso_vlan=
 dhcp_name=
 dhcp_ip=
 dhcp_mac=
-dhcp_port=
 vm_mac=
+iface=
 op=
 
-while getopts 'ADb:p:i:d:m:v:n:P:h' OPTION
+while getopts 'ADb:p:i:d:m:v:n:I:h' OPTION
 do
   case $OPTION in
   A)  op="add"
@@ -54,7 +52,7 @@ do
       ;;
   m)  dhcp_mac="$OPTARG"
       ;;
-  P)  dhcp_port="$OPTARG"
+  I)  iface="$OPTARG"
       ;;
   v)  vm_mac="$OPTARG"
       ;;
@@ -106,14 +104,15 @@ then
     exit 1
 fi
 
-if [ "$op" == "add" -a -z "$dhcp_port" ]
+if [ "$op" == "add" -a -z "$iface" ]
 then
-    echo Missing parameter DHCP PORT!
+    echo Missing parameter DHCP VM interface!
     exit 1
 fi
 
 if [ "$op" == "add" ]
 then
+    dhcp_port=`ovs-ofctl show $br | grep $iface | cut -d '(' -f 1|tr -d ' '`
     ovs-ofctl add-flow $br 
priority=200,arp,dl_vlan=$sec_iso_vlan,nw_dst=$dhcp_ip,actions=strip_vlan,output:$dhcp_port
     ovs-ofctl add-flow $br 
priority=180,arp,nw_dst=$dhcp_ip,actions=strip_vlan,output:$dhcp_port
     ovs-ofctl add-flow $br 
priority=150,dl_vlan=$sec_iso_vlan,dl_dst=$dhcp_mac,actions=strip_vlan,output:$dhcp_port

Reply via email to