Added template for package's test script
[openstack-build/neutron-build.git] / rpm / SOURCES / neutron-l3-setup
1 #!/bin/bash
2 #
3 # Copyright (C) 2012, Red Hat, Inc.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License"); you may
6 # not use this file except in compliance with the License. You may obtain
7 # a copy of the License at
8 #
9 #      http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 # License for the specific language governing permissions and limitations
15 # under the License.
16 #
17
18 # The script supports the plugins below
19 declare -a SUPPORTED_PLUGINS=(linuxbridge openvswitch)
20
21 #
22 # Print --help output and exit.
23 #
24 usage() {
25
26 cat << EOF
27 The helper script will install the necessary support for the L3 agent.
28
29 Usage: neutron-l3-setup [options]
30 Options:
31         --help        | -h
32                 Print usage information.
33         --plugin      | -p
34                 The neutron plugin. Supported plugins:-
35                     ${SUPPORTED_PLUGINS[*]}
36         --qhost       | -q
37                 The Neutron hostname (assumes that this is also the QPID host).
38 EOF
39
40         exit 0
41 }
42
43 is_valid_plugin() {
44         local i=
45         for i in "${SUPPORTED_PLUGINS[@]}"; do
46                 if [ "$i" == "$1" ]; then
47                         return 0 
48                 fi
49         done
50         return 1
51 }
52
53 L3_CONF=/etc/neutron/l3_agent.ini
54 L3_META_CONF=/etc/neutron/metadata_agent.ini
55
56 while [ $# -gt 0 ]
57 do
58         case "$1" in
59                 -h|--help)
60                         usage
61                         ;;
62                 -p|--plugin)
63                         shift
64                         NEUTRON_PLUGIN=${1}
65                         ;;
66                 -q|--qhost)
67                         shift
68                         Q_HOST=${1}
69                         ;;
70                 *)
71                         # ignore
72                         shift
73                         ;;
74         esac
75         shift
76 done
77
78 # if the plugin is not defined
79 if [ -z ${NEUTRON_PLUGIN} ] ; then
80         echo "Please select a plugin from: ${SUPPORTED_PLUGINS[*]}"
81         echo "Choice:"
82         read NEUTRON_PLUGIN
83 fi
84
85 # check that the plugin is valid
86 is_valid_plugin ${NEUTRON_PLUGIN}
87 if [ $? -ne 0 ]; then
88         echo "Plugin '${NEUTRON_PLUGIN}' not supported. Supported plugins:-"
89         echo "    ${SUPPORTED_PLUGINS[*]}"
90         exit 0
91 fi
92
93 echo "Neutron plugin: ${NEUTRON_PLUGIN}"
94
95 if [ -z ${Q_HOST} ] ; then
96     echo "Please enter the Neutron hostname:"
97     read Q_HOST
98 fi
99
100 Q_PORT=9696
101 Q_CONF=/etc/neutron/neutron.conf
102 # QPID
103 openstack-config --set ${Q_CONF} DEFAULT rpc_backend neutron.openstack.common.rpc.impl_qpid
104 openstack-config --set ${Q_CONF} DEFAULT qpid_hostname ${Q_HOST}
105
106 case "${NEUTRON_PLUGIN}" in
107 "linuxbridge")
108         LINUX_INTERFACE_DRIVER=neutron.agent.linux.interface.BridgeInterfaceDriver
109         openstack-config --set ${L3_CONF} DEFAULT external_network_bridge ''
110 ;;
111
112 "openvswitch")
113         if ! rpm -q openvswitch > /dev/null
114         then
115                 echo "Please install openvswitch"
116                 exit 0
117         fi
118         LINUX_INTERFACE_DRIVER=neutron.agent.linux.interface.OVSInterfaceDriver
119 ;;
120
121 esac
122
123 # Keystone specific
124 OS_USERNAME=${OS_USERNAME:-neutron}
125 OS_PASSWORD=${OS_PASSWORD:-servicepass}
126 OS_AUTH_URL=${OS_AUTH_URL:-http://localhost:35357/v2.0/}
127 OS_TENANT_NAME=${OS_TENANT_NAME:-service}
128
129 # Update Keystone
130 openstack-config --set ${L3_META_CONF} DEFAULT auth_url ${OS_AUTH_URL}
131 openstack-config --set ${L3_META_CONF} DEFAULT admin_user ${OS_USERNAME}
132 openstack-config --set ${L3_META_CONF} DEFAULT admin_password ${OS_PASSWORD}
133 openstack-config --set ${L3_META_CONF} DEFAULT admin_tenant_name ${OS_TENANT_NAME}
134
135 # Update interface driver
136 openstack-config --set ${L3_CONF} DEFAULT interface_driver ${LINUX_INTERFACE_DRIVER}
137
138 echo "Configuration updates complete!"