modify the file to revise the gateway_ip and cidr of orange pod2 for onos.
[joid.git] / ci / onos / juju_test_prepare.sh
1 #!/bin/bash
2
3 # launch eth on computer nodes and remove default gw route
4 # Update gateway mac to onos for l3 function
5
6 # author: York(Yuanyou)
7 # set the gateway ip and cidr and compute-node eth name.
8 case "$1" in
9     'orangepod2' )
10        GW_IP=161.105.231.1
11        CIDR=161.105.231.0/24
12        COMPUTE_ETH=eth1
13         ;;
14      'intelpod6' )
15        GW_IP=10.2.66.1
16        CIDR=10.2.66.0/24
17        COMPUTE_ETH=eth2
18         ;;
19      'intelpod5' )
20        GW_IP=10.2.65.1
21        CIDR=10.2.65.0/24
22        COMPUTE_ETH=eth2.724
23         ;;
24      'attvirpod1' )
25        GW_IP=10.10.15.1
26        CIDR=10.10.15.0/24
27        COMPUTE_ETH=eth1
28         ;;
29      'default' )
30        GW_IP=192.168.122.1
31        CIDR=192.168.122.0/24
32        COMPUTE_ETH=eth1
33         ;;
34      * )
35        GW_IP=192.168.122.1
36        CIDR=192.168.122.0/24
37        COMPUTE_ETH=eth1
38         ;;
39 esac
40
41 # launch eth on computer nodes and remove default gw route
42 launch_eth() {
43   computer_list=$(juju status --format short | grep -Eo 'nodes-compute/[0-9]')
44   for node in $computer_list; do
45     echo "node name is ${node}"
46     juju ssh $node "sudo ifconfig $COMPUTE_ETH up"
47     juju ssh $node "sudo route del default gw $GW_IP"
48   done
49 }
50
51 # create external network and subnet in openstack
52 create_ext_network() {
53   keystoneIp=$(juju status --format short | grep keystone/0 | grep -v ha | grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}')
54   configOpenrc admin openstack admin http://$keystoneIp:5000/v2.0 Canonical
55   juju scp ./admin-openrc nova-cloud-controller/0:
56   juju ssh nova-cloud-controller/0 "source admin-openrc;neutron net-create ext-net --shared --router:external=True;neutron subnet-create ext-net --name ext-subnet $CIDR"
57 }
58
59 configOpenrc()
60 {
61     echo  "  " > ./admin-openrc
62     echo  "export OS_USERNAME=$1" >> ./admin-openrc
63     echo  "export OS_PASSWORD=$2" >> ./admin-openrc
64     echo  "export OS_TENANT_NAME=$3" >> ./admin-openrc
65     echo  "export OS_AUTH_URL=$4" >> ./admin-openrc
66     echo  "export OS_REGION_NAME=$5" >> ./admin-openrc
67  }
68
69 # Update gateway mac to onos for l3 function
70 update_gw_mac() {
71   ## get gateway mac
72   GW_MAC=$(juju ssh nova-compute/0 "arp -a ${GW_IP} | grep -Eo '([0-9a-fA-F]{2})(([/\s:-][0-9a-fA-F]{2}){5})'")
73   ## set external gateway mac in onos
74   juju set onos-controller gateway-mac=$GW_MAC
75
76 }
77
78 main() {
79   launch_eth
80   create_ext_network
81   update_gw_mac
82 }
83
84 main "$@"