Cisco Vendor Code for Neutron
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cisco_neutron 9.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. #!/usr/bin/env bash
  2. #
  3. # lib/neutron
  4. # functions - functions specific to neutron
  5. # Dependencies:
  6. # ``functions`` file
  7. # ``DEST`` must be defined
  8. # ``STACK_USER`` must be defined
  9. # ``stack.sh`` calls the entry points in this order:
  10. #
  11. # - net_configure_neutron
  12. # - net_start_neutron_agents
  13. # - net_create_neutron_initial_network
  14. #
  15. # ``unstack.sh`` calls the entry points in this order:
  16. #
  17. # - net_stop_neutron
  18. # Neutron Networking
  19. # ------------------
  20. # Make sure that neutron is enabled in ``ENABLED_SERVICES``. If you want
  21. # to run Neutron on this host, make sure that q-svc is also in
  22. # ``ENABLED_SERVICES``.
  23. #
  24. # See "Neutron Network Configuration" below for additional variables
  25. # that must be set in localrc for connectivity across hosts with
  26. # Neutron.
  27. #
  28. # With Neutron networking the NETWORK_MANAGER variable is ignored.
  29. # Settings
  30. # --------
  31. # Set up default directories
  32. NEUTRON_CONF_DIR=/etc/neutron
  33. NEUTRON_CONF=$NEUTRON_CONF_DIR/neutron.conf
  34. count=0
  35. Q_CISCO_CSR1KV_SETUP_SCRIPT_DIR=${Q_CISCO_CSR1KV_SETUP_SCRIPT_DIR:-$DIR_CISCO/devstack/csr1kv}
  36. # Default Neutron Plugin
  37. Q_PLUGIN=${Q_PLUGIN:-cisco}
  38. # Default Neutron Port
  39. Q_PORT=${Q_PORT:-9696}
  40. # Default protocol
  41. Q_PROTOCOL=${Q_PROTOCOL:-$SERVICE_PROTOCOL}
  42. # RHEL's support for namespaces requires using veths with ovs
  43. Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True}
  44. # nova vif driver that all plugins should use
  45. Q_NOTIFY_NOVA_PORT_STATUS_CHANGES=${Q_NOTIFY_NOVA_PORT_STATUS_CHANGES:-True}
  46. Q_NOTIFY_NOVA_PORT_DATA_CHANGES=${Q_NOTIFY_NOVA_PORT_DATA_CHANGES:-True}
  47. Q_CISCO_MGMT_CFG_AGENT_IP=10.0.100.2
  48. # Enable ASR1K
  49. Q_CISCO_ASR1K_ENABLED=${Q_CISCO_ASR1K_ENABLED:-True}
  50. # MySQL info
  51. MYSQL_USER=${MYSQL_USER:root}
  52. MYSQL_PASSWORD=${MYSQL_PASSWORD:password}
  53. source $DIR_CISCO/devstack/csr1kv/cisco
  54. source $DIR_CISCO/devstack/csr1kv/cisco_router
  55. source $DIR_CISCO/devstack/csr1kv/ciscocfgagent
  56. # Cisco Routing Service Plugin functions
  57. # ---------------------------------
  58. # Use security group or not
  59. # Save trace setting
  60. XTRACE=$(set +o | grep xtrace)
  61. set +o xtrace
  62. # Functions
  63. # ---------
  64. # Test if any Neutron services are enabled
  65. # is_neutron_enabled
  66. function is_neutron_enabled {
  67. [[ ,${ENABLED_SERVICES} =~ ,"q-" ]] && return 0
  68. return 1
  69. }
  70. function configure_cisco_csr_router {
  71. net_create_neutron_accounts
  72. net_configure_neutron
  73. net_start_neutron_agents
  74. Q_L3_ENABLED="False"
  75. }
  76. function start_cisco_csr_router {
  77. if [[ "$count" == 0 ]];then
  78. if [[ "$Q_CISCO_ASR1K_ENABLED" == "True" ]]; then
  79. setup_for_asr1k
  80. else
  81. setup_for_csr1kv
  82. fi
  83. Q_L3_ENABLED="True"
  84. net_create_neutron_initial_network
  85. count=$((count+1))
  86. fi
  87. }
  88. # net_configure_neutron()
  89. # Set common config for Cisco router after neutron server and agents.
  90. function net_configure_neutron {
  91. # goes before q-svc to init Q_SERVICE_PLUGIN_CLASSES
  92. if is_service_enabled q-ciscorouter; then
  93. _configure_neutron_cisco_router
  94. fi
  95. if is_service_enabled q-agt q-svc; then
  96. _configure_neutron_service
  97. fi
  98. }
  99. function get_or_add_user_role {
  100. # Gets user role id
  101. local user_role_id=$(openstack user role list \
  102. $2 \
  103. --project $3 \
  104. --column "ID" \
  105. --column "Name" \
  106. | grep " $1 " | get_field 1)
  107. if [[ -z "$user_role_id" ]]; then
  108. # Adds role to user
  109. user_role_id=$(openstack role add \
  110. $1 \
  111. --user $2 \
  112. --project $3 \
  113. | grep " id " | get_field 2)
  114. fi
  115. echo $user_role_id
  116. }
  117. # net_create_neutron_accounts() - Set up common required neutron accounts
  118. # Tenant User Roles
  119. # ------------------------------------------------------------------
  120. # service neutron admin # if enabled
  121. # Migrated from keystone_data.sh
  122. function net_create_neutron_accounts {
  123. local service_tenant=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
  124. local service_role=$(openstack role list | awk "/ service / { print \$2 }")
  125. if [[ "$ENABLED_SERVICES" =~ "q-svc" ]]; then
  126. local neutron_user=$(get_or_create_user "neutron" \
  127. "$SERVICE_PASSWORD" $service_tenant)
  128. get_or_add_user_role $service_role $neutron_user $service_tenant
  129. if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
  130. local neutron_service=$(get_or_create_service "neutron" \
  131. "network" "Neutron Service")
  132. get_or_create_endpoint $neutron_service \
  133. "$REGION_NAME" \
  134. "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/" \
  135. "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/" \
  136. "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/"
  137. fi
  138. fi
  139. }
  140. function setup_for_asr1k {
  141. if [[ "$Q_PLUGIN" == "ml2" ]]; then
  142. plugin=ovs
  143. fi
  144. echo "Running ASR1K setup scripts with ${MYSQL_USER} ${MYSQL_PASSWORD}"
  145. if [[ -f $TOP_DIR/localrc ]]; then
  146. localrc_name=$TOP_DIR/localrc
  147. else
  148. localrc_name=$TOP_DIR/local.conf
  149. fi
  150. (cd $Q_CISCO_CSR1KV_SETUP_SCRIPT_DIR; ./csr1kv_install_all.sh neutron $plugin $localrc_name $MYSQL_USER $MYSQL_PASSWORD $Q_CISCO_MGMT_CFG_AGENT_IP True)
  151. }
  152. function setup_for_csr1kv {
  153. if [[ "$Q_PLUGIN" == "csr1kv_openvswitch" ]]; then
  154. plugin=ovs
  155. elif [[ "$Q_PLUGIN" == "cisco" || "${Q_CISCO_PLUGIN_SUBPLUGINS[0]}" == "n1kv" ]]; then
  156. plugin=n1kv
  157. else
  158. die $LINENO "Not a deployment with CSR1kv. Exiting!"
  159. fi
  160. echo "Running CSR1Kv setup with ${MYSQL_USER} ${MYSQL_PASSWORD}"
  161. if [[ -f $TOP_DIR/localrc ]]; then
  162. localrc_name=$TOP_DIR/localrc
  163. else
  164. localrc_name=$TOP_DIR/local.conf
  165. fi
  166. (cd $Q_CISCO_CSR1KV_SETUP_SCRIPT_DIR; ./csr1kv_install_all.sh neutron $plugin $localrc_name $MYSQL_USER $MYSQL_PASSWORD $Q_CISCO_MGMT_CFG_AGENT_IP False)
  167. }
  168. function net_create_neutron_initial_network {
  169. if [ "$Q_L3_ENABLED" == "True" && $NEUTRON_CREATE_INITIAL_NETWORK = "True" ]; then
  170. # Create a router, and add the private subnet as one of its interfaces
  171. if [[ "$Q_L3_ROUTER_PER_TENANT" == "True" ]]; then
  172. # create a tenant-owned router.
  173. DEMO_TENANT_NAME="demo"
  174. DEMO_TENANT_ID=$(openstack project list | awk "/ $DEMO_TENANT_NAME / { print \$2 }")
  175. ROUTER_ID=$(neutron router-create --tenant-id $DEMO_TENANT_ID $Q_ROUTER_NAME | grep ' id ' | get_field 2)
  176. die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $TENANT_ID $Q_ROUTER_NAME"
  177. else
  178. # Plugin only supports creating a single router, which should be admin owned.
  179. ROUTER_ID=$(neutron router-create $Q_ROUTER_NAME | grep ' id ' | get_field 2)
  180. die_if_not_set $LINENO ROUTER_ID "Failure creating ROUTER_ID for $Q_ROUTER_NAME"
  181. fi
  182. # Create an external network, and a subnet. Configure the external network as router gw
  183. if [ "$Q_USE_PROVIDERNET_FOR_PUBLIC" = "True" ]; then
  184. EXT_NET_ID=$(neutron net-create "$PUBLIC_NETWORK_NAME" -- --router:external=True --provider:network_type=flat --provider:physical_network=${PUBLIC_PHYSICAL_NETWORK} | grep ' id ' | get_field 2)
  185. else
  186. EXT_NET_ID=$(neutron net-create "$PUBLIC_NETWORK_NAME" -- --router:external=True | grep ' id ' | get_field 2)
  187. fi
  188. die_if_not_set $LINENO EXT_NET_ID "Failure creating EXT_NET_ID for $PUBLIC_NETWORK_NAME"
  189. if [[ "$IP_VERSION" =~ 4.* ]]; then
  190. # Configure router for IPv4 public access
  191. _neutron_configure_router_v4
  192. fi
  193. if [[ "$IP_VERSION" =~ .*6 ]]; then
  194. # Configure router for IPv6 public access
  195. _neutron_configure_router_v6
  196. fi
  197. fi
  198. }
  199. # Start running processes, including screen
  200. function net_start_neutron_agents {
  201. if is_service_enabled ciscocfgagent; then
  202. start_the_ciscocfgagent
  203. fi
  204. }
  205. # net_stop_neutron() - Stop running processes (non-screen)
  206. function net_stop_neutron {
  207. if is_service_enabled q-ciscorouter; then
  208. neutron_cisco_router_stop
  209. fi
  210. }
  211. function _configure_neutron_cisco_router {
  212. neutron_cisco_router_configure_common
  213. }
  214. # _configure_neutron_service() - Set config files for neutron service
  215. # It is called when q-svc is enabled.
  216. function _configure_neutron_service {
  217. Q_API_PASTE_FILE=$NEUTRON_CONF_DIR/api-paste.ini
  218. Q_POLICY_FILE=$NEUTRON_CONF_DIR/policy.json
  219. # Update either configuration file with plugin
  220. iniset $NEUTRON_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS
  221. if [[ $Q_SERVICE_PLUGIN_CLASSES != '' ]]; then
  222. iniset $NEUTRON_CONF DEFAULT service_plugins $Q_SERVICE_PLUGIN_CLASSES
  223. fi
  224. # Configuration for neutron notifations to nova.
  225. iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_status_changes $Q_NOTIFY_NOVA_PORT_STATUS_CHANGES
  226. iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_data_changes $Q_NOTIFY_NOVA_PORT_DATA_CHANGES
  227. iniset $NEUTRON_CONF DEFAULT nova_url "$NOVA_SERVICE_PROTOCOL://$NOVA_SERVICE_HOST:$NOVA_SERVICE_PORT/v2"
  228. iniset $NEUTRON_CONF DEFAULT nova_admin_username nova
  229. iniset $NEUTRON_CONF DEFAULT nova_admin_password $SERVICE_PASSWORD
  230. ADMIN_TENANT_ID=$(openstack project list | awk "/ service / { print \$2 }")
  231. iniset $NEUTRON_CONF DEFAULT nova_admin_tenant_id $ADMIN_TENANT_ID
  232. iniset $NEUTRON_CONF DEFAULT nova_admin_auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0"
  233. # Configure plugin
  234. net_neutron_plugin_configure_service
  235. }
  236. # Restore xtrace
  237. $XTRACE
  238. # Tell emacs to use shell-script-mode
  239. ## Local variables:
  240. ## mode: shell-script
  241. ## End: