Jack Lucas | a25c923 | 2020-03-02 11:07:31 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # ================================================================================ |
| 3 | # Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. |
| 4 | # ================================================================================ |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain 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, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | # ============LICENSE_END========================================================= |
| 17 | # |
| 18 | # Functions for uploading blueprints to DCAE inventory |
| 19 | |
| 20 | # Inventory API endpoint |
| 21 | INVENTORY=https://inventory:8080/dcae-service-types |
| 22 | #INVENTORY=https://localhost:8080/dcae-service-types |
| 23 | |
| 24 | # Default fixed values in service type definition |
| 25 | OWNER=dcaeorch |
| 26 | COMPONENT=dcae |
| 27 | APPLICATION=DCAE |
| 28 | |
| 29 | function flatten { |
| 30 | # Convert a blueprint file into a flattened, escaped string |
| 31 | # that can stored into a DCAE inventory "service type" |
| 32 | # $1: path to blueprint file to be flattened |
| 33 | |
| 34 | FLAT=$(sed -e 's/\\/\\\\/g' -e 's/"/\\"/g' -e 's/$/\\n/g' < $1 | tr -d '\n') |
| 35 | echo "${FLAT}" |
| 36 | } |
| 37 | |
| 38 | function create_service_type { |
| 39 | # Create a DCAE service type object (JSON), |
| 40 | # suitable for uploading to DCAE inventory. |
| 41 | # Use the name of the blueprint file (minus |
| 42 | # the .yaml suffix) as the type name. |
| 43 | # Use date-time (to the minute) in numeric |
| 44 | # form as the type version. |
| 45 | # $1: path to blueprint file for the service type |
| 46 | echo " |
| 47 | { |
| 48 | \"vnfTypes\": [], |
| 49 | \"owner\": \"${OWNER}\", |
| 50 | \"typeVersion\": $(date +%y%m%d%I%M), |
| 51 | \"typeName\": \"$(basename $1 .yaml)\", |
| 52 | \"component\": \"${COMPONENT}\", |
| 53 | \"application\": \"${APPLICATION}\", |
| 54 | \"blueprintTemplate\": \"$(flatten $1)\" |
| 55 | }" |
| 56 | } |
| 57 | |
| 58 | function upload_service_type { |
| 59 | # Transform a blueprint into a DCAE service type |
| 60 | # and upload to DCAE inventory |
| 61 | # $1: path to the blueprint |
| 62 | # $2: path to CA cert file (optional) |
| 63 | if [ "$2" ] |
| 64 | then |
| 65 | TLSCURL="--cacert $2" |
| 66 | fi |
| 67 | create_service_type $1 | \ |
| 68 | curl $TLSCURL -X POST -H "Content-Type: application/json" -d @- ${INVENTORY} |
| 69 | } |