PVLAN: Add network label parameter to PvlanSetupCommand

We need it to find the real bridge/switch to program on the OVS.
This commit is contained in:
Sheng Yang 2013-05-01 13:23:09 -07:00
parent 142f3b30f4
commit 40386fc4cb
8 changed files with 72 additions and 13 deletions

View File

@ -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;
}
}

View File

@ -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);

View File

@ -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

0
scripts/vm/hypervisor/xenserver/ovs-get-dhcp-port.sh Normal file → Executable file
View File

View File

@ -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])

View File

@ -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

View File

@ -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 {

View File

@ -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);