Browse code

xenapi - cleanup network configuration

The Xenserver/XCP part of devstack was configuring the hypervisor's
connectivity to the outer world, by adding VLANs, and physical
interfaces to the virtual networks. It added a lot of complexity, and
made it hard to get started with XenServer. This patch removes that
extra complexity, so it is left as an exercise for the user.

Related to blueprint blueprint xenapi-devstack-cleanup

Change-Id: If3367335c3da8621d0afe1f6cae77511fbdbb3e2

Mate Lakat authored on 2013/05/09 00:42:22
Showing 5 changed files
... ...
@@ -8,6 +8,34 @@ The Openstack services are configured to run within a "privileged" virtual
8 8
 machine on the Xenserver host (called OS domU). The VM uses the XAPI toolstack
9 9
 to communicate with the host.
10 10
 
11
+The provided localrc helps to build a basic environment.
12
+The requirements are:
13
+ - An internet-enabled network with a DHCP server on it
14
+ - XenServer box plugged in to the same network
15
+This network will be used as the OpenStack management network. The VM Network
16
+and the Public Network will not be connected to any physical interfaces, only
17
+new virtual networks will be created by the `install_os_domU.sh` script.
18
+
19
+Steps to follow:
20
+ - Install XenServer
21
+ - Download Devstack to XenServer
22
+ - Customise `localrc`
23
+ - Start `install_os_domU.sh` script
24
+
25
+The `install_os_domU.sh` script will:
26
+ - Setup XenAPI plugins
27
+ - Create the named networks, if they don't exist
28
+ - Install an Ubuntu Virtual Machine, with 4 network interfaces:
29
+   - eth0 - internal xapi interface
30
+   - eth1 - VM interface, connected to `VM_BRIDGE_OR_NET_NAME` defaults to
31
+   `"OpenStack VM Network"`.
32
+   - eth2 - Management interface, connected to `MGT_BRIDGE_OR_NET_NAME`,
33
+     defaults to `xenbr0`, XenServer's bridge associated with the Hypervisors
34
+     `eth0`.
35
+   - eth3 - Public interface, connected to `PUB_BRIDGE_OR_NET_NAME` defaults to
36
+   `"OpenStack Public Network"`.
37
+ - Start devstack inside the created OpenStack VM
38
+
11 39
 ## Step 1: Install Xenserver
12 40
 Install XenServer 5.6+ on a clean box. You can get XenServer by signing
13 41
 up for an account on citrix.com, and then visiting:
... ...
@@ -15,13 +43,12 @@ https://www.citrix.com/English/ss/downloads/details.asp?downloadId=2311504&produ
15 15
 
16 16
 For details on installation, see: http://wiki.openstack.org/XenServer/Install
17 17
 
18
-Here are some sample Xenserver network settings for when you are just
19
-getting started (Settings like this have been used with a laptop + cheap wifi router):
20
-
21
-* XenServer Host IP: 192.168.1.10
22
-* XenServer Netmask: 255.255.255.0
23
-* XenServer Gateway: 192.168.1.1
24
-* XenServer DNS: 192.168.1.1
18
+The XenServer IP configuration depends on your local network setup. If you are
19
+using dhcp, make a reservation for XenServer, so its IP address won't change
20
+over time. Make a note of the XenServer's IP address, as it has to be specified
21
+in `localrc`. The other option is to manually specify the IP setup for the
22
+XenServer box. Please make sure, that a gateway and a nameserver is configured,
23
+as `install_os_domU.sh` will connect to github.com to get source-code snapshots.
25 24
 
26 25
 ## Step 2: Download devstack
27 26
 On your XenServer host, run the following commands as root:
... ...
@@ -32,45 +59,63 @@ On your XenServer host, run the following commands as root:
32 32
 
33 33
 ## Step 3: Configure your localrc inside the devstack directory
34 34
 Devstack uses a localrc for user-specific configuration.  Note that
35
-the XENAPI_PASSWORD must be your dom0 root password.
35
+the `XENAPI_PASSWORD` must be your dom0 root password.
36 36
 Of course, use real passwords if this machine is exposed.
37 37
 
38 38
     cat > ./localrc <<EOF
39
+    # Passwords
40
+    # NOTE: these need to be specified, otherwise devstack will try
41
+    # to prompt for these passwords, blocking the install process.
42
+
39 43
     MYSQL_PASSWORD=my_super_secret
40 44
     SERVICE_TOKEN=my_super_secret
41 45
     ADMIN_PASSWORD=my_super_secret
42 46
     SERVICE_PASSWORD=my_super_secret
43 47
     RABBIT_PASSWORD=my_super_secret
44 48
     SWIFT_HASH="66a3d6b56c1f479c8b4e70ab5c2000f5"
45
-    # This is the password for the OpenStack VM (for both stack and root users)
49
+    # This will be the password for the OpenStack VM (both stack and root users)
46 50
     GUEST_PASSWORD=my_super_secret
47 51
 
48 52
     # XenAPI parameters
49
-    # IMPORTANT: The following must be set to your dom0 root password!
53
+    # NOTE: The following must be set to your XenServer root password!
54
+
50 55
     XENAPI_PASSWORD=my_xenserver_root_password
56
+
51 57
     XENAPI_CONNECTION_URL="http://address_of_your_xenserver"
52 58
     VNCSERVER_PROXYCLIENT_ADDRESS=address_of_your_xenserver
53 59
 
54
-    # Do not download the usual images yet!
60
+    # Do not download the usual images
55 61
     IMAGE_URLS=""
56 62
     # Explicitly set virt driver here
57 63
     VIRT_DRIVER=xenserver
58
-    # Explicitly set multi-host
64
+    # Explicitly enable multi-host
59 65
     MULTI_HOST=1
60 66
     # Give extra time for boot
61 67
     ACTIVE_TIMEOUT=45
62
-    # Host Interface, i.e. the interface on the nova vm you want to expose the
63
-    # services on. Usually eth2 (management network) or eth3 (public network) and
64
-    # not eth0 (private network with XenServer host) or eth1 (VM traffic network)
65
-    # The default is eth3.
66
-    # HOST_IP_IFACE=eth3
68
+    # Host Interface, i.e. the interface on the OpenStack vm you want to expose
69
+    # the services on. The default is eth3, which means the public network, but
70
+    # as the public network is going to be virtual, we are setting the services
71
+    # to listen on the management network, which defaults to 'xenbr0', the
72
+    # XenServer's network.
73
+    HOST_IP_IFACE=eth2
74
+
75
+    # Use DHCP server to configure the Management IP of OpenStack VM
76
+    MGT_IP="dhcp"
67 77
 
68 78
     # Settings for netinstalling Ubuntu
69
-    # UBUNTU_INST_RELEASE=precise
79
+    UBUNTU_INST_RELEASE=precise
80
+
81
+    # First time Ubuntu network install params, use the DHCP server on the
82
+    # management network
83
+    UBUNTU_INST_IFACE="eth2"
84
+    UBUNTU_INST_IP="dhcp"
85
+
86
+    # NOTE: the value of FLAT_NETWORK_BRIDGE will automatically be determined
87
+    # by install_os_domU.sh script.
70 88
 
71
-    # First time Ubuntu network install params
72
-    # UBUNTU_INST_IFACE="eth3"
73
-    # UBUNTU_INST_IP="dhcp"
89
+    # Public IP address is aligned with the devstack defaults (see FLOATING_RANGE)
90
+    PUB_IP=172.24.4.10
91
+    PUB_NETMASK=255.255.255.0
74 92
     EOF
75 93
 
76 94
 ## Step 4: Run `./install_os_domU.sh` from the `tools/xen` directory
... ...
@@ -93,3 +93,84 @@ function find_ip_by_name() {
93 93
         fi
94 94
     done
95 95
 }
96
+
97
+function _create_new_network() {
98
+    local name_label
99
+    name_label=$1
100
+
101
+    xe network-create name-label="$name_label"
102
+}
103
+
104
+function _multiple_networks_with_name() {
105
+    local name_label
106
+    name_label=$1
107
+
108
+    # A comma indicates multiple matches
109
+    xe network-list name-label="$name_label" --minimal | grep -q ","
110
+}
111
+
112
+function _network_exists() {
113
+    local name_label
114
+    name_label=$1
115
+
116
+    ! [ -z $(xe network-list name-label="$name_label" --minimal) ]
117
+}
118
+
119
+function _bridge_exists() {
120
+    local bridge
121
+    bridge=$1
122
+
123
+    ! [ -z $(xe network-list bridge="$bridge" --minimal) ]
124
+}
125
+
126
+
127
+function setup_network() {
128
+    local bridge_or_net_name
129
+    bridge_or_net_name=$1
130
+
131
+    if ! _bridge_exists "$bridge_or_net_name"; then
132
+        if _network_exists "$bridge_or_net_name"; then
133
+            if _multiple_networks_with_name "$bridge_or_net_name"; then
134
+                cat >&2 << EOF
135
+ERROR: Multiple networks found matching name-label to "$bridge_or_net_name"
136
+please review your XenServer network configuration / localrc file.
137
+EOF
138
+                exit 1
139
+            fi
140
+        else
141
+            _create_new_network "$bridge_or_net_name"
142
+        fi
143
+    fi
144
+}
145
+
146
+function bridge_for() {
147
+    local bridge_or_net_name
148
+    bridge_or_net_name=$1
149
+
150
+    if _bridge_exists "$bridge_or_net_name"; then
151
+        echo "$bridge_or_net_name"
152
+    else
153
+        xe network-list name-label="$bridge_or_net_name" params=bridge --minimal
154
+    fi
155
+}
156
+
157
+function xenapi_ip_on() {
158
+    local bridge_or_net_name
159
+    bridge_or_net_name=$1
160
+
161
+    ifconfig $(bridge_for "$bridge_or_net_name") | grep "inet addr" | cut -d ":" -f2 | sed "s/ .*//"
162
+}
163
+
164
+function xenapi_is_listening_on() {
165
+    local bridge_or_net_name
166
+    bridge_or_net_name=$1
167
+
168
+    ! [ -z $(xenapi_ip_on "$bridge_or_net_name") ]
169
+}
170
+
171
+function parameter_is_specified() {
172
+    local parameter_name
173
+    parameter_name=$1
174
+
175
+    compgen -v | grep "$parameter_name"
176
+}
... ...
@@ -67,97 +67,28 @@ create_directory_for_kernels
67 67
 #
68 68
 # Configure Networking
69 69
 #
70
-
71
-# Helper to create networks
72
-# Uses echo trickery to return network uuid
73
-function create_network() {
74
-    br=$1
75
-    dev=$2
76
-    vlan=$3
77
-    netname=$4
78
-    if [ -z $br ]
79
-    then
80
-        pif=$(xe_min pif-list device=$dev VLAN=$vlan)
81
-        if [ -z $pif ]
82
-        then
83
-            net=$(xe network-create name-label=$netname)
84
-        else
85
-            net=$(xe_min network-list  PIF-uuids=$pif)
86
-        fi
87
-        echo $net
88
-        return 0
89
-    fi
90
-    if [ ! $(xe_min network-list  params=bridge | grep -w --only-matching $br) ]
91
-    then
92
-        echo "Specified bridge $br does not exist"
93
-        echo "If you wish to use defaults, please keep the bridge name empty"
94
-        exit 1
95
-    else
96
-        net=$(xe_min network-list  bridge=$br)
97
-        echo $net
98
-    fi
99
-}
100
-
101
-function errorcheck() {
102
-    rc=$?
103
-    if [ $rc -ne 0 ]
104
-    then
105
-        exit $rc
106
-    fi
107
-}
108
-
109
-# Create host, vm, mgmt, pub networks on XenServer
110
-VM_NET=$(create_network "$VM_BR" "$VM_DEV" "$VM_VLAN" "vmbr")
111
-errorcheck
112
-MGT_NET=$(create_network "$MGT_BR" "$MGT_DEV" "$MGT_VLAN" "mgtbr")
113
-errorcheck
114
-PUB_NET=$(create_network "$PUB_BR" "$PUB_DEV" "$PUB_VLAN" "pubbr")
115
-errorcheck
116
-
117
-# Helper to create vlans
118
-function create_vlan() {
119
-    dev=$1
120
-    vlan=$2
121
-    net=$3
122
-    # VLAN -1 refers to no VLAN (physical network)
123
-    if [ $vlan -eq -1 ]
124
-    then
125
-        return
126
-    fi
127
-    if [ -z $(xe_min vlan-list  tag=$vlan) ]
128
-    then
129
-        pif=$(xe_min pif-list  network-uuid=$net)
130
-        # We created a brand new network this time
131
-        if [ -z $pif ]
132
-        then
133
-            pif=$(xe_min pif-list  device=$dev VLAN=-1)
134
-            xe vlan-create pif-uuid=$pif vlan=$vlan network-uuid=$net
135
-        else
136
-            echo "VLAN does not exist but PIF attached to this network"
137
-            echo "How did we reach here?"
138
-            exit 1
139
-        fi
140
-    fi
141
-}
142
-
143
-# Create vlans for vm and management
144
-create_vlan $PUB_DEV $PUB_VLAN $PUB_NET
145
-create_vlan $VM_DEV $VM_VLAN $VM_NET
146
-create_vlan $MGT_DEV $MGT_VLAN $MGT_NET
147
-
148
-# Get final bridge names
149
-if [ -z $VM_BR ]; then
150
-    VM_BR=$(xe_min network-list  uuid=$VM_NET params=bridge)
151
-fi
152
-if [ -z $MGT_BR ]; then
153
-    MGT_BR=$(xe_min network-list  uuid=$MGT_NET params=bridge)
70
+setup_network "$VM_BRIDGE_OR_NET_NAME"
71
+setup_network "$MGT_BRIDGE_OR_NET_NAME"
72
+setup_network "$PUB_BRIDGE_OR_NET_NAME"
73
+
74
+if parameter_is_specified "FLAT_NETWORK_BRIDGE"; then
75
+    cat >&2 << EOF
76
+ERROR: FLAT_NETWORK_BRIDGE is specified in localrc file
77
+This is considered as an error, as its value will be derived from the
78
+VM_BRIDGE_OR_NET_NAME variable's value.
79
+EOF
80
+    exit 1
154 81
 fi
155
-if [ -z $PUB_BR ]; then
156
-    PUB_BR=$(xe_min network-list  uuid=$PUB_NET params=bridge)
82
+
83
+if ! xenapi_is_listening_on "$MGT_BRIDGE_OR_NET_NAME"; then
84
+    cat >&2 << EOF
85
+ERROR: XenAPI does not have an assigned IP address on the management network.
86
+please review your XenServer network configuration / localrc file.
87
+EOF
88
+    exit 1
157 89
 fi
158 90
 
159
-# dom0 ip, XenAPI is assumed to be listening
160
-HOST_IP=${HOST_IP:-`ifconfig xenbr0 | grep "inet addr" | cut -d ":" -f2 | sed "s/ .*//"`}
91
+HOST_IP=$(xenapi_ip_on "$MGT_BRIDGE_OR_NET_NAME")
161 92
 
162 93
 # Set up ip forwarding, but skip on xcp-xapi
163 94
 if [ -a /etc/sysconfig/network ]; then
... ...
@@ -263,7 +194,15 @@ if [ -z "$templateuuid" ]; then
263 263
 
264 264
     # create a new VM with the given template
265 265
     # creating the correct VIFs and metadata
266
-    $THIS_DIR/scripts/install-os-vpx.sh -t "$UBUNTU_INST_TEMPLATE_NAME" -v $VM_BR -m $MGT_BR -p $PUB_BR -l $GUEST_NAME -r $OSDOMU_MEM_MB -k "flat_network_bridge=${VM_BR}"
266
+    FLAT_NETWORK_BRIDGE=$(bridge_for "$VM_BRIDGE_OR_NET_NAME")
267
+    $THIS_DIR/scripts/install-os-vpx.sh \
268
+        -t "$UBUNTU_INST_TEMPLATE_NAME" \
269
+        -v "$VM_BRIDGE_OR_NET_NAME" \
270
+        -m "$MGT_BRIDGE_OR_NET_NAME" \
271
+        -p "$PUB_BRIDGE_OR_NET_NAME" \
272
+        -l "$GUEST_NAME" \
273
+        -r "$OSDOMU_MEM_MB" \
274
+        -k "flat_network_bridge=${FLAT_NETWORK_BRIDGE}"
267 275
 
268 276
     # wait for install to finish
269 277
     wait_for_VM_to_halt
... ...
@@ -235,7 +235,7 @@ create_gi_vif()
235 235
 create_vm_vif()
236 236
 {
237 237
   local v="$1"
238
-  echo "Installing management interface on $BRIDGE_V."
238
+  echo "Installing VM interface on $BRIDGE_V."
239 239
   local out_network_uuid=$(find_network "$BRIDGE_V")
240 240
   create_vif "$v" "$out_network_uuid" "1" >/dev/null
241 241
 }
... ...
@@ -16,6 +16,16 @@ VDI_MB=${VDI_MB:-5000}
16 16
 OSDOMU_MEM_MB=1024
17 17
 OSDOMU_VDI_GB=8
18 18
 
19
+# Network mapping. Specify bridge names or network names. Network names may
20
+# differ across localised versions of XenServer. If a given bridge/network
21
+# was not found, a new network will be created with the specified name.
22
+
23
+# The management network is specified by the bridge name. xenbr0 is usually
24
+# the name of the bridge of the network associated with the hypervisor's eth0.
25
+MGT_BRIDGE_OR_NET_NAME="xenbr0"
26
+VM_BRIDGE_OR_NET_NAME="OpenStack VM Network"
27
+PUB_BRIDGE_OR_NET_NAME="OpenStack Public Network"
28
+
19 29
 # VM Password
20 30
 GUEST_PASSWORD=${GUEST_PASSWORD:-secrete}
21 31
 
... ...
@@ -28,28 +38,17 @@ HOST_IP_IFACE=${HOST_IP_IFACE:-eth3}
28 28
 # Our nova host's network info
29 29
 #
30 30
 
31
-# A host-only ip that let's the interface come up, otherwise unused
32
-VM_IP=${VM_IP:-10.255.255.255}
31
+# Management network
33 32
 MGT_IP=${MGT_IP:-172.16.100.55}
34
-PUB_IP=${PUB_IP:-192.168.1.55}
35
-
36
-# Public network
37
-PUB_NETMASK=${PUB_NETMASK:-255.255.255.0}
38
-PUB_BR=${PUB_BR:-"xenbr0"}
39
-PUB_VLAN=${PUB_VLAN:--1}
40
-PUB_DEV=${PUB_DEV:-eth0}
33
+MGT_NETMASK=${MGT_NETMASK:-255.255.255.0}
41 34
 
42
-# VM network params
35
+# VM Network
36
+VM_IP=${VM_IP:-10.255.255.255}
43 37
 VM_NETMASK=${VM_NETMASK:-255.255.255.0}
44
-VM_BR=${VM_BR:-""}
45
-VM_VLAN=${VM_VLAN:-100}
46
-VM_DEV=${VM_DEV:-eth0}
47 38
 
48
-# MGMT network params
49
-MGT_NETMASK=${MGT_NETMASK:-255.255.255.0}
50
-MGT_BR=${MGT_BR:-""}
51
-MGT_VLAN=${MGT_VLAN:-101}
52
-MGT_DEV=${MGT_DEV:-eth0}
39
+# Public network
40
+PUB_IP=${PUB_IP:-192.168.1.55}
41
+PUB_NETMASK=${PUB_NETMASK:-255.255.255.0}
53 42
 
54 43
 # Decide if you should enable eth0,
55 44
 # the guest installer network