[packages/vzctl: 1/2] - changed scripts for adding ips to proper add ipv6 ips
brushek
brushek at pld-linux.org
Sat Nov 3 00:45:23 CET 2012
commit 462cd34cc52ce195186020dcd126db26beb6747c
Author: Łukasz Chrustek <lukasz at chrustek.net>
Date: Sat Nov 3 00:43:16 2012 +0100
- changed scripts for adding ips to proper add ipv6 ips
- cleanup in patch
- rel up to 2
pld-add_ip.sh | 233 ++++++++++++--------------------------------------------
pld-del_ip.sh | 58 +++++---------
vzctl-pld.patch | 3 -
vzctl.spec | 2 +-
4 files changed, 68 insertions(+), 228 deletions(-)
---
diff --git a/vzctl.spec b/vzctl.spec
index 7767a53..4e607c7 100644
--- a/vzctl.spec
+++ b/vzctl.spec
@@ -2,7 +2,7 @@ Summary: OpenVZ containers control utility
Summary(pl.UTF-8): Narzędzie do zarządzania środowiskiem wirtualnym OpenVZ
Name: vzctl
Version: 4.0
-Release: 1
+Release: 2
License: GPL v2+
Group: Applications/System
Source0: http://download.openvz.org/utils/vzctl/%{version}/src/%{name}-%{version}.tar.bz2
diff --git a/pld-add_ip.sh b/pld-add_ip.sh
old mode 100644
new mode 100755
index fc2c1a5..5525f69
--- a/pld-add_ip.sh
+++ b/pld-add_ip.sh
@@ -1,5 +1,5 @@
#!/bin/bash
-# Copyright (C) 2000-2007 SWsoft. All rights reserved.
+# Copyright (C) 2000-2008, Parallels, Inc. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -16,225 +16,88 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#
-# This script configure IP alias(es) inside RedHat like VE.
-#
-# Parameters are passed in environment variables.
-# Required parameters:
-# IP_ADDR - IP address(es) to add
-# (several addresses should be divided by space)
-# Optional parameters:
-# VE_STATE - state of VE; could be one of:
-# starting | stopping | running | stopped
-# IPDELALL - delete all old interfaces
-#
+# Adds IP address(es) in a container running SuSE.
+set -x
VENET_DEV=venet0
-VENET_DEV_CFG=ifcfg-$VENET_DEV
-
-
-IFCFG_DIR=/etc/sysconfig/interfaces
+IFCFG_DIR=/etc/sysconfig/interfaces/
IFCFG=${IFCFG_DIR}/ifcfg-${VENET_DEV}
-NETFILE=/etc/sysconfig/network
+#ROUTES=${IFCFG_DIR}/ifroute-${VENET_DEV}
HOSTFILE=/etc/hosts
-ROUTE=/etc/sysconfig/network
-NETWORKRESTART=
-function fix_ifup
+function get_aliases()
{
- file="/sbin/ifup"
+ IFNUMLIST=
- [ -f "${file}" ] || return 0
- [ "x${VE_STATE}" != "xstarting" ] && return 0
-
- if grep -q 'if \[ "\${DEVICE}" = "lo" \]; then' ${file} 2>/dev/null
- then
- ${CP} ${file} ${file}.$$ || return 1
- /bin/sed -e 's/if \[ "\${DEVICE}" = "lo" \]; then/if \[ "${IPADDR}" = "127.0.0.1" \]; then/g' < ${file} > ${file}.$$ &&
- mv -f ${file}.$$ ${file}
- rm -f ${file}.$$ 2>/dev/null
- fi
+ [ -f ${IFCFG} ] || return
+ IFNUMLIST=`grep -e "^IPADDR" ${IFCFG} | sed 's/^IPADDR\(.*\)=.*/\1/'`
}
-function setup_network
+function init_config()
{
- # Set up venet0 main interface as 127.0.0.1
+
mkdir -p ${IFCFG_DIR}
- echo "DEVICE=${VENET_DEV}
-BOOTPROTO=static
+ echo "DEVICE=venet0
ONBOOT=yes
-IPADDR=127.0.0.1
+BOOTPROTO=static
+BROADCAST=0.0.0.0
NETMASK=255.255.255.255
-BROADCAST=0.0.0.0" > $IFCFG || error "Can't write to file $IFCFG" $VZ_FS_NO_DISK_SPACE
-
-
- remove_fake_old_route ${ROUTE}
-# if ! grep -q "${FAKEGATEWAYNET}/24 dev ${VENET_DEV}" ${ROUTE} 2>/dev/null; then
-# echo "${FAKEGATEWAYNET}/24 dev ${VENET_DEV} scope host
-#default via ${FAKEGATEWAY}" >> ${ROUTE} || error "Can't create ${ROUTE}" ${VZ_FS_NO_DISK_SPACE}
-# fi
- # Set /etc/sysconfig/network
- put_param $NETFILE NETWORKING yes
- put_param $NETFILE GATEWAY ${FAKEGATEWAY}
-
- # setup ipv6
- setup6_network
+IPADDR=127.0.0.1" > ${IFCFG} ||
+ error "Can't write to file ${IFCFG}" ${VZ_FS_NO_DISK_SPACE}
# Set up /etc/hosts
if [ ! -f ${HOSTFILE} ]; then
echo "127.0.0.1 localhost.localdomain localhost" > $HOSTFILE
fi
- fix_ifup
-}
-
-function setup6_network
-{
- [ "${IPV6}" != "yes" ] && return 0
-
- if ! grep -q 'IPV6INIT="yes"' ${IFCFG}; then
- put_param ${IFCFG} IPV6INIT yes
- fi
- if ! grep -q 'NETWORKING_IPV6="yes"' ${NETFILE}; then
- put_param ${NETFILE} NETWORKING_IPV6 yes
- put_param ${NETFILE} IPV6_DEFAULTDEV ${VENET_DEV}
- NETWORKRESTART=yes
- fi
-}
-
-function create_config
+function create_config()
{
local ip=$1
local ifnum=$2
- echo "DEVICE=${VENET_DEV}:${ifnum}
-BOOTPROTO=static
-ONBOOT=yes
-IPADDR=${ip}
-NETMASK=255.255.255.255" > ${IFCFG_DIR}/bak/${VENET_DEV_CFG}:${ifnum} ||
- error "Unable to create interface config file" ${VZ_FS_NO_DISK_SPACE}
-}
-
-function add_ip6
-{
- [ "${IPV6}" != "yes" ] && return
- if ! grep -qw "$1" ${IFCFG} 2>/dev/null; then
- setup6_network
- add_param ${IFCFG} IPV6ADDR_SECONDARIES "$1/128"
- ifconfig ${VENET_DEV} add "$1/128"
- fi
-}
-
-function get_all_aliasid
-{
- IFNUM=-1
-
- cd ${IFCFG_DIR} || return 1
- IFNUMLIST=`ls -1 bak/${VENET_DEV_CFG}:* 2>/dev/null |
- sed "s/.*${VENET_DEV_CFG}://"`
-}
-
-function get_aliasid_by_ip
-{
- local ip=$1
- local idlist
-
- cd ${IFCFG_DIR} || return 1
- IFNUM=`grep -l "IPADDR=${ip}$" ${VENET_DEV_CFG}:* | head -n 1 |
- sed -e 's/.*:\([0-9]*\)$/\1/'`
+#LABEL_${ifnum}=${ifnum}" >> ${IFCFG} ||
+ echo "IPADDR${ifnum}=${ip}" >> ${IFCFG} || error "Can't write to file ${IFCFG}" ${VZ_FS_NO_DISK_SPACE}
}
-function get_free_aliasid
+function add_ip()
{
- local found=
-
- [ -z "${IFNUMLIST}" ] && get_all_aliasid
- while test -z ${found}; do
- let IFNUM=IFNUM+1
- echo "${IFNUMLIST}" | grep -q -E "^${IFNUM}$" 2>/dev/null ||
- found=1
- done
-}
-
-function backup_configs
-{
- local delall=$1
-
- rm -rf ${IFCFG_DIR}/bak/ >/dev/null 2>&1
- mkdir -p ${IFCFG_DIR}/bak
- [ -n "${delall}" ] && return 0
-
- cd ${IFCFG_DIR} || return 1
- if ls ${VENET_DEV_CFG}:* > /dev/null 2>&1; then
- ${CP} ${VENET_DEV_CFG}:* ${IFCFG_DIR}/bak/ ||
- error "Unable to backup intrface config files" ${VZ_FS_NO_DISK_SPACE}
- fi
-}
+ local ipm
+ local ifnum=0
+ local found
-function move_configs
-{
- cd ${IFCFG_DIR} || return 1
- rm -rf ${VENET_DEV_CFG}:*
- mv -f bak/* ${IFCFG_DIR}/ >/dev/null 2>&1
- rm -rf ${IFCFG_DIR}/bak
-}
-
-function add_ip
-{
- local ip
- local new_ips
- local if_restart=
-
- # In case we are starting VE
if [ "x${VE_STATE}" = "xstarting" ]; then
- # Remove all VENET config files
- rm -f ${IFCFG} ${IFCFG}:* >/dev/null 2>&1
- fi
- if [ ! -f "${IFCFG}" ]; then
- setup_network
- if_restart=1
+ if [ -n "${IP_ADDR}" ]; then
+ init_config
+ elif grep -q "^IPADDR" ${IFCFG}; then
+ init_config
+ fi
+ elif [ "x${IPDELALL}" = "xyes" ]; then
+ init_config
+ elif [ ! -f "${IFCFG}" ]; then
+ init_config
fi
- backup_configs ${IPDELALL}
- new_ips="${IP_ADDR}"
- if [ "x${IPDELALL}" = "xyes" ]; then
- new_ips=
- for ip in ${IP_ADDR}; do
- get_aliasid_by_ip "${ip}"
- if [ -n "${IFNUM}" ]; then
- # ip already exists just create it in bak
- create_config "${ip}" "${IFNUM}"
- else
- new_ips="${new_ips} ${ip}"
+
+ get_aliases
+ for ipm in ${IP_ADDR}; do
+ ip_conv $ipm
+ found=
+ if grep -q -w "${_IP}" ${IFCFG}; then
+ continue
+ fi
+ while test -z ${found}; do
+ let ifnum++
+ if ! echo "${IFNUMLIST}" | grep -w -q "${ifnum}"; then
+ found=1
fi
done
- fi
- for ip in ${new_ips}; do
- if [ "${ip#*:}" = "${ip}" ]; then
- get_free_aliasid
- create_config "${ip}" "${IFNUM}"
- else
- if [ "x${IPDELALL}" = "xyes" ]; then
- del_param ${IFCFG} IPV6ADDR_SECONDARIES ""
- fi
- add_ip6 "${ip}"
- fi
+ create_config ${_IP} ${ifnum}
done
- move_configs
if [ "x${VE_STATE}" = "xrunning" ]; then
- # synchronyze config files & interfaces
- if [ "${NETWORKRESTART}" = "yes" ]; then
- /etc/init.d/network restart
- echo "Tutaj 2"
- elif [ -n "${if_restart}" ]; then
- ifup ${VENET_DEV}:${IFNUM}
- echo "Tutaj 3: ${VENET_DEV}:${IFNUM}";
- else
- cd /etc/sysconfig/network-scripts &&
- ./ifup-aliases ${VENET_DEV}
- ifup ${VENET_DEV}:${IFNUM}
- echo "Tutaj 4: ${VENET_DEV}:${IFNUM}";
- fi
+ ifdown $VENET_DEV >/dev/null 2>&1
+ ifup $VENET_DEV >/dev/null 2>&1
fi
}
add_ip
+
exit 0
# end of script
diff --git a/pld-del_ip.sh b/pld-del_ip.sh
old mode 100644
new mode 100755
index 67e1252..4cdf94b
--- a/pld-del_ip.sh
+++ b/pld-del_ip.sh
@@ -1,5 +1,5 @@
#!/bin/bash
-# Copyright (C) 2000-2007 SWsoft. All rights reserved.
+# Copyright (C) 2000-2008, Parallels, Inc. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -16,54 +16,34 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#
-# This script deletes IP alias(es) inside VE for RedHat like systems.
-#
-# Parameters are passed in environment variables.
-# Required parameters:
-# IP_ADDR - IPs to delete, several addresses should be divided by space
-# Optional parameters:
-# IPDELALL - delete all ip addresses
+# Deletes IP address(es) from a container running SuSE.
+
VENET_DEV=venet0
-VENET_DEV_CFG=ifcfg-${VENET_DEV}
IFCFG_DIR=/etc/sysconfig/interfaces/
-IFCFG=${IFCFG_DIR}${VENET_DEV_CFG}
-
-# Function to delete IP address for PLD like systems
-function del_ip
+IFCFG="${IFCFG_DIR}/ifcfg-${VENET_DEV}"
+set -x
+function del_ip()
{
- local ip
- local filetodel
- local file
- local aliasid
+ local ipm ids id
- [ -d ${IFCFG_DIR} ] || return 0
- cd ${IFCFG_DIR} || return 0
if [ "x${IPDELALL}" = "xyes" ]; then
- ifdown ${VENET_DEV} >/dev/null 2>&1
- rm -f ${VENET_DEV_CFG} ${VENET_DEV_CFG}:* 2>/dev/null
- del_param ${IFCFG} IPV6ADDR_SECONDARIES ""
- return 0;
+ ifdown ${VENET_DEV} 2>/dev/null
+ rm -f ${IFCFG} 2>/dev/null
+ return
fi
- for ip in ${IP_ADDR}; do
- # IPV6 processing
- if [ "${ip#*:}" != "${ip}" ]; then
- del_param ${IFCFG} IPV6ADDR_SECONDARIES "${ip}\\/128"
- ifconfig ${VENET_DEV} del ${ip}/128
- continue
- fi
- # find and delete a file with this alias
- filetodel=`grep -l "IPADDR=${ip}$" \
- ${VENET_DEV_CFG}:* 2>/dev/null`
- for file in ${filetodel}; do
- rm -f "${file}"
- aliasid=`echo ${file} | sed s/.*://g`
- if [ -n "${aliasid}" ]; then
- ifconfig ${VENET_DEV}:${aliasid} down >/dev/null 2>&1
- fi
+ for ipm in ${IP_ADDR}; do
+ ip_conv $ipm
+ ids=`grep -E "^IPADDR.*=${_IP}$" ${IFCFG} 2>/dev/null |
+ sed 's/^IPADDR\(.*\)=.*/\1/'`
+ for id in ${ids}; do
+ sed -e "/^IPADDR${id}=/ d " < ${IFCFG} > ${IFCFG}.bak && mv -f ${IFCFG}.bak ${IFCFG}
+ #ifconfig ${VENET_DEV}:${id} down 2>/dev/null
+ ip addr del ${IP_ADDR} dev ${VENET_DEV} 2>/dev/null
done
done
}
del_ip
+
exit 0
# end of script
diff --git a/vzctl-pld.patch b/vzctl-pld.patch
index 21c17d8..d60958c 100644
--- a/vzctl-pld.patch
+++ b/vzctl-pld.patch
@@ -29,7 +29,6 @@ diff -ru vzctl-4.0/bin/Makefile.am vzctl-4.0-patched/bin/Makefile.am
install-suse:
-Tylko w vzctl-4.0-patched/bin: Makefile.am.orig
diff -ru vzctl-4.0/etc/dists/Makefile.am vzctl-4.0-patched/etc/dists/Makefile.am
--- vzctl-4.0/etc/dists/Makefile.am 2012-09-25 16:53:23.000000000 +0200
+++ vzctl-4.0-patched/etc/dists/Makefile.am 2012-10-27 17:30:19.150478764 +0200
@@ -51,7 +50,6 @@ diff -ru vzctl-4.0/etc/dists/Makefile.am vzctl-4.0-patched/etc/dists/Makefile.am
gentoo \
mandrake \
owl \
-Tylko w vzctl-4.0-patched/etc/dists: Makefile.am.orig
diff -ru vzctl-4.0/etc/init.d/initd-functions.in vzctl-4.0-patched/etc/init.d/initd-functions.in
--- vzctl-4.0/etc/init.d/initd-functions.in 2012-09-25 16:53:23.000000000 +0200
+++ vzctl-4.0-patched/etc/init.d/initd-functions.in 2012-10-27 17:30:19.151478423 +0200
@@ -153,7 +151,6 @@ diff -ru vzctl-4.0/etc/init.d/initd-functions.in vzctl-4.0-patched/etc/init.d/in
status $p
;;
debian)
-Tylko w vzctl-4.0-patched/etc/init.d: initd-functions.in.orig
diff -ru vzctl-4.0/etc/init.d/Makefile.am vzctl-4.0-patched/etc/init.d/Makefile.am
--- vzctl-4.0/etc/init.d/Makefile.am 2012-09-25 16:53:23.000000000 +0200
+++ vzctl-4.0-patched/etc/init.d/Makefile.am 2012-10-27 17:32:07.083190799 +0200
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/packages/vzctl.git/commitdiff/20ad9d431d2e004a75d0b621e0f22ef12243a970
More information about the pld-cvs-commit
mailing list