-setopnfvspaces(){
- # Create spaces
- for sp in admin tenant-data public-api tenant-api tenant-public; do
- maas $PROFILE spaces create name=$sp || true
- done
-}
-
-getfabrichostingnet(){
- SUBN_CIDR=$1
- NET_FABRIC_NAME=$(maas $PROFILE subnets read | jq -r ".[] | select(.cidr==\"$SUBN_CIDR\")".vlan.fabric)
- NET_FABRIC_ID=$(maas $PROFILE fabric read $NET_FABRIC_NAME | jq -r ".id")
-}
-
-deleteexistingnetw(){
- CIDR_LIST=$(cat labconfig.json | jq --raw-output ".opnfv.spaces[]".cidr | grep -v null)
- for CIDR in $CIDR_LIST; do
- NETID=$(maas $PROFILE subnets read | jq ".[] | select(.cidr==\"$CIDR\")".id)
- maas $PROFILE subnet delete $NETID
- done
-}
-
-deleteunusednetw(){
- USED_CIDR_LIST=$(cat labconfig.json | jq --raw-output ".opnfv.spaces[]".cidr | grep -v null)
- CIDR_LIST=$(maas $PROFILE networks read | jq -r ".[].description")
- for CIDR in $CIDR_LIST; do
- if [[ $USED_CIDR_LIST != *$CIDR* ]]; then
- NETID=$(maas $PROFILE subnets read | jq ".[] | select(.cidr==\"$CIDR\")".id)
- maas $PROFILE subnet delete $NETID
- fi
- done
-}
-
-setopnfvfabrics(){
-
- # Based on first node we get the fabric mapping
- NODE_0_MAC_LIST=$(cat labconfig.json | jq --raw-output ".lab.racks[0].nodes[0].nics[] ".mac[] | sort -u)
- FAB_ID=1
- for MAC in $NODE_0_MAC_LIST; do
- # Get the spaces attached to a mac
- IF_SPACES=$(cat labconfig.json | jq --raw-output ".lab.racks[0].nodes[$NODE_ID].nics[] | select(.mac[] | contains(\"$MAC\")) ".spaces[])
- if [[ $IF_SPACES == *admin* ]]; then
- # Reuse fabric 0 to be sure the interface i hosted by the jumphost (assuming it is the first one)
- FABRIC_ID=$ADMIN_FABRIC_ID
- maas $PROFILE fabric update $FABRIC_ID name=opnfv$FAB_ID
- else
- # Create a new fabric
- FABRIC_ID=$(maas $PROFILE fabrics create name=opnfv$FAB_ID| jq --raw-output ".id")
- fi
- # Create the network attached to a space
- for SPACE in $IF_SPACES; do
- # First check if this space have a vlan
- SP_VLAN=$(cat labconfig.json | jq --raw-output ".opnfv.spaces[] | select(.type==\"$SPACE\")".vlan)
- # Create it if needed
- if ([ $SP_VLAN ] && [ "$SP_VLAN" != "null" ]); then
- maas $PROFILE vlans create $FABRIC_ID vid=$SP_VLAN
- VID=$SP_VLAN
- VID_REQ="vid=$SP_VLAN"
+setupspacenetwork(){
+ #get space, subnet and vlan and create accordingly.
+ #for type in admin osapi data storage external floating public; do
+ nettypes=`cat labconfig.json | jq '.opnfv.spaces[]'.type | cut -d \" -f 2`
+ for type in $nettypes; do
+ config_done=0
+ SPACE_CIDR=`cat labconfig.json | jq '.opnfv.spaces[] | select(.type=="'$type'")'.cidr | cut -d \" -f 2 `
+ SPACE_VLAN=`cat labconfig.json | jq '.opnfv.spaces[] | select(.type=="'$type'")'.vlan | cut -d \" -f 2 `
+ SPACE_GWAY=`cat labconfig.json | jq '.opnfv.spaces[] | select(.type=="'$type'")'.gateway | cut -d \" -f 2 `
+ NET_FABRIC_NAME=$(maas $PROFILE subnets read | jq -r ".[] | select(.cidr==\"$SPACE_CIDR\")".vlan.fabric)
+ if ([ $NET_FABRIC_NAME ] && [ $NET_FABRIC_NAME != "null" ]); then
+ NET_FABRIC_VID=$(maas $PROFILE subnets read | jq -r ".[] | select(.cidr==\"$SPACE_CIDR\")".vlan.vid)
+ NET_FABRIC_ID=$(maas $PROFILE fabric read $NET_FABRIC_NAME | jq -r ".id")
+ if ([ $SPACE_VLAN == "null" ]); then
+ SPACE_VLAN=0
+ fi
+ NET_VLAN_ID=$(maas $PROFILE vlans read $NET_FABRIC_ID | jq -r ".[] | select(.vid==\"$SPACE_VLAN\")".id)
+ NET_VLAN_VID=$(maas $PROFILE vlans read $NET_FABRIC_ID | jq -r ".[] | select(.vid==\"$SPACE_VLAN\")".vid)
+ if ([ $SPACE_GWAY ] && [ "$SPACE_GWAY" != "null" ]); then
+ maas $PROFILE subnet update $SPACE_CIDR gateway_ip=$SPACE_GWAY || true
+ fi
+ if ([ $NET_VLAN_VID ] && [ $NET_VLAN_VID == "0" ]); then
+ config_done=1
+ elif ([ $NET_VLAN_VID ] && [ $NET_VLAN_VID == $SPACE_VLAN ]); then
+ config_done=1