-enablesubnetanddhcp(){
- TEMP_CIDR=$1
- enabledhcp=$2
- space=$3
-
- SUBNET_PREFIX=${TEMP_CIDR::-5}
-
- IP_RES_RANGE_LOW="$SUBNET_PREFIX.1"
- IP_RES_RANGE_HIGH="$SUBNET_PREFIX.39"
-
- API_KEY=`sudo maas-region apikey --username=ubuntu`
- maas login $PROFILE $API_SERVERMAAS $API_KEY
-
- maas $PROFILE ipranges create type=reserved \
- start_ip=$IP_RES_RANGE_LOW end_ip=$IP_RES_RANGE_HIGH \
- comment='This is a reserved range' || true
-
- IP_DYNAMIC_RANGE_LOW="$SUBNET_PREFIX.40"
- IP_DYNAMIC_RANGE_HIGH="$SUBNET_PREFIX.150"
-
- maas $PROFILE ipranges create type=dynamic \
- start_ip=$IP_DYNAMIC_RANGE_LOW end_ip=$IP_DYNAMIC_RANGE_HIGH \
- comment='This is a reserved dynamic range' || true
-
- FABRIC_ID=$(maas $PROFILE subnet read $TEMP_CIDR | jq '.vlan.fabric_id')
-
- PRIMARY_RACK_CONTROLLER=$(maas $PROFILE rack-controllers read | jq -r '.[0].system_id')
-
- if [ "$space" == "admin" ]; then
- MY_GATEWAY=`cat labconfig.json | jq '.opnfv.spaces[] | select(.type=="admin")'.gateway | cut -d \" -f 2 `
- #MY_NAMESERVER=`cat deployconfig.json | jq '.opnfv.upstream_dns' | cut -d \" -f 2`
- if ([ $MY_GATEWAY ] && [ "$MY_GATEWAY" != "null" ]); then
- maas $PROFILE subnet update $TEMP_CIDR gateway_ip=$MY_GATEWAY || true
- fi
- #maas $PROFILE subnet update $TEMP_CIDR dns_servers=$MY_NAMESERVER || true
- #below command will enable the interface with internal-api space.
- SPACEID=$(maas $PROFILE space read internal-api | jq '.id')
- maas $PROFILE subnet update $TEMP_CIDR space=$SPACEID || true
- if [ "$enabledhcp" == "true" ]; then
- maas $PROFILE vlan update $FABRIC_ID $VLAN_TAG dhcp_on=True primary_rack=$PRIMARY_RACK_CONTROLLER || true
- fi
- elif [ "$space" == "data" ]; then
- MY_GATEWAY=`cat labconfig.json | jq '.opnfv.spaces[] | select(.type=="data")'.gateway | cut -d \" -f 2 `
- if ([ $MY_GATEWAY ] && [ "$MY_GATEWAY" != "null" ]); then
- maas $PROFILE subnet update $TEMP_CIDR gateway_ip=$MY_GATEWAY || true
- fi
- #below command will enable the interface with data-api space for data network.
- SPACEID=$(maas $PROFILE space read admin-api | jq '.id')
- maas $PROFILE subnet update $TEMP_CIDR space=$SPACEID || true
- if [ "$enabledhcp" == "true" ]; then
- maas $PROFILE vlan update $FABRIC_ID $VLAN_TAG dhcp_on=True primary_rack=$PRIMARY_RACK_CONTROLLER || true
- fi
- elif [ "$space" == "public" ]; then
- MY_GATEWAY=`cat labconfig.json | jq '.opnfv.spaces[] | select(.type=="data")'.public | cut -d \" -f 2 `
- if ([ $MY_GATEWAY ] && [ "$MY_GATEWAY" != "null" ]); then
- maas $PROFILE subnet update $TEMP_CIDR gateway_ip=$MY_GATEWAY || true
- fi
- #below command will enable the interface with public-api space for data network.
- SPACEID=$(maas $PROFILE space read public-api | jq '.id')
- maas $PROFILE subnet update $TEMP_CIDR space=$SPACEID || true
- if [ "$enabledhcp" == "true" ]; then
- maas $PROFILE vlan update $FABRIC_ID $VLAN_TAG dhcp_on=True primary_rack=$PRIMARY_RACK_CONTROLLER || true
+setupspacenetwork(){
+
+ #get space, subnet and vlan and create accordingly.
+ #for type in admin 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
+ 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
+ else
+ NET_VLAN_ID=$(maas $PROFILE vlans create $NET_FABRIC_ID vid=$SPACE_VLAN | jq --raw-output ".id")
+ if ([ $NET_VLAN_ID ] && [ $NET_VLAN_ID != "null" ]); then
+ maas $PROFILE subnet update $SPACE_CIDR vlan=$NET_VLAN_ID
+ NET_FABRIC_VID=$SPACE_VLAN
+ fi
+ fi
+ else
+ if ([ $SPACE_CIDR ] && [ "$SPACE_CIDR" != "null" ]); then
+ FABRIC_ID=$(maas $PROFILE fabrics create name=opnfv$type | jq --raw-output ".id")
+ NET_FABRIC_ID=$FABRIC_ID
+ NET_FABRIC_VID=$SPACE_VLAN
+ if ([ $SPACE_VLAN ] && [ "$SPACE_VLAN" != "null" ]); then
+ NET_VLAN_ID=$(maas $PROFILE vlans create $FABRIC_ID vid=$SPACE_VLAN | jq --raw-output ".id")
+ if ([ $SPACE_GWAY ] && [ "$SPACE_GWAY" != "null" ]); then
+ maas $PROFILE subnets create fabric=$FABRIC_ID cidr=$SPACE_CIDR vid=$VID_ID gateway_ip=$SPACE_GWAY
+ else
+ maas $PROFILE subnets create fabric=$FABRIC_ID cidr=$SPACE_CIDR vid=$VID_ID
+ fi
+ NET_FABRIC_VID=$VLAN_ID
+ else
+ if ([ $SPACE_GWAY ] && [ "$SPACE_GWAY" != "null" ]); then
+ maas $PROFILE subnets create fabric=$FABRIC_ID cidr=$SPACE_CIDR vid="0" gateway_ip=$SPACE_GWAY
+ else
+ maas $PROFILE subnets create fabric=$FABRIC_ID cidr=$SPACE_CIDR vid="0"
+ fi
+ fi
+ NET_FABRIC_NAME=$(maas $PROFILE subnets read | jq -r ".[] | select(.cidr==\"$SPACE_CIDR\")".vlan.fabric)
+ fi