lib/pvl/hosts/dhcp.sh
author Tero Marttila <tero.marttila@aalto.fi>
Tue, 03 Mar 2015 12:48:31 +0200
changeset 723 4644a67c329a
parent 719 4ddebf1d754a
permissions -rw-r--r--
lib/pvl/hosts/dhcp: fix test_cmd $DHCP_CONF
632
711be783d0a1 update lib: fixfix
Tero Marttila <tero.marttila@aalto.fi>
parents: 629
diff changeset
     1
DHCP_SBIN=/usr/sbin/dhcpd
711be783d0a1 update lib: fixfix
Tero Marttila <tero.marttila@aalto.fi>
parents: 629
diff changeset
     2
DHCP_CONF=/etc/dhcp/dhcpd.conf
711be783d0a1 update lib: fixfix
Tero Marttila <tero.marttila@aalto.fi>
parents: 629
diff changeset
     3
DHCP_SERVICE=isc-dhcp-server
628
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
     4
662
4750b8b85aa1 lib/pvl: fix pvl/hosts/dhcp.sh srcs and --include-path
Tero Marttila <terom@paivola.fi>
parents: 632
diff changeset
     5
# absolute path!
4750b8b85aa1 lib/pvl: fix pvl/hosts/dhcp.sh srcs and --include-path
Tero Marttila <terom@paivola.fi>
parents: 632
diff changeset
     6
DHCP_INCLUDE="$SRV/var/dhcp"
4750b8b85aa1 lib/pvl: fix pvl/hosts/dhcp.sh srcs and --include-path
Tero Marttila <terom@paivola.fi>
parents: 632
diff changeset
     7
628
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
     8
## Generate DHCP hosts config from hosts hosts using pvl.hosts-dhcp
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
     9
#
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    10
#   update_hosts_dhcpe $out $src
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    11
function update_hosts_dhcp {
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    12
    local out="$1"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    13
    local src="$2"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    14
    local msg="$out: Generating DHCP hosts: $src"
715
76ed62924d50 lib/pvl/hosts: include cache for proper hosts dependencies
Tero Marttila <tero.marttila@aalto.fi>
parents: 701
diff changeset
    15
    local include_cache=$(include_cache_path $src)
76ed62924d50 lib/pvl/hosts: include cache for proper hosts dependencies
Tero Marttila <tero.marttila@aalto.fi>
parents: 701
diff changeset
    16
    local srcs=($(include_cache $include_cache))
628
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    17
715
76ed62924d50 lib/pvl/hosts: include cache for proper hosts dependencies
Tero Marttila <tero.marttila@aalto.fi>
parents: 701
diff changeset
    18
    if apply_check "$out" ${srcs[@]:-}; then
628
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    19
        log_skip "$msg"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    20
    else
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    21
        log_apply "$msg"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    22
    
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    23
        apply_cmd "$out" $OPT/bin/pvl.hosts-dhcp \
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    24
            --hosts-include="$HOSTS_INCLUDE" \
719
4ddebf1d754a lib/pvl/hosts: fix update_hosts_dhcp include_cache
Tero Marttila <tero.marttila@aalto.fi>
parents: 715
diff changeset
    25
            --hosts-include-trace=$include_cache \
628
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    26
             "$src"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    27
    fi
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    28
}
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    29
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    30
## Generate dhcp confs from source using pvl.dhcp-conf:
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    31
function update_dhcp_conf {
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    32
    local out="$1"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    33
    local src="$2"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    34
    local msg="$out: Generating DHCP conf: $src"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    35
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    36
    if apply_check "$out" "$src"; then
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    37
        log_skip "$msg"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    38
    else
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    39
        log_apply "$msg"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    40
            
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    41
        apply_cmd "$out" $OPT/bin/pvl.dhcp-conf \
662
4750b8b85aa1 lib/pvl: fix pvl/hosts/dhcp.sh srcs and --include-path
Tero Marttila <terom@paivola.fi>
parents: 632
diff changeset
    42
            --include-path=$DHCP_INCLUDE \
628
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    43
            "$src"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    44
    fi
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    45
}
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    46
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    47
## Test DHCP configuration for validity using dhcpd -t:
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    48
#
701
8ddc141af313 update pvl/hosts: only test the global dhcp config, since things like sublclasses means that the individual dhcp confs will not pass
Tero Marttila <tero.marttila@aalto.fi>
parents: 664
diff changeset
    49
#   check_dhcp
628
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    50
#
701
8ddc141af313 update pvl/hosts: only test the global dhcp config, since things like sublclasses means that the individual dhcp confs will not pass
Tero Marttila <tero.marttila@aalto.fi>
parents: 664
diff changeset
    51
# Uses the global $DHCPD_CONF, 
628
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    52
function test_dhcp {
632
711be783d0a1 update lib: fixfix
Tero Marttila <tero.marttila@aalto.fi>
parents: 629
diff changeset
    53
    if [ ! -e "$DHCP_SBIN" ]; then
628
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    54
        log_warn "check_dhcp: dhcpd not installed, skipping: $conf"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    55
        return 0
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    56
    fi
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    57
   
701
8ddc141af313 update pvl/hosts: only test the global dhcp config, since things like sublclasses means that the individual dhcp confs will not pass
Tero Marttila <tero.marttila@aalto.fi>
parents: 664
diff changeset
    58
    log_check "Checking DHCP: $DHCP_CONF" 
628
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    59
723
4644a67c329a lib/pvl/hosts/dhcp: fix test_cmd $DHCP_CONF
Tero Marttila <tero.marttila@aalto.fi>
parents: 719
diff changeset
    60
    test_cmd "$DHCP_CONF" \
701
8ddc141af313 update pvl/hosts: only test the global dhcp config, since things like sublclasses means that the individual dhcp confs will not pass
Tero Marttila <tero.marttila@aalto.fi>
parents: 664
diff changeset
    61
        "$DHCP_SBIN" -cf "$DHCP_CONF" -t
628
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    62
}
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    63
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    64
## Reload dhcp hosts
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    65
#
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    66
#   reload_dhcp
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    67
#
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    68
# noop's if we haven't reloaded zones
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    69
function reload_dhcp {
629
7214fe5c6fac lib/pvl: fixfix
Tero Marttila <tero.marttila@aalto.fi>
parents: 628
diff changeset
    70
    if [ "$UPDATE_RELOAD" = 1 ]; then
628
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    71
        log_force "Reload DHCP"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    72
        
629
7214fe5c6fac lib/pvl: fixfix
Tero Marttila <tero.marttila@aalto.fi>
parents: 628
diff changeset
    73
    elif [ "$UPDATE_RELOAD" = 0 ]; then
628
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    74
        log_noop "Skip reload DHCP"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    75
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    76
        return
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    77
 
632
711be783d0a1 update lib: fixfix
Tero Marttila <tero.marttila@aalto.fi>
parents: 629
diff changeset
    78
    elif [ ! -e "$DHCP_SBIN" ]; then
628
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    79
        warn "Skip missing DHCP"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    80
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    81
        return 
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    82
   
632
711be783d0a1 update lib: fixfix
Tero Marttila <tero.marttila@aalto.fi>
parents: 629
diff changeset
    83
    elif ! service_status $DHCP_SERVICE; then
711be783d0a1 update lib: fixfix
Tero Marttila <tero.marttila@aalto.fi>
parents: 629
diff changeset
    84
        log_skip "dhcpd not running; did not restart"
628
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    85
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    86
        return
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    87
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    88
    else
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    89
        log_apply "Reload DHCP"
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    90
    fi
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    91
632
711be783d0a1 update lib: fixfix
Tero Marttila <tero.marttila@aalto.fi>
parents: 629
diff changeset
    92
    service_restart $DHCP_SERVICE
628
b10ad946d01d update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    93
}