2 # Utility Functions used by OPNFV Apex
3 # author: Tim Rozet (trozet@redhat.com)
5 SSH_OPTIONS=(-o StrictHostKeyChecking=no -o GlobalKnownHostsFile=/dev/null -o UserKnownHostsFile=/dev/null -o LogLevel=error)
7 ##connects to undercloud
8 ##params: user to login with, command to execute on undercloud (optional)
9 function undercloud_connect {
13 echo "Missing required argument: user to login as to undercloud"
18 ssh ${SSH_OPTIONS[@]} ${user}@$(get_undercloud_ip)
20 ssh ${SSH_OPTIONS[@]} -T ${user}@$(get_undercloud_ip) "$2"
24 ##outputs the Undercloud's IP address
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]+")
31 ##connects to overcloud nodes
32 ##params: node to login to, command to execute on overcloud (optional)
33 function overcloud_connect {
39 echo "Missing required argument: overcloud node to login to"
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>"
47 node_output=$(undercloud_connect "stack" "source stackrc; nova list")
48 node=$(echo "$1" | sed -E 's/([a-zA-Z]+)([0-9]+)/\1-\2/')
50 node_ip=$(echo "$node_output" | grep "$node" | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+")
52 if [ "$node_ip" == "" ]; then
53 echo -e "Unable to find IP for ${node} in \n${node_output}"
58 ssh ${SSH_OPTIONS[@]} heat-admin@${node_ip}
60 ssh ${SSH_OPTIONS[@]} -T heat-admin@${node_ip} "$2"
64 ##connects to opendaylight karaf console
66 function opendaylight_connect {
68 opendaylight_ip=$(undercloud_connect "stack" "cat overcloudrc | grep SDN_CONTROLLER_IP | grep -Eo [0-9]+\.[0-9]+\.[0-9]+\.[0-9]+")
70 if [ "$opendaylight_ip" == "" ]; then
71 echo -e "Unable to find IP for OpenDaylight in overcloudrc"
74 echo -e "Connecting to ODL Karaf console. Default password is 'karaf'"
77 ssh -p 8101 ${SSH_OPTIONS[@]} karaf@${opendaylight_ip}
80 ##outputs heat stack deployment failures
82 function debug_stack {
84 openstack stack failures list overcloud --long