source: trunk/packages/xen-common/xen-common/tools/examples/vif-bridge @ 34

Last change on this file since 34 was 34, checked in by hartmans, 18 years ago

Add xen and xen-common

  • Property svn:executable set to *
File size: 1.9 KB
Line 
1#!/bin/bash
2#============================================================================
3# /etc/xen/vif-bridge
4#
5# Script for configuring a vif in bridged mode.
6# The hotplugging system will call this script if it is specified either in
7# the device configuration given to Xend, or the default Xend configuration
8# in /etc/xen/xend-config.sxp.  If the script is specified in neither of those
9# places, then this script is the default.
10#
11# Usage:
12# vif-bridge (add|remove|online|offline)
13#
14# Environment vars:
15# vif         vif interface name (required).
16# XENBUS_PATH path to this device's details in the XenStore (required).
17#
18# Read from the store:
19# bridge  bridge to add the vif to (optional).  Defaults to searching for the
20#         bridge itself.
21# ip      list of IP networks for the vif, space-separated (optional).
22#
23# up:
24# Enslaves the vif interface to the bridge and adds iptables rules
25# for its ip addresses (if any).
26#
27# down:
28# Removes the vif interface from the bridge and removes the iptables
29# rules for its ip addresses (if any).
30#============================================================================
31
32dir=$(dirname "$0")
33. "$dir/vif-common.sh"
34
35bridge=${bridge:-}
36bridge=$(xenstore_read_default "$XENBUS_PATH/bridge" "$bridge")
37
38if [ -z "$bridge" ]
39then
40  bridge=$(brctl show | cut -d "
41" -f 2 | cut -f 1)
42
43  if [ -z "$bridge" ]
44  then
45     fatal "Could not find bridge, and none was specified"
46  fi
47fi
48
49RET=0
50ip link show $bridge 1>/dev/null 2>&1 || RET=1
51if [ "$RET" -eq 1 ]
52then
53    fatal "Could not find bridge device $bridge"
54fi
55
56case "$command" in
57    online)
58        setup_bridge_port "$vif"
59        add_to_bridge "$bridge" "$vif"
60        ;;
61
62    offline)
63        do_without_error brctl delif "$bridge" "$vif"
64        do_without_error ifconfig "$vif" down
65        ;;
66esac
67
68handle_iptable
69
70log debug "Successful vif-bridge $command for $vif, bridge $bridge."
71if [ "$command" = "online" ]
72then
73  success
74fi
Note: See TracBrowser for help on using the repository browser.