summaryrefslogtreecommitdiffstats
path: root/ms/gra/gra-docker/src/main/scripts/graToMdsal.sh
blob: 7d22bf5f18837a298561517c035b0e92a5c8e82e (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
#!/bin/bash

# Copies data from GRA microservice and stores in MDSAL in ODL

TMPNAME=gra-mdsal-$$

if [ $# -eq 2 ]
then
    fetchFile=false
    GRA_EXPORT_FILE=$1
    MDSAL_URL=$2
elif [ $# -eq 3 ]
then
    fetchFile=true
    GRA_EXPORT_FILE=$TMPNAME.tar.gz
    GRA_NAMESPACE=$1
    GRA_GRA_POD=$2
    MDSAL_URL=$3
else
    echo "Usage: $0 {export-file-name | nft-namespace gra-pod-name} eom-url"
    exit 1
fi


# Check credentials configuration
if [ -z "$GRA_USER" ]
then
    echo "Error: GRA_USER must be set/exported"
    exit 1
fi

if [ -z "$GRA_PASSWORD" ]
then
    echo "Error: GRA_PASSWORD must be set/exported"
    exit 1
fi

if [ -z "$MDSAL_USER" ]
then
    echo "Error: MDSAL_USER must be set/exported"
    exit 1
fi

if [ -z "$MDSAL_PASSWORD" ]
then
    echo "Error: MDSAL_PASSWORD must be set/exported"
    exit 1
fi

set -e

TMPNAME=gra-mdsal-$$
mkdir /tmp/$TMPNAME

if [ "$fetchFile" = "true" ]
then
    # Export data on Azure
    kubectl -n $GRA_NAMESPACE exec -ti $GRA_GRA_POD -c gra -- env ODL_USER=$GRA_USER AAF_MECHID_CRED=$GRA_PASSWORD /opt/sdnc/gra/bin/exportGraDaexim.sh /tmp/$GRA_EXPORT_FILE


    # Put exported data to NFT EOM
    kubectl -n $GRA_NAMESPACE cp $GRA_GRA_POD:/tmp/$GRA_EXPORT_FILE /tmp/$TMPNAME/$GRA_EXPORT_FILE
else
    cp $GRA_EXPORT_FILE /tmp/$TMPNAME
fi

cd /tmp/$TMPNAME
tar xzf $GRA_EXPORT_FILE

# Massage files and create daexim input
echo "{" > lsc_backup_config_$TMPNAME.json
addComma=false
if [ -f services_config.json ]
then
    echo "Converting service data ..."
    cat services_config.json | python3 -mjson.tool | sed -e "s/services/GENERIC-RESOURCE-API:services/" -e "/\"gateway-address\": \"\"/d"  > services_config_upd.json
    cat services_config_upd.json | sed -e "1s/{//" -e "$ s/}//" >> lsc_backup_config_$TMPNAME.json
    addComma=true
fi

if [ -f contrail_config.json ]
then
    if [ "$addComma" = "true" ]
    then
        echo "," >> lsc_backup_config_$TMPNAME.json
    fi
    cat contrail_config.json | sed -e "s/{//" -e "s/contrail-route-allotted-resources/GENERIC-RESOURCE-API:contrail-route-allotted-resources/" -e "s/}$//" >> lsc_backup_config_$TMPNAME.json
    addComma=true
fi

if [ -f portmirror_config.json ]
then
    if [ "$addComma" = "true" ]
    then
        echo "," >> lsc_backup_config_$TMPNAME.json
    fi
    cat portmirror_config.json | sed -e "s/{//" -e "s/port-mirror-configurations/GENERIC-RESOURCE-API:port-mirror-configurations/" -e "s/}$//" >> lsc_backup_config_$TMPNAME.json
    addComma=true
fi

echo "}" >> lsc_backup_config_$TMPNAME.json

echo "Exported data files are in /tmp/$TMPNAME"

if [ -f services_config_upd.json ]
then
    echo "Importing service data ..."
    curl -k -v -u${MDSAL_USER}:${MDSAL_PASSWORD} -H "Content-Type: application/json" -X PUT -d@services_config_upd.json ${MDSAL_URL}/restconf/config/GENERIC-RESOURCE-API:services/
fi

if [ -f contrail_config.json ]
then
    echo "Importing contrail data ..."
    curl -k -v -u${MDSAL_USER}:${MDSAL_PASSWORD} -H "Content-Type: application/json" -X PUT -d@contrail_config.json ${MDSAL_URL}/restconf/config/GENERIC-RESOURCE-API:contrail-route-allotted-resources/
fi

if [ -f portmirror_config.json ]
then
    echo "Importing port mirror data ..."
    curl -k -v -u${MDSAL_USER}:${MDSAL_PASSWORD} -H "Content-Type: application/json" -X PUT -d@portmirror_config.json ${MDSAL_URL}/restconf/config/GENERIC-RESOURCE-API:port-mirror-configurations/
fi