summaryrefslogtreecommitdiffstats
path: root/cm-container/scripts/load-plugins.sh
diff options
context:
space:
mode:
authorJack Lucas <jflucas@research.att.com>2020-05-18 18:23:38 -0400
committerJack Lucas <jflucas@research.att.com>2020-06-12 09:39:23 -0400
commitec3410a8478bedba8a06efb02f1610c2ebfdf130 (patch)
tree59b8a007f1d76fc1b3a8eadc36825a5f28e1201d /cm-container/scripts/load-plugins.sh
parenta774ad9f309576a61db9689f5315f2577e507b25 (diff)
Move plugin upload to CM container
Issue-ID: DCAEGEN2-2236 Issue-ID: DCAEGEN2-1789 Signed-off-by: Jack Lucas <jflucas@research.att.com> Change-Id: Ibc4612dedbf73a17a237b88abe198add391b82de
Diffstat (limited to 'cm-container/scripts/load-plugins.sh')
-rwxr-xr-xcm-container/scripts/load-plugins.sh103
1 files changed, 103 insertions, 0 deletions
diff --git a/cm-container/scripts/load-plugins.sh b/cm-container/scripts/load-plugins.sh
new file mode 100755
index 0000000..f4d1f66
--- /dev/null
+++ b/cm-container/scripts/load-plugins.sh
@@ -0,0 +1,103 @@
+#!/bin/bash
+# ============LICENSE_START=======================================================
+# Copyright (c) 2019-2020 AT&T Intellectual Property. All rights reserved.
+# ================================================================================
+# 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.
+# ============LICENSE_END=========================================================
+# Runs at deployment time to load the plugins/type files
+# that were stored into the container file system at build time
+
+PLUGINS_LOADED=/opt/manager/plugins-loaded
+PLUGIN_DIR=/opt/plugins
+
+# Set defaults for CM address, protocol, and port
+CMADDR=${CMADDR:-dcae-cloudify-manager}
+CMPROTO=${CMPROTO:-https}
+CMPORT=${CMPORT:-443}
+
+# Password is currently fixed at the default
+# Eventually the password will be passed in as an environment variable
+CMPASS=${CMPASS:-admin}
+
+# Set up additional parameters for using HTTPS
+CACERT="/opt/onap/certs/cacert.pem"
+CURLTLS=""
+if [ $CMPROTO = "https" ]
+then
+ CURLTLS="--cacert $CACERT"
+fi
+
+### FUNCTION DEFINITIONS ###
+
+# cm_hasany: Query Cloudify Manager and return 0 (true) if there are any entities matching the query
+# Used to see if something is already present on CM
+# $1 -- query fragment, for instance "plugins?archive_name=xyz.wgn" to get
+# the number of plugins that came from the archive file "xyz.wgn"
+function cm_hasany {
+ # We use _include=id to limit the amount of data the CM sends back
+ # We rely on the "metadata.pagination.total" field in the response
+ # for the total number of matching entities
+ COUNT=$(curl -Ss -H "Tenant: default_tenant" --user admin:${CMPASS} ${CURLTLS} "${CMPROTO}://${CMADDR}:${CMPORT}/api/v3.1/$1&_include=id" \
+ | /bin/jq .metadata.pagination.total)
+ if (( $COUNT > 0 ))
+ then
+ return 0
+ else
+ return 1
+ fi
+}
+
+# Install plugin if it's not already installed
+# $1 -- path to wagon file for plugin
+# $2 -- path to type file for plugin
+function install_plugin {
+ ARCHIVE=$(basename $1)
+ # See if it's already installed
+ if cm_hasany "plugins?archive_name=$ARCHIVE"
+ then
+ echo plugin $1 already installed on ${CMADDR}
+ else
+ cfy plugin upload -y $2 $1
+ fi
+}
+
+### END FUNCTION DEFINTIONS ###
+
+set -ex
+
+
+# Wait for Cloudify Manager to come up
+while ! /scripts/cloudify-ready.sh
+do
+ echo "Waiting for CM to come up"
+ sleep 15
+done
+
+if [[ ! -f ${PLUGINS_LOADED} ]]
+then
+
+ # Each subdirectory of ${PLUGIN_DIR} contains a wagon (.wgn) and type file (.yaml)
+ for p in ${PLUGIN_DIR}/*
+ do
+ # Expecting exactly 1 .wgn and 1 .yaml
+ # But just in case, taking only the first of each
+ # (If either is missing, will fail on install_plugin)
+ wagons=($p/*.wgn)
+ types=($p/*.yaml)
+ install_plugin ${wagons[0]} ${types[0]}
+ done
+
+ touch ${PLUGINS_LOADED}
+else
+ echo "Plugins already loaded"
+fi \ No newline at end of file