scripts/kvm-ifdown
author Jens Kasten <jens@kasten-edv.de>
Mon, 19 Mar 2012 04:19:05 +0100
changeset 87 228ce8fbd4ff
parent 55 1d4c061d1502
permissions -rw-r--r--
update readme
0
d05fbfd9a5cf build repository new
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
     1
#!/usr/bin/env python
d05fbfd9a5cf build repository new
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
     2
d05fbfd9a5cf build repository new
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
     3
import sys
d05fbfd9a5cf build repository new
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
     4
import os
d05fbfd9a5cf build repository new
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
     5
from subprocess import call
d05fbfd9a5cf build repository new
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
     6
d05fbfd9a5cf build repository new
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
     7
def del_iface_from_bridge():
d05fbfd9a5cf build repository new
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
     8
    iface = sys.argv[1]
55
1d4c061d1502 update and fixes for new structur
Jens Kasten <jens@kasten-edv.de>
parents: 0
diff changeset
     9
    bridge = "kvm_bridge_%s" % iface
1d4c061d1502 update and fixes for new structur
Jens Kasten <jens@kasten-edv.de>
parents: 0
diff changeset
    10
    if bridge in os.environ:
1d4c061d1502 update and fixes for new structur
Jens Kasten <jens@kasten-edv.de>
parents: 0
diff changeset
    11
        bridge = os.environ[bridge]
1d4c061d1502 update and fixes for new structur
Jens Kasten <jens@kasten-edv.de>
parents: 0
diff changeset
    12
        cmd = ["brctl", "delif", bridge, iface] 
1d4c061d1502 update and fixes for new structur
Jens Kasten <jens@kasten-edv.de>
parents: 0
diff changeset
    13
        call(cmd)
0
d05fbfd9a5cf build repository new
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    14
    # bring down interface
d05fbfd9a5cf build repository new
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    15
    iface_down = ["ip", "link", "set", iface , "down"]
d05fbfd9a5cf build repository new
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    16
    call(iface_down)
d05fbfd9a5cf build repository new
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    17
    # remove tun-tap device
d05fbfd9a5cf build repository new
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    18
    del_iface_from_tun = ["tunctl", "-d", iface]
d05fbfd9a5cf build repository new
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    19
d05fbfd9a5cf build repository new
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    20
del_iface_from_bridge()