Don't use separate cache file for addresses.

This commit is contained in:
Mikhail Efremov 2011-05-06 15:39:00 +04:00
parent 98a23bb27e
commit 8366976493
3 changed files with 20 additions and 35 deletions

View File

@ -17,8 +17,6 @@ alterator_api_version=1
. alterator-hw-functions
. shell-config
mkdir -p $cachedir
###
is_defined()
@ -353,18 +351,6 @@ get_ifacedir()
fi
}
read_iface_address()
{
local name="$1"
local ifacedir="$(get_ifacedir "$name")"
if ! [ -f "$cachedir/$name-ipv4address" ]; then
> "$cachedir/$name-ipv4address"
if [ -s "$ifacedir/ipv4address" ]; then
cat "$ifacedir/ipv4address" > $cachedir/$name-ipv4address
fi
fi
}
read_iface()
{
local name="$1"; shift
@ -383,8 +369,6 @@ read_iface()
write_string_param dns "$(read_iface_dns "$ifacedir")"
write_string_param search "$(read_iface_search "$ifacedir")"
read_iface_address $name
write_string_param default "$(read_iface_default_gw "$ifacedir")"
write_string_param ip_string "$(netdev_read_ip "$name"|head -n1)"
@ -452,8 +436,6 @@ write_iface()
shell_config_del "$ifacedir/options" HOST
fi
write_iface_addresses "$ifacedir" "$(echo $(cat $cachedir/${name}-ipv4address))"
is_defined "in_default" &&
write_iface_default_gw "$ifacedir" "$in_default"
@ -476,8 +458,7 @@ add_iface_address()
local addr="$2"
local mask="$3"
if [ -n "$iface" -a -n "$addr" -a -n "$mask" ] ; then
read_iface_address $iface
echo "$addr/$mask" >> "$cachedir/$iface-ipv4address"
echo "$addr/$mask" >> "$cachedir/$iface/ipv4address"
fi
}
@ -486,18 +467,18 @@ del_iface_address()
local iface="$1"
local addr="$2"
if [ -n "$iface" -a -n "$addr" ] ; then
read_iface_address $iface
sed -i -e "s|^${addr}$||" -e '/^$/d' "$cachedir/$iface-ipv4address"
sed -i -e "s|^${addr}$||" -e '/^$/d' "$cachedir/$iface/ipv4address"
fi
}
list_iface_addresses()
{
local name="$1"; shift
[ -n "$name" ] || name="$(list_eth_cached|head -n1)"
read_iface_address $name
cat "$cachedir/$name-ipv4address" | write_enum
local ifacedir="$(get_ifacedir "$name")"
[ -s "$ifacedir/ipv4address" ] && cat "$ifacedir/ipv4address" | write_enum
}
#initial actions
@ -523,9 +504,13 @@ on_message()
{
case "$in_action" in
add_iface_address)
add_iface_address "$in_real_name" "${in_addip}" "${in_addmask}";;
init_cache "$in_name" "$in_bridge"
add_iface_address "$in_name" "${in_addip}" "${in_addmask}"
;;
del_iface_address)
del_iface_address "$in_real_name" "$in_addresses" ;;
init_cache "$in_name" "$in_bridge"
del_iface_address "$in_name" "$in_addresses"
;;
list)
case "${in__objects##*/}" in
avail_masks) list_mask ;;

View File

@ -99,9 +99,9 @@
(define (ui-append-address)
(if (regexp-exec (make-regexp (string-append "^" "([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])([.]([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9+]|25[0-5])){3}" "$") regexp/extended) (form-value "add-ip"))
(begin
(apply woo "add_iface_address" "/net-eth" (form-value-list '("real_name" "add-ip" "add-mask")))
(apply woo "add_iface_address" "/net-eth" (form-value-list '("name" "add-ip" "add-mask")))
(form-update-visibility "invalid_ip_message" #f)
(read-interface-address (form-value "real_name"))
(read-interface-address (form-value "name"))
(form-update-value "add-ip" "")
)
(form-update-visibility "invalid_ip_message" #t)
@ -111,8 +111,8 @@
(define (ui-delete-address)
(catch/message (lambda()
(apply woo "del_iface_address" "/net-eth"
(form-value-list '("language" "real_name" "addresses")))))
(read-interface-address (form-value "real_name"))
(form-value-list '("language" "name" "addresses")))))
(read-interface-address (form-value "name"))
)
(define (check-addresses-list)

View File

@ -90,8 +90,8 @@
(define (ui-append-address)
(if (regexp-exec (make-regexp (string-append "^" "([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])([.]([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9+]|25[0-5])){3}" "$") regexp/extended) (form-value "add-ip"))
(begin
(apply woo "add_iface_address" "/net-eth" (form-value-list '("real_name" "add-ip" "add-mask")))
(read-interface-address (form-value "real_name"))
(apply woo "add_iface_address" "/net-eth" (form-value-list '("name" "add-ip" "add-mask")))
(read-interface-address (form-value "name"))
(form-update-value "add-ip" "")
)
(document:popup-critical (_ "invalid IP address") 'ok)
@ -109,8 +109,8 @@
(define (ui-delete-address)
(catch/message (lambda()
(apply woo "del_iface_address" "/net-eth"
(form-value-list '("language" "real_name" "addresses")))))
(read-interface-address (form-value "real_name"))
(form-value-list '("language" "name" "addresses")))))
(read-interface-address (form-value "name"))
)
;;; UI