Added template for package's test script
[openstack-build/neutron-build.git] / rpm / SOURCES / neutron-dhcp-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 DHCP agent.
28
29 Usage: neutron-dhcp-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 DHCP_CONF=/etc/neutron/dhcp_agent.ini
54
55 while [ $# -gt 0 ]
56 do
57         case "$1" in
58                 -h|--help)
59                         usage
60                         ;;
61                 -p|--plugin)
62                         shift
63                         NEUTRON_PLUGIN=${1}
64                         ;;
65                 -q|--qhost)
66                         shift
67                         Q_HOST=${1}
68                         ;;
69                 *)
70                         # ignore
71                         shift
72                         ;;
73         esac
74         shift
75 done
76
77 # if the plugin is not defined
78 if [ -z ${NEUTRON_PLUGIN} ] ; then
79         echo "Please select a plugin from: ${SUPPORTED_PLUGINS[*]}"
80         echo "Choice:"
81         read NEUTRON_PLUGIN
82 fi
83
84 # check that the plugin is valid
85 is_valid_plugin ${NEUTRON_PLUGIN}
86 if [ $? -ne 0 ]; then
87         echo "Plugin '${NEUTRON_PLUGIN}' not supported. Supported plugins:-"
88         echo "    ${SUPPORTED_PLUGINS[*]}"
89         exit 0
90 fi
91
92 echo "Neutron plugin: ${NEUTRON_PLUGIN}"
93
94 if [ -z ${Q_HOST} ] ; then
95     echo "Please enter the Neutron hostname:"
96     read Q_HOST
97 fi
98
99 Q_PORT=9696
100 Q_CONF=/etc/neutron/neutron.conf
101 # QPID
102 openstack-config --set ${Q_CONF} DEFAULT rpc_backend neutron.openstack.common.rpc.impl_qpid
103 openstack-config --set ${Q_CONF} DEFAULT qpid_hostname ${Q_HOST}
104
105 case "${NEUTRON_PLUGIN}" in
106 "linuxbridge")
107         LINUX_INTERFACE_DRIVER=neutron.agent.linux.interface.BridgeInterfaceDriver
108 ;;
109
110 "openvswitch")
111         if ! rpm -q openvswitch > /dev/null
112         then
113                 echo "Please install openvswitch"
114                 exit 0
115         fi
116         LINUX_INTERFACE_DRIVER=neutron.agent.linux.interface.OVSInterfaceDriver
117 ;;
118
119 esac
120
121 # Keystone specific
122 OS_USERNAME=${OS_USERNAME:-neutron}
123 OS_PASSWORD=${OS_PASSWORD:-servicepass}
124 OS_AUTH_URL=${OS_AUTH_URL:-http://localhost:35357/v2.0/}
125 OS_TENANT_NAME=${OS_TENANT_NAME:-service}
126
127 # Update Keystone
128 openstack-config --set ${DHCP_CONF} DEFAULT auth_url ${OS_AUTH_URL}
129 openstack-config --set ${DHCP_CONF} DEFAULT admin_username ${OS_USERNAME}
130 openstack-config --set ${DHCP_CONF} DEFAULT admin_password ${OS_PASSWORD}
131 openstack-config --set ${DHCP_CONF} DEFAULT admin_tenant_name ${OS_TENANT_NAME}
132
133 # Update interface driver
134 openstack-config --set ${DHCP_CONF} DEFAULT interface_driver ${LINUX_INTERFACE_DRIVER}
135
136 echo "Configuration updates complete!"