Skip to content

Commit

Permalink
Tidy up some switch code and set as 1.2-beta2
Browse files Browse the repository at this point in the history
  • Loading branch information
churchers committed Jun 29, 2018
1 parent b87d207 commit 851e2eb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
20 changes: 9 additions & 11 deletions lib/vm-switch-standard
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ switch::standard::init(){
local _id _addr _mtu

# see if it already exists
switch::standard::id "_id" "${_name}" && return 0
switch::find "_id" "${_name}" && return 0

# create a bridge for this switch
_id=$(ifconfig bridge create descr "vm-${_name}" group vm-switch up 2>/dev/null)
Expand Down Expand Up @@ -104,8 +104,7 @@ switch::standard::remove(){
local _id

# get the bridge id
switch::standard::id "_id" "${_switch}"
[ $? -eq 0 ] || return 1
switch::find "_id" "${_switch}" || return 1

# remove all member interfaces
switch::standard::__remove_members "${_switch}" "${_id}"
Expand All @@ -124,7 +123,7 @@ switch::standard::add_member(){
local _if="$2"
local _id _vlan _mtu

switch::standard::id "_id" "${_switch}" || util::err "unable to locate switch id"
switch::find "_id" "${_switch}" || util::err "unable to locate switch id"
config::core::get "_vlan" "vlan_${_switch}"
config::core::get "_mtu" "mtu_${_switch}"
switch::standard::__configure_port "${_switch}" "${_id}" "${_if}" "${_vlan}" "${_mtu}"
Expand All @@ -141,7 +140,7 @@ switch::standard::remove_member(){
local _if="$2"
local _id _vlan

switch::standard::id "_id" "${_switch}" || util::err "unable to locate switch id"
switch::find "_id" "${_switch}" || util::err "unable to locate switch id"
config::core::remove "ports_${_switch}" "${_if}"
config::core::get "_vlan" "vlan_${_switch}"
switch::standard::__unconfigure_port "${_switch}" "${_id}" "${_if}" "${_vlan}"
Expand All @@ -157,7 +156,7 @@ switch::standard::vlan(){
local _vlan="$2"
local _id

switch::standard::id "_id" "${_switch}" || util::err "unable to locate switch id"
switch::find "_id" "${_switch}" || util::err "unable to locate switch id"
switch::standard::__remove_members "${_switch}" "${_id}"

# update configuration
Expand Down Expand Up @@ -208,7 +207,7 @@ switch::standard::__add_members(){

# get the id if not provided
if [ -z "${_id}" ]; then
switch::standard::id "_id" "${_switch}" || util:err "failed to get switch id while adding members"
switch::find "_id" "${_switch}" || util:err "failed to get switch id while adding members"
fi

config::core::get "_ports" "ports_${_switch}"
Expand All @@ -234,8 +233,7 @@ switch::standard::__remove_members(){

# get id if not given to us
if [ -z "${_id}" ]; then
switch::standard::id "_id" "${_switch}"
[ $? -eq 0 ] || util::err "failed to get switch id while removing members"
switch::find "_id" "${_switch}" || util::err "failed to get switch id while removing members"
fi

# get full port list
Expand Down Expand Up @@ -273,7 +271,7 @@ switch::standard::__configure_port(){

# see if vlan interface already exists
_vname="${_port}.${_vlan}"
switch::standard::id "_viface" "${_vname}"
switch::find "_viface" "${_vname}"

# create if needed
if [ $? -ne 0 ]; then
Expand Down Expand Up @@ -310,7 +308,7 @@ switch::standard::__unconfigure_port(){

if [ -n "${_vlan}" ]; then
# get vlan interface
switch::standard::id "_vid" "${_port}.${_vlan}"
switch::find "_vid" "${_port}.${_vlan}"

# remove the vlan interface, it will be removed from bridge automatically
[ $? -eq 0 ] && ifconfig ${_vid} destroy >/dev/null 2>&1
Expand Down
6 changes: 3 additions & 3 deletions lib/vm-switch-vxlan
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ switch::vxlan::init(){
local _id _vlan _if _maddr _addr

# see if the bridge already exists
switch::standard::id "_id" "${_name}" && return 0
switch::find "_id" "${_name}" && return 0

# need a vlan id and interface
config::core::get "_vlan" "vlan_${_name}"
Expand Down Expand Up @@ -82,7 +82,7 @@ switch::vxlan::show(){
local _format="$2"
local _id _vlan _port _addr _priv

switch::standard::id "_id" "${_name}"
switch::find "_id" "${_name}"
config::core::get "_vlan" "vlan_${_name}"
config::core::get "_port" "ports_${_name}"
config::core::get "_addr" "addr_${_name}"
Expand Down Expand Up @@ -120,7 +120,7 @@ switch::vxlan::remove(){
local _id _vlan _maddr

# try to get guest bridge and vxlan id
switch::standard::id "_id" "${_switch}"
switch::find "_id" "${_switch}"
[ $? -eq 0 ] || return 1

config::core::get "_vlan" "vlan_${_switch}"
Expand Down
4 changes: 2 additions & 2 deletions vm
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

VERSION=1.2-beta1
VERSION_INT=102068
VERSION=1.2-beta2
VERSION_INT=102069
VERSION_BSD=$(uname -K)
PATH=${PATH}:/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin

Expand Down

0 comments on commit 851e2eb

Please sign in to comment.