Configurable HTTP(S) support for VES messaging
[sim/o1-interface.git] / ntsimulator / deploy / tls / enable_netconf_call_home.sh
1 #! /bin/bash
2 ################################################################################
3 #
4 # Copyright 2020 highstreet technologies GmbH and others
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9
10 #     http://www.apache.org/licenses/LICENSE-2.0
11
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17
18 ################################################################################
19
20 sleep 20
21
22 netconf_call_home=`jq '.["netconf-call-home"]' /opt/dev/scripts/configuration.json`
23
24
25 if [ $netconf_call_home = "false" ] ; then
26    echo "NETCONF Call Home is disabled, nothing to do..."
27    exit 0
28 else
29    echo "Enabling NETCONF Call Home in device..."
30 fi
31
32 controller_ip=`jq '.["controller-details"] ."controller-ip"' /opt/dev/scripts/configuration.json`
33 controller_username=`jq '.["controller-details"] ."controller-username"' /opt/dev/scripts/configuration.json`
34 controller_password=`jq '.["controller-details"] ."controller-password"' /opt/dev/scripts/configuration.json`
35 controller_port=`jq '.["controller-details"] ."controller-port"' /opt/dev/scripts/configuration.json`
36 netconf_call_home_port=`jq '.["controller-details"] ."netconf-call-home-port"' /opt/dev/scripts/configuration.json`
37
38 SSH_PUB_KEY_MELACON="$(cat /home/netconf/.ssh/melacon.server.key.pub | awk '{print $2}')"
39
40 payload='{
41       "odl-netconf-callhome-server:device": [
42         {
43           "odl-netconf-callhome-server:unique-id": "'$HOSTNAME'",
44           "odl-netconf-callhome-server:ssh-host-key": "'$SSH_PUB_KEY_MELACON'",
45           "odl-netconf-callhome-server:credentials": {
46             "odl-netconf-callhome-server:username": "netconf",
47             "odl-netconf-callhome-server:passwords": [
48               "netconf"
49             ]
50           }
51         }
52       ]
53 }'
54
55 odl_ip=`sed -e 's/^"//' -e 's/"$//' <<<"$controller_ip"`
56 odl_username=`sed -e 's/^"//' -e 's/"$//' <<<"$controller_username"`
57 odl_password=`sed -e 's/^"//' -e 's/"$//' <<<"$controller_password"`
58
59 echo "Payload: $payload"
60
61 curl -v -H 'Content-Type: application/json' -X PUT -u $odl_username:$odl_password \
62 -d "$payload" http://$odl_ip:$controller_port/restconf/config/odl-netconf-callhome-server:netconf-callhome-server/allowed-devices/device/$HOSTNAME
63
64 echo '<netconf-server xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-server">
65         <call-home>
66           <netconf-client>
67             <name>test_ssh_ch_client</name>
68             <ssh>
69               <endpoints>
70                 <endpoint>
71                   <name>test_ssh_ch_endpt</name>
72                   <address>'$odl_ip'</address>
73                   <port>'$netconf_call_home_port'</port>
74                 </endpoint>
75               </endpoints>
76               <host-keys>
77                 <host-key>
78                   <name>melacon server key</name>
79                   <public-key>melacon_server_key</public-key>
80                 </host-key>
81               </host-keys>
82             </ssh>
83             <connection-type>
84               <persistent/>
85             </connection-type>
86           </netconf-client>
87         </call-home>
88     </netconf-server>' > connections.xml
89
90 sysrepocfg --merge=connections.xml --format=xml ietf-netconf-server
91 rm connections.xml
92
93 echo 'Done'
94 exit 0