Merge R3 into master
[it/dep.git] / tools / k8s / bin / gen-ric-heat-yaml.sh
1 #!/bin/bash
2 #
3 ################################################################################
4 #   Copyright (c) 2019 AT&T Intellectual Property.                             #
5 #   Copyright (c) 2019 Nokia.                                                  #
6 #                                                                              #
7 #   Licensed under the Apache License, Version 2.0 (the "License");            #
8 #   you may not use this file except in compliance with the License.           #
9 #   You may obtain a copy of the License at                                    #
10 #                                                                              #
11 #       http://www.apache.org/licenses/LICENSE-2.0                             #
12 #                                                                              #
13 #   Unless required by applicable law or agreed to in writing, software        #
14 #   distributed under the License is distributed on an "AS IS" BASIS,          #
15 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
16 #   See the License for the specific language governing permissions and        #
17 #   limitations under the License.                                             #
18 ################################################################################
19
20
21 usage() {
22     echo "Usage: $0 [ -n <number of VMs {1-99}> ][ -6 ]" 1>&2;
23
24     echo "n:    Set the number of VMs that will be installed. This number must be between 1 and 99; " 1>&2;
25     echo "6:    When set, VMs will be configured with an IPv6 interface" 1>&2;
26     exit 1;
27 }
28
29 unset V6
30 while getopts ":n:6" o; do
31     case "${o}" in
32     n)
33         if [[ ${OPTARG} =~ ^[0-9]+$ ]];then
34             if [ ${OPTARG} -ge 1 -a ${OPTARG} -le 15 ]; then
35                 vm_num=${OPTARG}
36             else
37                 usage
38             fi
39         else
40             usage
41         fi
42         ;;
43     6)
44         V6='-v6'
45         ;;
46     *)
47          usage
48          ;;
49     esac
50 done
51 shift $((OPTIND-1))
52
53 NUM_K8S_VMS=$(($vm_num - 1))
54 unset SEQ
55 if [ "$NUM_K8S_VMS" -gt "0" ]; then
56   SEQ=$(seq -f %02g $NUM_K8S_VMS)
57 fi
58
59 if [ -z "$WORKSPACE" ]; then
60     export WORKSPACE=`git rev-parse --show-toplevel`
61 fi
62 PARTS_DIR=$WORKSPACE/ric-infra/00-Kubernetes/heat/parts
63
64 cat <<EOF
65 #
66 # Generated by scripts/gen-onap-oom-yaml.sh; MANUAL CHANGES WILL BE LOST
67 #
68 EOF
69
70 cat $PARTS_DIR/part-1${V6}.yaml
71
72
73 # the first node is master
74 #for VM_NUM in mst $(seq -f %02g $NUM_K8S_VMS); do
75 for VM_NUM in mst $SEQ; do
76     VM_TYPE=k8s HOST_LABEL=compute VM_NUM=$VM_NUM envsubst < $PARTS_DIR/part-2${V6}.yaml
77 done
78
79
80 cat $PARTS_DIR/part-3${V6}.yaml
81
82 #for VM_NUM in mst $(seq -f %02g $NUM_K8S_VMS); do
83 for VM_NUM in mst $SEQ; do
84     K8S_VM_NAME=k8s_$VM_NUM
85     cat <<EOF
86   ${K8S_VM_NAME}_vm_ip:
87     description: The IP address of the ${K8S_VM_NAME} instance
88     value: { get_attr: [${K8S_VM_NAME}_floating_ip, floating_ip_address] }
89
90 EOF
91 done