class CoreNode(LxcNode):
    apitype = coreapi.CORE_NODE_DEF
    
    ''' I added the following lines '''
    def bootconf(self):
        return os.path.join(self.confdir, "boot.conf")

    def quaggaconf(self):
        return os.path.join(self.confdir, "Quagga.conf")

    def bootscript(self):
        # read Quagga search paths from core.conf file
        try:
            quagga_bin_search = self.session.cfg['quagga_bin_search']
            quagga_sbin_search = self.session.cfg['quagga_sbin_search']
        except KeyError:
            quagga_bin_search = "/usr/bin"
            quagga_sbin_search = "/usr/sbin"
        bootconf = self.bootconf()
        quaggaconf = self.quaggaconf()
        return """\
#!/bin/sh

QUAGGA_SBIN_SEARCH=%s
QUAGGA_BIN_SEARCH=%s
QUAGGA_STATE_DIR=%s
CONF_DIR=%s

startup()
{
    cmd=$1
    file=$2

    if [ -r "$file" ]; then
        bootcmd=$(awk '
            /bootcmd/ {
                for(i=0;i<=NF;i++)
                    if ($i == "bootcmd")
                        print $(i+1);
                    exit;
                }
            ' $file)

        if [ "$bootcmd" ]; then
            $bootcmd $file
        else
            $cmd $file
        fi
    fi
}

searchforprog()
{
    prog=$1
    searchpath=$@
    ret=
    for p in $searchpath; do
        if [ -x $p/$prog ]; then
            ret=$p
            break
        fi
    done
    echo $ret
}

bootconf()
{
    /bin/sh $1
}

bootquagga()
{
    /sbin/sysctl -w net.ipv4.conf.all.forwarding=1
    /sbin/sysctl -w net.ipv6.conf.all.forwarding=1
    /sbin/sysctl -w net.ipv4.conf.all.send_redirects=0

    QUAGGA_BIN_DIR=$(searchforprog vtysh $QUAGGA_BIN_SEARCH)
    if [ "z$QUAGGA_BIN_DIR" = "z" ]; then
        echo "ERROR: Quagga's 'vtysh' daemon not found in search path:"
        echo "  $QUAGGA_BIN_SEARCH"
        return 1
    fi
    QUAGGA_SBIN_DIR=$(searchforprog zebra $QUAGGA_SBIN_SEARCH)
    if [ "z$QUAGGA_SBIN_DIR" = "z" ]; then
        echo "ERROR: Quagga's 'zebra' daemon not found in search path:"
        echo "  $QUAGGA_SBIN_SEARCH"
        return 1
    fi
    mkdir -p $QUAGGA_STATE_DIR
    $QUAGGA_SBIN_DIR/zebra -d -u root -g root

    # if /etc/quagga exists, point /etc/quagga/Quagga.conf -> CONF_DIR
    if [ "$CONF_DIR" != "/etc/quagga" ] && [ -d /etc/quagga ] && [ ! -e /etc/quagga/Quagga.conf ]; then
        ln -s $CONF_DIR/Quagga.conf /etc/quagga/Quagga.conf
    fi

    vtyfiles="zebra.vty"
    for r in rip ripng ospf6 ospf bgp; do
        if grep -q "^router \<${r}\>" $1; then
            $QUAGGA_SBIN_DIR/${r}d -d -u root -g root
            vtyfiles="$vtyfiles ${r}d.vty"
        fi
    done

    for f in $vtyfiles; do
        count=1
        until [ -e $QUAGGA_STATE_DIR/$f ]; do
            if [ $count -eq 10 ]; then
                echo "ERROR: vty file not found: $QUAGGA_STATE_DIR/$f" >&2
                return 1
            fi
            sleep 0.1
            count=$(($count + 1))
        done
    done

    echo "service integrated-vtysh-config" > $CONF_DIR/vtysh.conf

    $QUAGGA_BIN_DIR/vtysh -b
}

startup bootquagga $CONF_DIR/%s
startup bootconf $CONF_DIR/%s
startup bootconf $CONF_DIR/%s
""" % (quagga_sbin_search, quagga_bin_search, QUAGGA_STATE_DIR,
       self.confdir, "Quagga.conf", "boot.conf", self.name + ".conf")
