File: Debian_functions

package info (click to toggle)
convirt 1.1-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 3,784 kB
  • ctags: 2,602
  • sloc: python: 22,446; sh: 1,845; makefile: 47
file content (115 lines) | stat: -rw-r--r-- 3,371 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
#
#   ConVirt   -  Copyright (c) 2008 Convirture Corp.
#   ======
#
# ConVirt is a Virtualization management tool with a graphical user
# interface that allows for performing the standard set of VM operations
# (start, stop, pause, kill, shutdown, reboot, snapshot, etc...). It
# also attempts to simplify various aspects of VM lifecycle management.
#
#
# This software is subject to the GNU General Public License, Version 2 (GPLv2)
# and for details, please consult it at:
#
#    http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
# 
#
# author : Jd <jd_jedi@users.sourceforge.net>
#

# Distribution and version specific code can go here.
# Assume that common functions are included
# Assme the DIST and the VER to be set here.
open_ports()
{
    echo "open_ports : not implemented for ${DIST} distribution. "
    echo "If you are using firewall, please open 8002 and 8006 ports."
    echo "These are required for ConVirt to connect succesfully"
    return 0
}
# Restart the network
restart_network()
{
    /etc/init.d/networking restart
    return 0
}
# update the network service
setup_nw_svc()
{
    # default dnsmasq service is causing problems. disable it.
    echo "Disabling default dnsmasq service."
    /etc/init.d/dnsmasq stop
    update-rc.d -f dnsmasq remove
    update-rc.d convirt-nw defaults
    return 0
}

verify_bridge(){
  match_found=`grep "^auto $bridgeName" -c /etc/network/interfaces`
  if [  $match_found -gt 0 ]; then
    return 1
  fi
  return 0
}

# Milind : Implementation for Debian/Ubuntu
# Bridge parameters from 
# https://help.ubuntu.com/community/KVM/Networking
#
setup_public_bridge_for_kvm() { 
  # create a backup file so people can restore easily
  NW_FILE=/etc/network/interfaces
  BACKUP_FILE=$NW_FILE.`date +"%Y%m%d.%H%M%S"`
  cp $NW_FILE $BACKUP_FILE
  CHANGED="F" 
  # Iterate through interfaces
  PHY_IFACES=`get_physical_interfaces`
  for iface in $PHY_IFACES
  do 
    index=`echo $iface | sed 's/^[^0-9]*//'`
    bridgeName=br$index

    # check if the interface is not already part of some other 
    # bridge
    grep "bridge_ports .*$iface" $NW_FILE >/dev/null 2>/dev/null
    if [ $? != 1 ]; then
       echo "interface $iface already part of bridge. skiping it"
       continue
    fi

    verify_bridge
    if [ "$?" == "0" ]; then
      CHANGED="T"
      # look for interface entry in NW_FILE, if not, add it.
      grep "iface .*$iface inet" $NW_FILE >/dev/null 2>/dev/null
      if [ $? == 1 ]; then
         echo "" >> $NW_FILE
         echo "auto $iface" >> $NW_FILE  
         echo "iface $iface inet manual" >> $NW_FILE  
      fi
      echo ""  >> $NW_FILE
      echo "auto $bridgeName"  >> $NW_FILE
      echo "iface $bridgeName inet dhcp" >> $NW_FILE
      echo "  bridge_ports $iface" >> $NW_FILE
      echo "  bridge_fd 0" >> $NW_FILE
      echo "  bridge_stp off" >> $NW_FILE
      echo "  bridge_maxwait 0" >> $NW_FILE
      echo ""  >> $NW_FILE

      mkdir -p /etc/kvm
      sed  "{s/SWITCH_NAME/$bridgeName/} " < ${common_scripts}/qemubridge-ifup > /etc/kvm/qemu-ifup-${bridgeName}
      chmod 744 /etc/kvm/qemu-ifup-${bridgeName}
     
      # switch the interface to manual
      sed -i "s/iface $iface inet.*/iface $iface inet manual/" $NW_FILE 
      
    fi
  done
  if [ "$CHANGED" == "T" ]; then
     enable_ip_forward
     restart_network
  else
     rm -f $BACKUP_FILE
  fi
}