This repository has been archived by the owner on Mar 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mount-remote-folder.sh
59 lines (53 loc) · 1.85 KB
/
mount-remote-folder.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#! /bin/bash
if [ $# -ne 10 ] ; then
echo "Usage: $0 hosterUrl appId login password targetEnvName targetNodeGroup targetPath sourceEnvName sourceNodeGroup sourcePath"
echo "targetEnvName: shopozor-ci"
echo "targetNodeGroup: cp"
echo "targetPath: /mnt"
echo "sourceEnvName: shopozor-management-frontend-e2e"
echo "sourceNodeGroup: cp"
echo "sourcePath: /home/node/reports"
exit 0
fi
. helpers.sh
HOSTER_URL=$1
APPID=$2
SESSION=$(getSession $3 $4 ${HOSTER_URL})
TARGET_ENV_NAME=$5
TARGET_NODE_GROUP=$6
TARGET_PATH=$7
SOURCE_ENV_NAME=$8
SOURCE_NODE_GROUP=$9
SOURCE_PATH=${10}
getSourceNodeId() {
local session=$1
local envName=$2
local nodeGroup=$3
echo "Getting info about environment <$envName>..." >&2
local cmd=$(curl -k \
-H "${CONTENT_TYPE}" \
-A "${USER_AGENT}" \
-X POST \
-fsS ${HOSTER_URL}/1.0/environment/control/rest/getenvinfo -d "envName=${envName}&session=${session}")
echo "Got info about environment <$envName>" >&2
echo $(echo $cmd | jq ".nodes[] | select(.nodeGroup == \"${nodeGroup}\") | .id")
}
mountRemoteFolder() {
# mounts sourceNodeId:/home/node/reports on targetEnvName:$targetPath
local session=$1
local targetEnvName=$2
local targetNodeGroup=$3
local targetPath=$4
local sourcePath=$5
local readOnly="true"
local sourceNodeId=$(getSourceNodeId $SESSION ${SOURCE_ENV_NAME} ${SOURCE_NODE_GROUP})
echo "Mounting remote folder..." >&2
curl -k \
-H "${CONTENT_TYPE}" \
-A "${USER_AGENT}" \
-X POST \
-fsS ${HOSTER_URL}/1.0/environment/file/rest/addmountpointbygroup -d "protocol=nfs&path=${targetPath}&envName=${targetEnvName}&session=${session}&sourceNodeId=${sourceNodeId}&readOnly=${readOnly}&nodeGroup=${targetNodeGroup}&sourcePath=${sourcePath}"
echo "Remote folder mounted" >&2
exit 0
}
mountRemoteFolder $SESSION $TARGET_ENV_NAME $TARGET_NODE_GROUP $TARGET_PATH $SOURCE_PATH