Contents of /trunk/vzctl/magellan-add_ip.sh
Parent Directory | Revision Log
Revision 272 -
(show annotations)
(download)
(as text)
Sat Jul 21 22:43:26 2007 UTC (17 years, 2 months ago) by niro
File MIME type: application/x-sh
File size: 2983 byte(s)
Sat Jul 21 22:43:26 2007 UTC (17 years, 2 months ago) by niro
File MIME type: application/x-sh
File size: 2983 byte(s)
-magellan specific vzctl files
1 | #!/bin/bash |
2 | # Copyright (C) 2000-2007 SWsoft. All rights reserved. |
3 | # |
4 | # This program is free software; you can redistribute it and/or modify |
5 | # it under the terms of the GNU General Public License as published by |
6 | # the Free Software Foundation; either version 2 of the License, or |
7 | # (at your option) any later version. |
8 | # |
9 | # This program is distributed in the hope that it will be useful, |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | # GNU General Public License for more details. |
13 | # |
14 | # You should have received a copy of the GNU General Public License |
15 | # along with this program; if not, write to the Free Software |
16 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 | # |
18 | # |
19 | # This script configure IP alias(es) inside Magellan like VE. |
20 | # |
21 | # Parameters are passed in environment variables. |
22 | # Required parameters: |
23 | # IP_ADDR - IP address(es) to add |
24 | # (several addresses should be divided by space) |
25 | # Optional parameters: |
26 | # VE_STATE - state of VE; could be one of: |
27 | # starting | stopping | running | stopped |
28 | # IPDELALL - delete all old interfaces |
29 | # |
30 | |
31 | VENET_DEV=venet0 |
32 | IFCFG_DIR=/etc/conf.d |
33 | IFCFG=${IFCFG_DIR}/net.${VENET_DEV} |
34 | ROUTESCFG=${IFCFG_DIR}/net.routes |
35 | SCRIPT=/etc/runlevels/default/net.${VENET_DEV} |
36 | HOSTFILE=/etc/hosts |
37 | |
38 | function setup_network() |
39 | { |
40 | cat > ${IFCFG} << EOF |
41 | ONBOOT=yes |
42 | NETWORKING=static |
43 | IP=127.0.0.1 |
44 | NETMASK=255.255.255.255 |
45 | BROADCAST=0.0.0.0 |
46 | EOF |
47 | |
48 | # setup routes |
49 | echo "-net ${FAKEGATEWAY} netmask 255.255.255.255 dev ${VENET_DEV}" > ${ROUTESCFG} |
50 | echo "default gw ${FAKEGATEWAY}" >> ${ROUTESCFG} |
51 | |
52 | # Set up /etc/hosts |
53 | if [ ! -f ${HOSTFILE} ]; then |
54 | echo "127.0.0.1 localhost.localdomain localhost" > $HOSTFILE |
55 | fi |
56 | } |
57 | |
58 | function get_all_aliasid() |
59 | { |
60 | IFNUM=-1 |
61 | IFNUMLIST=$(for i in $(find ${IFCFG_DIR} -name net.${VENET_DEV}:*); do echo $i | sed "s/.*${VENET_DEV}://"; done) |
62 | } |
63 | |
64 | function get_free_aliasid() |
65 | { |
66 | local found= |
67 | |
68 | [ -z "${IFNUMLIST}" ] && get_all_aliasid |
69 | while test -z ${found}; do |
70 | let IFNUM=IFNUM+1 |
71 | echo "${IFNUMLIST}" | grep -q -E "${IFNUM}" 2>/dev/null || found=1 |
72 | done |
73 | } |
74 | |
75 | function create_config() |
76 | { |
77 | local ip=$1 |
78 | local ifnum=$2 |
79 | |
80 | echo -e "# auto-generated configuration for ${VENET_DEV}:${ifnum} |
81 | ONBOOT=yes |
82 | NETWORKING=static |
83 | IP=${ip} |
84 | NETMASK=255.255.255.255 |
85 | BROADCAST=0.0.0.0 |
86 | " > ${IFCFG}:${ifnum} |
87 | } |
88 | |
89 | |
90 | function add_ip() |
91 | { |
92 | local ip |
93 | local new_ips |
94 | |
95 | # In case we are starting VE |
96 | if [ "x${VE_STATE}" = "xstarting" ]; then |
97 | setup_network |
98 | fi |
99 | |
100 | if [ "x${IPDELALL}" = "xyes" ]; then |
101 | rm -f ${IFCFG} |
102 | rm -f ${IFCFG}:[0-9]* |
103 | fi |
104 | |
105 | for ip in ${IP_ADDR}; do |
106 | found= |
107 | if grep -e "\\<${ip}\\>" >/dev/null 2>&1 ${IFCFG}:*; then |
108 | continue |
109 | fi |
110 | get_free_aliasid |
111 | create_config ${ip} ${IFNUM} |
112 | done |
113 | |
114 | if [ "x${VE_STATE}" = "xrunning" ]; then |
115 | # synchronyze config files & interfaces |
116 | /etc/init.d/network restart 2>/dev/null 1>/dev/null |
117 | fi |
118 | } |
119 | |
120 | add_ip |
121 | exit 0 |
122 | # end of script |