Added template for package's test script
[openstack-build/neutron-build.git] / rpm / SOURCES / neutron-node-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 selected plugin.
28
29 Usage: neutron-node-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 NEUTRON_USER=neutron
54 LB_CONF=/etc/neutron/plugins/linuxbridge/linuxbridge_conf.ini
55 OVS_CONF=/etc/neutron/plugins/openvswitch/ovs_neutron_plugin.ini
56
57 # Nova specific
58 NOVA_CONF=/etc/nova/nova.conf
59
60 while [ $# -gt 0 ]
61 do
62         case "$1" in
63                 -h|--help)
64                         usage
65                         ;;
66                 -p|--plugin)
67                         shift
68                         NEUTRON_PLUGIN=${1}
69                         ;;
70                 -q|--qhost)
71                         shift
72                         Q_HOST=${1}
73                         ;;
74                 *)
75                         # ignore
76                         shift
77                         ;;
78         esac
79         shift
80 done
81
82 # if the plugin is not defined
83 if [ -z ${NEUTRON_PLUGIN} ] ; then
84         echo "Please select a plugin from: ${SUPPORTED_PLUGINS[*]}"
85         echo "Choice:"
86         read NEUTRON_PLUGIN
87 fi
88
89 # check that the plugin is valid
90 is_valid_plugin ${NEUTRON_PLUGIN}
91 if [ $? -ne 0 ]; then
92         echo "Plugin '${NEUTRON_PLUGIN}' not supported. Supported plugins:-"
93         echo "    ${SUPPORTED_PLUGINS[*]}"
94         exit 0
95 fi
96
97 echo "Neutron plugin: ${NEUTRON_PLUGIN}"
98
99 if ! [ -e "/etc/neutron/plugins/${NEUTRON_PLUGIN}" ]; then
100         echo "Please install the ${NEUTRON_PLUGIN} neutron plugin"
101         exit 0
102 fi
103
104 #if the database hostname and is not defined and is required
105 if [ -z ${Q_HOST} ] ; then
106     echo "Please enter the Neutron hostname:"
107     read Q_HOST
108 fi
109
110 Q_PORT=9696
111 Q_CONF=/etc/neutron/neutron.conf
112 # QPID
113 openstack-config --set ${Q_CONF} DEFAULT rpc_backend neutron.openstack.common.rpc.impl_qpid
114 openstack-config --set ${Q_CONF} DEFAULT qpid_hostname ${Q_HOST}
115
116 case "${NEUTRON_PLUGIN}" in
117 "linuxbridge")
118 ;;
119
120 "openvswitch")
121         if ! rpm -q openvswitch > /dev/null
122         then
123                 echo "Please install openvswitch"
124                 exit 0
125         fi
126         OVS_CONF=/etc/neutron/plugins/openvswitch/ovs_neutron_plugin.ini
127         openstack-config --set ${OVS_CONF} SECURITYGROUP firewall_driver neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver
128 ;;
129
130 esac
131
132 echo "Would you like to update the nova configuration files? (y/n): "
133 read response
134 case "$response" in
135 y|Y)
136         ;;
137 *)
138         echo "Complete!"
139         exit 0
140 esac
141
142 # Keystone specific
143 OS_USERNAME=${OS_USERNAME:-neutron}
144 OS_PASSWORD=${OS_PASSWORD:-servicepass}
145 OS_AUTH_URL=${OS_AUTH_URL:-http://127.0.0.1:35357/v2.0/}
146 OS_TENANT_NAME=${OS_TENANT_NAME:-service}
147
148 # If OpenStack is installed then configure nova.conf
149 if ! [ -e "${NOVA_CONF}" ]; then
150         echo "Please install OpenStack compute and then set the values"
151         echo "in /etc/nova/nova.conf DEFAULT section"
152         echo "    network_api_class=nova.network.neutronv2.api.API"
153         echo "    neutron_admin_username=${OS_USERNAME}"
154         echo "    neutron_admin_password=${OS_PASSWORD}"
155         echo "    neutron_admin_auth_url=${OS_AUTH_URL}"
156         echo "    neutron_auth_strategy=keystone"
157         echo "    neutron_admin_tenant_name=${OS_TENANT_NAME}"
158         echo "    neutron_url=http://${Q_HOST}:${Q_PORT}/"
159         echo "    firewall_driver=nova.virt.firewall.NoopFirewallDriver"
160         echo "    security_group_api=neutron"
161 else
162         openstack-config --set ${NOVA_CONF} DEFAULT network_api_class nova.network.neutronv2.api.API
163         openstack-config --set ${NOVA_CONF} DEFAULT neutron_admin_username ${OS_USERNAME}
164         openstack-config --set ${NOVA_CONF} DEFAULT neutron_admin_password ${OS_PASSWORD}
165         openstack-config --set ${NOVA_CONF} DEFAULT neutron_admin_auth_url ${OS_AUTH_URL}
166         openstack-config --set ${NOVA_CONF} DEFAULT neutron_auth_strategy keystone 
167         openstack-config --set ${NOVA_CONF} DEFAULT neutron_admin_tenant_name ${OS_TENANT_NAME}
168         openstack-config --set ${NOVA_CONF} DEFAULT neutron_url http://${Q_HOST}:${Q_PORT}/
169         openstack-config --set ${NOVA_CONF} DEFAULT firewall_driver nova.virt.firewall.NoopFirewallDriver
170         openstack-config --set ${NOVA_CONF} DEFAULT security_group_api neutron
171 fi
172
173 echo "Configuration updates complete!"