| Alex Savatieiev | ec70369 | 2019-06-07 15:33:31 -0500 | [diff] [blame] | 1 | #!/bin/bash | 
 | 2 | export OS_INTERFACE='admin' | 
 | 3 |  | 
 | 4 | # local vars | 
 | 5 | name_prefix=cvp | 
 | 6 | filename=${name_prefix}.manifest | 
| Alex Savatieiev | 2ddfe16 | 2019-07-02 12:05:51 -0500 | [diff] [blame] | 7 | rcfile=${name_prefix}rc | 
| Alex Savatieiev | ec70369 | 2019-06-07 15:33:31 -0500 | [diff] [blame] | 8 | huge_pages=false | 
| Alex Savatieiev | 2ddfe16 | 2019-07-02 12:05:51 -0500 | [diff] [blame] | 9 | logfile=prepare.log | 
| Alex Savatieiev | ec70369 | 2019-06-07 15:33:31 -0500 | [diff] [blame] | 10 |  | 
 | 11 | # Project, User, Roles | 
 | 12 | project=${name_prefix}.project | 
 | 13 | user=${name_prefix}.user | 
 | 14 | admin=${name_prefix}.admin | 
 | 15 | password=mcp1234 | 
 | 16 |  | 
 | 17 | # Security group | 
 | 18 | sg_all=${name_prefix}.sg.all | 
 | 19 | sg_icmp=${name_prefix}.sg.icmp | 
 | 20 | sg_ssh=${name_prefix}.sg.ssh | 
 | 21 | sg_iperf=${name_prefix}.sg.perf | 
 | 22 |  | 
 | 23 | # Testkey | 
 | 24 | key=${name_prefix}_testkey | 
 | 25 |  | 
 | 26 | # Flavors: tiny, small (cirrus and migration), medium (ubuntu and volume/stress activities) | 
 | 27 | flavor_t=${name_prefix}.tiny | 
 | 28 | flavor_s=${name_prefix}.small | 
 | 29 | flavor_m=${name_prefix}.medium | 
| Alex | 6892c8c | 2021-01-28 16:07:29 -0600 | [diff] [blame] | 30 | flavor_h=${name_prefix}.high | 
| Alex Savatieiev | ec70369 | 2019-06-07 15:33:31 -0500 | [diff] [blame] | 31 |  | 
 | 32 | # Fixed Networks (2, for testing router interconnection) | 
 | 33 | net_left=${name_prefix}.net.1 | 
 | 34 | net_right=${name_prefix}.net.2 | 
 | 35 | subnet1=${name_prefix}.subnet.1 | 
 | 36 | subnet2=${name_prefix}.subnet.2 | 
 | 37 |  | 
 | 38 | # Router | 
 | 39 | router=${name_prefix}.router | 
 | 40 |  | 
 | 41 | # Images: cirros (3.5, 4.0), ubuntu (16.04) | 
 | 42 | cirros3=${name_prefix}.cirros.35 | 
 | 43 | cirros4=${name_prefix}.cirros.40 | 
 | 44 | ubuntu16=${name_prefix}.ubuntu.1604 | 
| Alex | 6892c8c | 2021-01-28 16:07:29 -0600 | [diff] [blame] | 45 | ubuntuspt=${name_prefix}.ubuntu.spt | 
| Alex Savatieiev | ec70369 | 2019-06-07 15:33:31 -0500 | [diff] [blame] | 46 |  | 
 | 47 | cirros3_link=http://download.cirros-cloud.net/0.3.5/cirros-0.3.5-x86_64-disk.img | 
 | 48 | cirros4_link=http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-aarch64-disk.img | 
 | 49 | ubuntu16_link=https://cloud-images.ubuntu.com/xenial/current/xenial-server-cloudimg-amd64-disk1.img | 
 | 50 |  | 
 | 51 | # Volume (2GB) | 
 | 52 | volume=${name_prefix}.volume | 
 | 53 |  | 
 | 54 | function show_help { | 
 | 55 |     printf "CVP Pipeline: Resource creation script\n\t-h, -?\t\tShow this help\n" | 
 | 56 |     printf "\t-H\t\tAdds '--property hw:mem_page_size=large' to flavors, i.e. huge_pages for DPDK\n" | 
 | 57 |     printf "\t-w <path>\tSets working folder" | 
 | 58 | } | 
 | 59 |  | 
 | 60 | OPTIND=1 # Reset in case getopts has been used previously in the shell. | 
 | 61 | while getopts "h?:Hw:" opt; do | 
 | 62 |     case "$opt" in | 
 | 63 |     h|\?) | 
 | 64 |         show_help | 
 | 65 |         exit 0 | 
 | 66 |         ;; | 
 | 67 |     w)  working_folder=${OPTARG} | 
 | 68 |         printf "# Working folder is ${working_folder}\n" | 
 | 69 |         ;; | 
 | 70 |     h)  huge_pages=true | 
 | 71 |         printf "# Using 'huge_pages' property in flavors\n" | 
 | 72 |         ;; | 
 | 73 |     esac | 
 | 74 | done | 
 | 75 |  | 
 | 76 | shift $((OPTIND-1)) | 
 | 77 | [ "${1:-}" = "--" ] && shift | 
 | 78 |  | 
 | 79 | function put() { | 
 | 80 |     echo "$1=$2" | tee -a ${filename} | 
 | 81 | } | 
 | 82 |  | 
 | 83 | # now, some hard to understand stuff... | 
 | 84 | # f1 $(<command with output to cut>) | 
 | 85 | function f1() { echo $1 | cut -d' ' -f1; }; | 
 | 86 | # <commands with output to cut> | p1 | 
 | 87 | function p1() { while read input; do echo ${input} | cut -d' ' -f1; done; }; | 
 | 88 | # ol1 is short for openstack list with 1 param. Also grep and cut | 
 | 89 | # "ol1 network public" will list all networks, grep by name public and return IDs | 
 | 90 | function ol1() { echo $(openstack $1 list -c ID -c Name -f value | grep $2 | cut -d' ' -f1); } | 
 | 91 | # same as ol1 but with 2 initial commands before list | 
 | 92 | function ol2() { echo $(openstack $1 $2 list -c ID -c Name -f value | grep $3 | cut -d' ' -f1); } | 
 | 93 |  | 
 | 94 | function print_manifest() { | 
 | 95 |     touch ./${filename} | 
 | 96 |     truncate -s 0 ${filename} | 
| Alex Savatieiev | 2ddfe16 | 2019-07-02 12:05:51 -0500 | [diff] [blame] | 97 |     printf "\n\n# Checking and filling manifest: $(pwd)/${filename}\n" | 
 | 98 |     put project_name ${project} | 
| Alex Savatieiev | ec70369 | 2019-06-07 15:33:31 -0500 | [diff] [blame] | 99 |     put project_id $(ol1 project ${project}) | 
 | 100 |     put user_name ${user} | 
 | 101 |     put user_id $(ol1 user ${user}) | 
 | 102 |     put admin_name ${admin} | 
 | 103 |     put admin_id $(ol1 user ${admin}) | 
 | 104 |     # sg | 
 | 105 |     put secgroup_all_name ${sg_all} | 
 | 106 |     put secgroup_all_id $(ol2 security group ${sg_all}) | 
 | 107 |     put secgroup_icmp_name ${sg_icmp} | 
 | 108 |     put secgroup_icmp_id $(ol2 security group ${sg_icmp}) | 
 | 109 |     put secgroup_ssh_name ${sg_ssh} | 
 | 110 |     put secgroup_ssh_id $(ol2 security group ${sg_ssh}) | 
 | 111 |     put secgroup_iperf_name ${sg_iperf} | 
 | 112 |     put secgroup_iperf_id $(ol2 security group ${sg_iperf}) | 
 | 113 |  | 
 | 114 |     # keypair | 
 | 115 |     put keypair_name ${key} | 
 | 116 |     put keypair_id $(ol1 keypair ${key}) | 
 | 117 |  | 
 | 118 |     # flavors | 
 | 119 |     put flavor_tiny_name ${flavor_t} | 
 | 120 |     put flavor_tiny_id $(ol1 flavor ${flavor_t}) | 
 | 121 |     put flavor_small_name ${flavor_s} | 
 | 122 |     put flavor_small_id $(ol1 flavor ${flavor_s}) | 
 | 123 |     put flavor_medium_name ${flavor_m} | 
 | 124 |     put flavor_medium_id $(ol1 flavor ${flavor_m}) | 
| Alex | 6892c8c | 2021-01-28 16:07:29 -0600 | [diff] [blame] | 125 |     put flavor_high_name ${flavor_h} | 
 | 126 |     put flavor_high_id $(ol1 flavor ${flavor_h}) | 
| Alex Savatieiev | ec70369 | 2019-06-07 15:33:31 -0500 | [diff] [blame] | 127 |  | 
 | 128 |     # fixed nets | 
 | 129 |     put fixed_net_left_name ${net_left} | 
 | 130 |     put fixed_net_left_id $(ol1 network ${net_left}) | 
 | 131 |     put fixed_net_right_name ${net_right} | 
 | 132 |     put fixed_net_right_id $(ol1 network ${net_right}) | 
 | 133 |     put fixed_net_left_subnet_name ${subnet1} | 
 | 134 |     put fixed_net_left_subnet_id $(openstack subnet list --network ${net_left} -c ID -f value | p1) | 
 | 135 |     put fixed_net_right_subnet_name ${subnet2} | 
 | 136 |     put fixed_net_right_subnet_id $(openstack subnet list --network ${net_right} -c ID -f value | p1) | 
 | 137 |  | 
 | 138 |     # router | 
 | 139 |     put router_name ${router} | 
 | 140 |     put router_id $(ol1 router ${router}) | 
 | 141 |  | 
 | 142 |     # volumes | 
 | 143 |     put volume_name ${volume} | 
 | 144 |     put volume_id $(ol1 volume ${volume}) | 
 | 145 |  | 
 | 146 |     # images | 
 | 147 |     put cirros35_name ${cirros3} | 
 | 148 |     put cirros35_id $(ol1 image ${cirros3}) | 
 | 149 |     put cirros40_name ${cirros4} | 
 | 150 |     put cirros40_id $(ol1 image ${cirros4}) | 
| Alex | 6892c8c | 2021-01-28 16:07:29 -0600 | [diff] [blame] | 151 |     put ubuntu16_name ${ubuntu16} | 
| Alex Savatieiev | ec70369 | 2019-06-07 15:33:31 -0500 | [diff] [blame] | 152 |     put ubuntu16_id $(ol1 image ${ubuntu16}) | 
| Alex | 6892c8c | 2021-01-28 16:07:29 -0600 | [diff] [blame] | 153 |     put ubuntuspt_name ${ubuntuspt} | 
 | 154 |     put ubuntuspt_id $(ol1 image ${ubuntuspt}) | 
| Alex Savatieiev | ec70369 | 2019-06-07 15:33:31 -0500 | [diff] [blame] | 155 | } | 
 | 156 |  | 
| Alex Savatieiev | 2ddfe16 | 2019-07-02 12:05:51 -0500 | [diff] [blame] | 157 | # create rc file out of current ENV vars | 
 | 158 | function putrc() { | 
 | 159 |     printf "# Saving ${1} file\n" | 
 | 160 |     echo "export OS_IDENTITY_API_VERSION=${OS_IDENTITY_API_VERSION:-3}" >${1} | 
 | 161 |     echo "export OS_AUTH_URL=${OS_AUTH_URL}" >>${1} | 
 | 162 |     echo "export OS_PROJECT_DOMAIN_NAME=${OS_PROJECT_DOMAIN_NAME}" >>${1} | 
 | 163 |     echo "export OS_USER_DOMAIN_NAME=${OS_USER_DOMAIN_NAME}" >>${1} | 
 | 164 |     echo "export OS_PROJECT_NAME=${OS_PROJECT_NAME}" >>${1} | 
 | 165 |     echo "export OS_TENANT_NAME=${OS_TENANT_NAME}" >>${1} | 
 | 166 |     echo "export OS_USERNAME=${OS_USERNAME}" >>${1} | 
 | 167 |     echo "export OS_PASSWORD=${OS_PASSWORD}" >>${1} | 
 | 168 |     echo "export OS_REGION_NAME=${OS_REGION_NAME}" >>${1} | 
 | 169 |     echo "export OS_INTERFACE=${OS_INTERFACE}" >>${1} | 
 | 170 |     echo "export OS_ENDPOINT_TYPE=${OS_ENDPOINT_TYPE}" >>${1} | 
 | 171 |     echo "export OS_CACERT=${OS_CACERT}" >>${1} | 
 | 172 | } | 
 | 173 |  | 
 | 174 | # update ENV vars to newly created project | 
 | 175 | function updatesession() { | 
 | 176 |     export OS_PROJECT_NAME=${project} | 
 | 177 |     export OS_TENANT_NAME=${project} | 
 | 178 |     export OS_USERNAME=${admin} | 
 | 179 |     export OS_PASSWORD=${password} | 
 | 180 | } | 
 | 181 |  | 
| Alex Savatieiev | ec70369 | 2019-06-07 15:33:31 -0500 | [diff] [blame] | 182 | function process_cmds() { | 
 | 183 |     if [ -s ${cmds} ]; then | 
| Alex Savatieiev | 2ddfe16 | 2019-07-02 12:05:51 -0500 | [diff] [blame] | 184 |         cat ${cmds} | tr '\n' '\0' | xargs -P 1 -n 1 -0 echo | tee /dev/tty | openstack -v 2>&1 >>${logfile} | 
| Alex Savatieiev | ec70369 | 2019-06-07 15:33:31 -0500 | [diff] [blame] | 185 |         truncate -s 0 ${cmds} | 
 | 186 |     fi | 
 | 187 | } | 
 | 188 |  | 
 | 189 | function _project() { | 
| Alex | d844aa9 | 2021-03-19 15:29:40 -0500 | [diff] [blame] | 190 |     echo project create ${project} >>${cmds} | 
| Alex Savatieiev | ec70369 | 2019-06-07 15:33:31 -0500 | [diff] [blame] | 191 |     echo role add --user admin --project ${project} admin >>${cmds} | 
 | 192 | } | 
 | 193 |  | 
 | 194 | function _users() { | 
 | 195 |     echo user create --project ${project} --password ${password} ${user} >>${cmds} | 
 | 196 |     echo user create --project ${project} --password ${password} ${admin} >>${cmds} | 
 | 197 |     echo role add --user ${admin} --project ${project} admin >>${cmds} | 
 | 198 | } | 
 | 199 |  | 
 | 200 | function _sg_all() { | 
| Alex | d844aa9 | 2021-03-19 15:29:40 -0500 | [diff] [blame] | 201 |     echo security group create --project ${project} ${sg_all} >>${cmds} | 
| Alex Savatieiev | ec70369 | 2019-06-07 15:33:31 -0500 | [diff] [blame] | 202 |     # icmp | 
 | 203 |     echo security group rule create --protocol icmp ${sg_all} >>${cmds} | 
 | 204 |     # ssh | 
 | 205 |     echo security group rule create --protocol tcp --dst-port 22 ${sg_all} >>${cmds} | 
 | 206 |     # iperf | 
 | 207 |     echo security group rule create --protocol tcp --dst-port 5001 ${sg_all} >>${cmds} | 
 | 208 |     # iperf3 | 
 | 209 |     echo security group rule create --protocol tcp --dst-port 5201 ${sg_all} >>${cmds} | 
 | 210 |     # nc connectivity | 
 | 211 |     echo security group rule create --protocol tcp --dst-port 3000 ${sg_all} >>${cmds} | 
 | 212 |     # http | 
 | 213 |     echo security group rule create --protocol tcp --dst-port 80 ${sg_all} >>${cmds} | 
| Alex | 6892c8c | 2021-01-28 16:07:29 -0600 | [diff] [blame] | 214 |     # https | 
 | 215 |     echo security group rule create --protocol tcp --dst-port 443 ${sg_all} >>${cmds} | 
| Alex Savatieiev | ec70369 | 2019-06-07 15:33:31 -0500 | [diff] [blame] | 216 | } | 
 | 217 |  | 
 | 218 | function _sg_icmp() { | 
| Alex | d844aa9 | 2021-03-19 15:29:40 -0500 | [diff] [blame] | 219 |     echo security group create --project ${project} ${sg_icmp} >>${cmds} | 
| Alex Savatieiev | ec70369 | 2019-06-07 15:33:31 -0500 | [diff] [blame] | 220 |     echo security group rule create --protocol icmp ${sg_icmp} >>${cmds} | 
 | 221 | } | 
 | 222 |  | 
 | 223 | function _sg_ssh() { | 
| Alex | d844aa9 | 2021-03-19 15:29:40 -0500 | [diff] [blame] | 224 |     echo security group create --project ${project} ${sg_ssh} >>${cmds} | 
| Alex Savatieiev | ec70369 | 2019-06-07 15:33:31 -0500 | [diff] [blame] | 225 |     # icmp | 
 | 226 |     echo security group rule create --protocol icmp ${sg_ssh} >>${cmds} | 
 | 227 |     # ssh | 
 | 228 |     echo security group rule create --protocol tcp --dst-port 22 ${sg_ssh} >>${cmds} | 
 | 229 | } | 
 | 230 |  | 
 | 231 | function _sg_iperf() { | 
| Alex | d844aa9 | 2021-03-19 15:29:40 -0500 | [diff] [blame] | 232 |     echo security group create --project ${project} ${sg_iperf} >>${cmds} | 
| Alex Savatieiev | ec70369 | 2019-06-07 15:33:31 -0500 | [diff] [blame] | 233 |     # icmp | 
 | 234 |     echo security group rule create --protocol icmp ${sg_iperf} >>${cmds} | 
 | 235 |     # iperf | 
 | 236 |     echo security group rule create --protocol tcp --dst-port 5001 ${sg_iperf} >>${cmds} | 
 | 237 |     # iperf3 | 
 | 238 |     echo security group rule create --protocol tcp --dst-port 5201 ${sg_iperf} >>${cmds} | 
 | 239 | } | 
 | 240 |  | 
 | 241 | function create_keypair() { | 
 | 242 |     echo "# Creating keypair" | 
 | 243 |     openstack keypair create ${key} >${key} | 
 | 244 |     chmod 600 ${key} | 
 | 245 |     echo "-> created keyfile: $(pwd)/${key}" | 
 | 246 | } | 
 | 247 |  | 
 | 248 | function _flavors() { | 
 | 249 |     # huge paged flavors | 
 | 250 |     if [ "$huge_pages" = true ]; then | 
 | 251 |         echo flavor create --id 1 --ram 64 --disk 1 --vcpus 1 ${flavor_t} --property hw:mem_page_size=large >>${cmds} | 
| Alex | 6892c8c | 2021-01-28 16:07:29 -0600 | [diff] [blame] | 252 |         echo flavor create --id 2 --ram 256 --disk 2 --vcpus 1 ${flavor_s} --property hw:mem_page_size=large >>${cmds} | 
 | 253 |         echo flavor create --id 3 --ram 2048 --disk 10 --vcpus 2 ${flavor_m} --property hw:mem_page_size=large >>${cmds} | 
 | 254 |         echo flavor create --id 4 --ram 2048 --disk 20 --vcpus 4 ${flavor_h} --property hw:mem_page_size=large >>${cmds} | 
| Alex Savatieiev | ec70369 | 2019-06-07 15:33:31 -0500 | [diff] [blame] | 255 |     else | 
| Alex | 6892c8c | 2021-01-28 16:07:29 -0600 | [diff] [blame] | 256 |         echo flavor create --id 1 --ram 64 --disk 1 --vcpus 1 ${flavor_t} >>${cmds} | 
 | 257 |         echo flavor create --id 2 --ram 256 --disk 2 --vcpus 1 ${flavor_s} >>${cmds} | 
 | 258 |         echo flavor create --id 3 --ram 2048 --disk 10 --vcpus 2 ${flavor_m} >>${cmds} | 
 | 259 |         echo flavor create --id 4 --ram 2048 --disk 20 --vcpus 4 ${flavor_h} >>${cmds} | 
| Alex Savatieiev | ec70369 | 2019-06-07 15:33:31 -0500 | [diff] [blame] | 260 |     fi | 
 | 261 | } | 
 | 262 |  | 
 | 263 | function _volumes() { | 
 | 264 |     echo volume create --size 2 ${volume} >>${cmds} | 
 | 265 | } | 
 | 266 |  | 
 | 267 | function create_fixed_nets() { | 
 | 268 |     echo "# Creating fixed networks" | 
 | 269 |     echo network create --project ${project} ${net_left} >>${cmds} | 
 | 270 |     echo subnet create ${subnet1} --network ${net_left} --subnet-range 10.10.11.0/24 >>${cmds} | 
 | 271 |     echo network set --share ${net_left} >>${cmds} | 
 | 272 |     echo network create --project ${project} ${net_right} >>${cmds} | 
 | 273 |     echo subnet create ${subnet2} --network ${net_right} --subnet-range 10.10.12.0/24 >>${cmds} | 
 | 274 |     echo network set --share ${net_right} >>${cmds} | 
 | 275 |     process_cmds | 
 | 276 |  | 
 | 277 |     # get subnet ids | 
 | 278 |     subnet1_id=$(openstack subnet list --network ${net_left} -c ID -f value) | 
 | 279 |     subnet2_id=$(openstack subnet list --network ${net_right} -c ID -f value) | 
 | 280 |  | 
 | 281 |     echo router create --project ${project} ${router} >>${cmds} | 
 | 282 |     process_cmds | 
 | 283 |  | 
 | 284 |     router_id=$(openstack router list -c ID -c Name -f value | grep ${router} | cut -d' ' -f1) | 
 | 285 |     echo router add subnet ${router_id} ${subnet1_id} >>${cmds} | 
 | 286 |     echo router add subnet ${router_id} ${subnet2_id} >>${cmds} | 
 | 287 |     process_cmds | 
 | 288 |  | 
 | 289 |     # TODO: Search for external net | 
| Alex | 6892c8c | 2021-01-28 16:07:29 -0600 | [diff] [blame] | 290 |     external=public | 
| Alex Savatieiev | ec70369 | 2019-06-07 15:33:31 -0500 | [diff] [blame] | 291 |     echo router set ${router} --external-gateway ${external} >>${cmds} | 
 | 292 |     process_cmds | 
 | 293 | } | 
 | 294 |  | 
 | 295 | function _get_image() { | 
 | 296 |     # build vars for name and link | 
 | 297 |     name="${1}" | 
 | 298 |     link="${1}_link" | 
| Alex | 6892c8c | 2021-01-28 16:07:29 -0600 | [diff] [blame] | 299 |     which wget >/dev/null | 
| Alex Savatieiev | ec70369 | 2019-06-07 15:33:31 -0500 | [diff] [blame] | 300 |     if [ $? -ne 0 ]; then | 
 | 301 |         printf "\nERROR: 'wget' not detected. Download skipped: ${!name}\n" | 
 | 302 |     else | 
 | 303 |         # no redownloads, quet, save named and show progress | 
 | 304 |         r=$(wget --no-check-certificate -nc -q -O ./${!name} --show-progress ${!link}) | 
 | 305 |         if [ $? -ne 0 ]; then | 
 | 306 |             # non-empty output on error | 
 | 307 |             echo ${r} | 
 | 308 |         fi | 
 | 309 |     fi | 
 | 310 | } | 
 | 311 |  | 
 | 312 | function create_image() { | 
 | 313 |     name="${1}" | 
 | 314 |     # Check if image is in the cloud | 
 | 315 |     echo "# Checking image '${!name}'" | 
 | 316 |     ids=( $(ol1 image ${!name}) ) | 
| Alex | 6892c8c | 2021-01-28 16:07:29 -0600 | [diff] [blame] | 317 |     # if array is empty, download and upload it | 
| Alex Savatieiev | ec70369 | 2019-06-07 15:33:31 -0500 | [diff] [blame] | 318 |     if [ ${#ids[@]} -eq 0 ]; then | 
 | 319 |         # check and download | 
 | 320 |         if [ ! -f ${!name} ]; then | 
 | 321 |             r=$(_get_image ${1}) | 
 | 322 |         else | 
 | 323 |             r="" | 
 | 324 |         fi | 
 | 325 |         # check if output is not empty | 
 | 326 |         if [ ${#r} -eq 0 ]; then | 
 | 327 |             image_id=$(openstack image create --public --disk-format qcow2 --container-format bare --file ${!name} ${!name} -c id -f value) | 
 | 328 |             echo "-> created ${!name} (${image_id})" | 
 | 329 |         else | 
 | 330 |             printf "\n-> Error detected, creation skipped\n" | 
 | 331 |         fi | 
 | 332 |     else | 
 | 333 |         # image(s) already there, list them | 
 | 334 |         for id in ${ids[@]}; do | 
 | 335 |             echo "-> found ${!name} with ID of '${id}'" | 
 | 336 |         done | 
 | 337 |     fi | 
 | 338 | } | 
 | 339 |  | 
 | 340 | ################### | 
 | 341 | ### Main | 
 | 342 | ################### | 
 | 343 | if [[ -z ${working_folder+x} ]]; then | 
 | 344 |     # cwd into working dir | 
 | 345 |     cd ${working_folder} | 
 | 346 | fi | 
 | 347 |  | 
 | 348 | cmds=$(mktemp) | 
 | 349 | trap "rm -f ${cmds}" EXIT | 
 | 350 | echo "Using tempfile: '${cmds}'" | 
 | 351 |  | 
| Alex Savatieiev | 2ddfe16 | 2019-07-02 12:05:51 -0500 | [diff] [blame] | 352 | touch ${logfile} | 
 | 353 | echo "Using log file: '${logfile}'" | 
 | 354 |  | 
 | 355 | # Create | 
 | 356 | echo "# Creating project and users" | 
| Alex Savatieiev | ec70369 | 2019-06-07 15:33:31 -0500 | [diff] [blame] | 357 | _project | 
 | 358 | _users | 
| Alex Savatieiev | 2ddfe16 | 2019-07-02 12:05:51 -0500 | [diff] [blame] | 359 | process_cmds | 
 | 360 |  | 
 | 361 | echo "# Creating 'rc' and switching" | 
 | 362 | putrc "./adminrc" | 
 | 363 | updatesession | 
 | 364 | putrc "./${rcfile}" | 
 | 365 |  | 
 | 366 | echo "# Creating basic resources" | 
 | 367 | # not dependent stuff | 
| Alex Savatieiev | ec70369 | 2019-06-07 15:33:31 -0500 | [diff] [blame] | 368 | _sg_all | 
 | 369 | _sg_icmp | 
 | 370 | _sg_ssh | 
 | 371 | _sg_iperf | 
 | 372 | _flavors | 
 | 373 | _volumes | 
 | 374 | process_cmds | 
 | 375 |  | 
| Alex Savatieiev | 2ddfe16 | 2019-07-02 12:05:51 -0500 | [diff] [blame] | 376 | # sophisticated, step dependent stuff | 
| Alex Savatieiev | ec70369 | 2019-06-07 15:33:31 -0500 | [diff] [blame] | 377 | create_keypair | 
 | 378 | create_fixed_nets | 
 | 379 |  | 
 | 380 | # images | 
 | 381 | create_image cirros3 | 
 | 382 | create_image cirros4 | 
 | 383 | create_image ubuntu16 | 
| Ievgeniia Zadorozhna | 427c405 | 2021-05-20 13:54:53 +0300 | [diff] [blame] | 384 | # update image name to correct one uploaded | 
 | 385 | ubuntuspt_file="ubuntuspt.img" | 
 | 386 | openstack image create --public --disk-format qcow2 --container-format bare --file ${ubuntuspt_file} ${ubuntuspt} -c id -f value | 
| Alex Savatieiev | ec70369 | 2019-06-07 15:33:31 -0500 | [diff] [blame] | 387 |  | 
| Alex Savatieiev | 2ddfe16 | 2019-07-02 12:05:51 -0500 | [diff] [blame] | 388 | ### Manifest and fall back to original rc | 
| Alex Savatieiev | ec70369 | 2019-06-07 15:33:31 -0500 | [diff] [blame] | 389 | print_manifest | 
| Alex | 6892c8c | 2021-01-28 16:07:29 -0600 | [diff] [blame] | 390 | printf ="\n\nSetting quota\n" | 
 | 391 | openstack quota set --cores -1 --ram -1 --instances -1 --volumes -1 --gigabytes -1 cvp.project | 
| Alex Savatieiev | 2ddfe16 | 2019-07-02 12:05:51 -0500 | [diff] [blame] | 392 | source "./adminrc" | 
| Alex | 6892c8c | 2021-01-28 16:07:29 -0600 | [diff] [blame] | 393 | printf "\n\nOriginal rc preserved and backed up in 'adminrc'\nNew rc is '${rcfile}'\n" |