net-interfaces 2.17 KB
Newer Older
glucas's avatar
glucas committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash

# Copyright (C) 2009 Google Inc.
# Copyright (C) 2015-2016 Alsace Réseau Neutre
#
# 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
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.


#
# Create a valid /etc/network/interfaces file for the ARN network.
#


# exit on error so ganeti is aware and outputs the message to the user
set -e

# Include ARN variables
. /etc/ganeti/common-arn-vars

VMNETCONF=$CONFDIR/$INSTANCE_NAME/net.conf


if [ ! -d "$TARGET" ]; then
    echo "Missing target directory"
    exit 1
fi

if [ ! -d "$TARGET/etc/network" ]; then
    echo "Missing target network directory"
    exit 1
fi

if [ -z "$NIC_COUNT" ]; then
    echo "Missing NIC COUNT"
    exit 1
fi

if [ ! -r "$VMNETCONF" ]; then
    echo "Missing VM's network configuration: $CONFDIR/$INSTANCE_NAME/net.conf"
    exit 1
fi


cat > $TARGET/etc/network/interfaces <<EOF
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

auto lo
iface lo inet loopback

EOF


if [ "$NIC_COUNT" -gt 0 ]; then

    . $VMNETCONF

    if [ -n "${IPV4_NET% *}" ]; then
        cat >> $TARGET/etc/network/interfaces <<EOF
auto eth0
iface eth0 inet static
  pre-up  /sbin/ip link set \$IFACE up
  pre-up  /sbin/ip route add 169.254.42.1 dev \$IFACE
  address ${IPV4_NET% *}
  gateway 169.254.42.1

EOF
    fi

    if [ -n "${IPV6_NET% *}" ]; then
        cat >> $TARGET/etc/network/interfaces <<EOF
auto eth0
iface eth0 inet6 static
  address ${IPV6_NET% *}
  gateway fe80::42:1
  accept_ra 0
  autoconf 0
  dad-attempts 0

EOF
    fi

fi

exit 0