openstack-helm/ironic/templates/bin/_manage-cleaning-network.sh.tpl
Mingyuan Qi 1fd5ec6595 Check return value of get subnets before iterate for ironic
With the update of openstack clients:
openstack client >= 4.0.0
neutron client >= 6.14.0
neturon lib >= 1.29.1

The command 'openstack network show ${network} -f value -c subnets'
returns '[]' instead of null string if no subnets found in the
specific network. This commit adds a check logic to avoid subsequent
command returns error by using '[]' as subnet input.

Change-Id: I7e7d5209227b0e34131b7715dbd3faa6066a94b7
Signed-off-by: Mingyuan Qi <mingyuan.qi@intel.com>
2019-12-31 19:02:45 +00:00

51 lines
1.7 KiB
Smarty

#!/bin/bash
{{/*
Copyright 2017 The Openstack-Helm Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/}}
set -ex
if ! openstack network show ${neutron_network_name}; then
IRONIC_NEUTRON_CLEANING_NET_ID=$(openstack network create -f value -c id \
--share \
--provider-network-type flat \
--provider-physical-network ${neutron_provider_network} \
${neutron_network_name})
else
IRONIC_NEUTRON_CLEANING_NET_ID=$(openstack network show ${neutron_network_name} -f value -c id)
fi
SUBNETS=$(openstack network show $IRONIC_NEUTRON_CLEANING_NET_ID -f value -c subnets)
if [ "x${SUBNETS}" != "x[]" ]; then
for SUBNET in ${SUBNETS}; do
CURRENT_SUBNET=$(openstack subnet show $SUBNET -f value -c name)
if [ "x${CURRENT_SUBNET}" == "x${neutron_subnet_name}" ]; then
openstack subnet show ${neutron_subnet_name}
SUBNET_EXISTS=true
fi
done
fi
if [ "x${SUBNET_EXISTS}" != "xtrue" ]; then
openstack subnet create \
--gateway ${neutron_subnet_gateway%/*} \
--allocation-pool start=${neutron_subnet_alloc_start},end=${neutron_subnet_alloc_end} \
--dns-nameserver ${neutron_subnet_dns_nameserver} \
--subnet-range ${neutron_subnet_cidr} \
--network ${neutron_network_name} \
${neutron_subnet_name}
fi