Blame tests/p_bridge-utils/p_bridge-utils-functions

Pablo Greco 6c1f07
#!/bin/bash
Pablo Greco 6c1f07
Pablo Greco 6c1f07
function bru_add_bridge_7
Pablo Greco 6c1f07
{
Pablo Greco 6c1f07
  bridge=$1
Pablo Greco 6c1f07
  bridge_present=`brctl show | grep $bridge`
Pablo Greco 6c1f07
  if ! [ "$bridge_present" ]
Pablo Greco 6c1f07
    then
Pablo Greco 6c1f07
    brctl addbr $bridge 
Pablo Greco 6c1f07
    bridge_present=`brctl show | grep $bridge`
Pablo Greco 6c1f07
    if [ "$bridge_present" ]
Pablo Greco 6c1f07
    then
Pablo Greco 6c1f07
      ret_val=0
Pablo Greco 6c1f07
    else
Pablo Greco 6c1f07
      ret_val=1
Pablo Greco 6c1f07
    fi
Pablo Greco 6c1f07
  else
Pablo Greco 6c1f07
    ret_val=0
Pablo Greco 6c1f07
  fi
Pablo Greco 6c1f07
  echo $ret_val
Pablo Greco 6c1f07
}
Pablo Greco 6c1f07
function bru_add_bridge_8
Pablo Greco 6c1f07
{
Pablo Greco 6c1f07
  bridge=$1
Pablo Greco 6c1f07
  bridge_present=`cat /proc/net/dev | grep $bridge`
Pablo Greco 6c1f07
  if ! [ "$bridge_present" ]
Pablo Greco 6c1f07
  then
Pablo Greco 6c1f07
    ip link add name $bridge type bridge
Pablo Greco 6c1f07
    bridge_present=`cat /proc/net/dev | grep $bridge`
Pablo Greco 6c1f07
    if [ "$bridge_present" ]
Pablo Greco 6c1f07
    then
Pablo Greco 6c1f07
      ret_val=0
Pablo Greco 6c1f07
    else
Pablo Greco 6c1f07
      ret_val=1
Pablo Greco 6c1f07
    fi
Pablo Greco 6c1f07
  else
Pablo Greco 6c1f07
    ret_val=0
Pablo Greco 6c1f07
  fi
Pablo Greco 6c1f07
  echo $ret_val
Pablo Greco 6c1f07
}
Pablo Greco 6c1f07
Pablo Greco 6c1f07
function bru_del_bridge_7
Pablo Greco 6c1f07
{
Pablo Greco 6c1f07
  bridge=$1
Pablo Greco 6c1f07
  bridge_present=`brctl show | grep $bridge`
Pablo Greco 6c1f07
  if ! [ "$bridge_present" ]
Pablo Greco 6c1f07
  then
Pablo Greco 6c1f07
    ret_val=1
Pablo Greco 6c1f07
  else
Pablo Greco 6c1f07
    brctl delbr $bridge
Pablo Greco 6c1f07
    bridge_present=`brctl show | grep $bridge`
Pablo Greco 6c1f07
    if [ $bridge_present ]
Pablo Greco 6c1f07
    then
Pablo Greco 6c1f07
      ret_val=1
Pablo Greco 6c1f07
    else
Pablo Greco 6c1f07
      ret_val=0
Pablo Greco 6c1f07
    fi
Pablo Greco 6c1f07
  fi
Pablo Greco 6c1f07
}
Pablo Greco 6c1f07
function bru_del_bridge_8
Pablo Greco 6c1f07
{
Pablo Greco 6c1f07
  bridge=$1
Pablo Greco 6c1f07
  bridge_present=`cat /proc/net/dev | grep $bridge`
Pablo Greco 6c1f07
  if ! [ "$bridge_present" ]
Pablo Greco 6c1f07
  then
Pablo Greco 6c1f07
    ret_val=1
Pablo Greco 6c1f07
  else
Pablo Greco 6c1f07
    ip link del name $bridge
Pablo Greco 6c1f07
    bridge_present=`cat /proc/net/dev | grep $bridge`
Pablo Greco 6c1f07
    if [ $bridge_present ]
Pablo Greco 6c1f07
    then
Pablo Greco 6c1f07
      ret_val=1
Pablo Greco 6c1f07
    else
Pablo Greco 6c1f07
      ret_val=0
Pablo Greco 6c1f07
    fi
Pablo Greco 6c1f07
  fi
Pablo Greco 6c1f07
  echo $ret_val
Pablo Greco 6c1f07
}
Pablo Greco 6c1f07
Pablo Greco 6c1f07
function bru_add_bridge
Pablo Greco 6c1f07
{
Pablo Greco 6c1f07
  if [ "$centos_ver" -ge 8 ] ; then
Pablo Greco 6c1f07
    bru_add_bridge_8 $1
Pablo Greco 6c1f07
  else
Pablo Greco 6c1f07
    bru_add_bridge_7 $1
Pablo Greco 6c1f07
  fi
Pablo Greco 6c1f07
}
Pablo Greco 6c1f07
Pablo Greco 6c1f07
function bru_del_bridge
Pablo Greco 6c1f07
{
Pablo Greco 6c1f07
  if [ "$centos_ver" -ge 8 ] ; then
Pablo Greco 6c1f07
    bru_del_bridge_8 $1
Pablo Greco 6c1f07
  else
Pablo Greco 6c1f07
    bru_del_bridge_7 $1
Pablo Greco 6c1f07
  fi
Pablo Greco 6c1f07
}