Bumps OVS version to 2.8 for OVN
[apex.git] / lib / utility-functions.sh
1 #!/usr/bin/env bash
2 # Utility Functions used by  OPNFV Apex
3 # author: Tim Rozet (trozet@redhat.com)
4
5 SSH_OPTIONS=(-o StrictHostKeyChecking=no -o GlobalKnownHostsFile=/dev/null -o UserKnownHostsFile=/dev/null -o LogLevel=error)
6
7 ##connects to undercloud
8 ##params: user to login with, command to execute on undercloud (optional)
9 function undercloud_connect {
10   local user=$1
11
12   if [ -z "$1" ]; then
13     echo "Missing required argument: user to login as to undercloud"
14     return 1
15   fi
16
17   if [ -z "$2" ]; then
18     ssh ${SSH_OPTIONS[@]} ${user}@$(get_undercloud_ip)
19   else
20     ssh ${SSH_OPTIONS[@]} -T ${user}@$(get_undercloud_ip) "$2"
21   fi
22 }
23
24 ##outputs the Undercloud's IP address
25 ##params: none
26 function get_undercloud_ip {
27   echo $(arp -an | grep $(virsh domiflist undercloud | grep default |\
28     awk '{print $5}') | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+")
29 }
30
31 ##connects to overcloud nodes
32 ##params: node to login to, command to execute on overcloud (optional)
33 function overcloud_connect {
34   local node
35   local node_output
36   local node_ip
37
38   if [ -z "$1" ]; then
39     echo "Missing required argument: overcloud node to login to"
40     return 1
41   elif ! echo "$1" | grep -E "(controller|compute)[0-9]+" > /dev/null; then
42     echo "Invalid argument: overcloud node to login to must be in the format: \
43 controller<number> or compute<number>"
44     return 1
45   fi
46
47   node_output=$(undercloud_connect "stack" "source stackrc; nova list")
48   node=$(echo "$1" | sed -E 's/([a-zA-Z]+)([0-9]+)/\1-\2/')
49
50   node_ip=$(echo "$node_output" | grep "$node" | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+")
51
52   if [ "$node_ip" == "" ]; then
53     echo -e "Unable to find IP for ${node} in \n${node_output}"
54     return 1
55   fi
56
57   if [ -z "$2" ]; then
58     ssh ${SSH_OPTIONS[@]} heat-admin@${node_ip}
59   else
60     ssh ${SSH_OPTIONS[@]} -T heat-admin@${node_ip} "$2"
61   fi
62 }
63
64 ##connects to opendaylight karaf console
65 ##params: None
66 function opendaylight_connect {
67   local opendaylight_ip
68   opendaylight_ip=$(undercloud_connect "stack" "cat overcloudrc | grep SDN_CONTROLLER_IP | grep -Eo [0-9]+\.[0-9]+\.[0-9]+\.[0-9]+")
69
70   if [ "$opendaylight_ip" == "" ]; then
71     echo -e "Unable to find IP for OpenDaylight in overcloudrc"
72     return 1
73   else
74     echo -e "Connecting to ODL Karaf console.  Default password is 'karaf'"
75   fi
76
77   ssh -p 8101 ${SSH_OPTIONS[@]} karaf@${opendaylight_ip}
78 }
79
80 ##outputs heat stack deployment failures
81 ##params: none
82 function debug_stack {
83   source ~/stackrc
84   openstack stack failures list overcloud --long
85 }