summaryrefslogtreecommitdiffstats
path: root/deploy/aws/oom_cluster_host_install.sh
blob: bee4bef66fd4f34a9b791eab086955803b2c6aa1 (plain)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash
#############################################################################
#
# Copyright © 2018 Amdocs.
#
# 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.
#
#############################################################################
# v20180815
# Amazon AWS specific EFS/NFS share and rancher host join script for each cluster node
# https://wiki.onap.org/display/DW/Cloud+Native+Deployment
# source from https://jira.onap.org/browse/OOM-320
# Michael O'Brien

usage() {
cat <<EOF
Usage: $0 [PARAMs]
example
 master
 sudo ./cluster.sh -n false -s cl.onap.info -e fs-00c0f00 -r us-east-2
 clients
 sudo ./cluster.sh -n true -s cl.onap.info -e fs-00c0f00 -r us-east-2 -t 23D4:15:qQ -c false -a host1.onap.info -v true
 sudo ./oom_cluster_host_install.sh -n true -s cd.onap.cloud -e 1 -r us-east-2 -t token -c false -a 104.209.158.156 -v true
Prereq:
  You must create an EFS (NFS wrapper) on AWS

-u                      : Display usage
-n [true|false]         : is node (non master)
-s [master server]      : target server (ip or FQDN only)
-e [AWS efs id]         : AWS Elastic File System ID prefix
-r [AWS region prefix]  : AWS Region prefix
-t [token]              : registration token
-h [agent ver]          : agent version (default 1.2.10 for 1.6.18
-c [true/false]         : use computed client address
-a [IP address]         : client address ip - no FQDN
-v [validate true/false]: optional
EOF
}

register_node() {
    #constants
    DOCKERDATA_NFS=dockerdata-nfs
    DOCKER_VER=17.03
    USERNAME=ubuntu
    PORT=8880

    if [[ "$IS_NODE" != false ]]; then
        sudo curl https://releases.rancher.com/install-docker/$DOCKER_VER.sh | sh
        sudo usermod -aG docker $USERNAME
    fi
    sudo apt-get install nfs-common -y
    sudo mkdir /$DOCKERDATA_NFS
    sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 $AWS_EFS.efs.$AWS_REGION.amazonaws.com:/ /$DOCKERDATA_NFS
    if [[ "$IS_NODE" != false ]]; then
        echo "Running agent docker..."
        if [[ "$COMPUTEADDRESS" != false ]]; then
            echo "sudo docker run --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v$AGENT_VER http://$MASTER:$PORT/v1/scripts/$TOKEN"
            sudo docker run --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v$AGENT_VER http://$MASTER:$PORT/v1/scripts/$TOKEN
        else
            echo "sudo docker run -e CATTLE_AGENT_IP=\"$ADDRESS\" --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v$AGENT_VER http://$MASTER:$PORT/v1/scripts/$TOKEN"
            sudo docker run -e CATTLE_AGENT_IP="$ADDRESS" --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v$AGENT_VER http://$MASTER:$PORT/v1/scripts/$TOKEN
        fi
    fi
}

IS_NODE=false
MASTER=
TOKEN=
AWS_REGION=
AWS_EFS=
AGENT_VER=1.2.10
COMPUTEADDRESS=true
ADDRESS=
VALIDATE=
while getopts ":u:n:s:e:r:t:h:c:a:v" PARAM; do
  case $PARAM in
    u)
      usage
      exit 1
      ;;
    n)
      IS_NODE=${OPTARG}
      ;;
    s)
      MASTER=${OPTARG}
      ;;
    e)
      AWS_EFS=${OPTARG}
      ;;
    r)
      AWS_REGION=${OPTARG}
      ;;
    t)
      TOKEN=${OPTARG}
      ;;
    h)
      AGENT_VER=${OPTARG}
      ;;
    c)
      COMPUTEADDRESS=${OPTARG}
      ;;
    a)
      ADDRESS=${OPTARG}
      ;;
    v)
      VALIDATE=${OPTARG}
      ;;
    ?)
      usage
      exit
      ;;
  esac
done

if [ -z $MASTER ]; then
  usage
  exit 1
fi

register_node  $IS_NODE $MASTER $AWS_EFS $AWS_REGION $TOKEN $AGENT_VER $COMPUTEADDRESS $ADDRESS $VALIDATE
echo "check dockerdata-nfs"
sudo ls /dockerdata-nfs
echo "if you get http://$MASTER:8880/v1 is not accessible (The requested URL returned error: 404 Not Found) - check your token"
printf "**** Success: Done ****\n"