X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?p=sim%2Fo1-interface.git;a=blobdiff_plain;f=ntsimulator%2Fscripts%2Fclean.sh;h=5d21e4c936bb216f6e97b051c4484d898e2c52cf;hp=2d9bd569f811a1178939ca12bda944dba910c0f6;hb=1f1479ff8ce3a268acb7b70a32bb789d859a915b;hpb=34ec819462d5f81ceeb723e47467bf50a8454f34 diff --git a/ntsimulator/scripts/clean.sh b/ntsimulator/scripts/clean.sh index 2d9bd56..5d21e4c 100755 --- a/ntsimulator/scripts/clean.sh +++ b/ntsimulator/scripts/clean.sh @@ -15,34 +15,74 @@ # See the License for the specific language governing permissions and # limitations under the License. ################################################################################ + if [ "$#" -ne 1 ]; then echo "ID Parameter missing." - echo "Usage: $0 id + echo "Usage: $0 id/all -where id is the docker container id of the NTS Manager instance that we want to clean. " +where id is the docker container id of the NTS Manager instance that we want to clean. Use 'all' if you want to clean all containers and all managers." exit 1 fi -echo "Cleaning up containers started by the NTS Manager $1..." +if [ "$1" = "all" ]; then + echo "Cleaning up all NTS simulated devices..." -mapfile -t NTS_containers < <( docker ps -a --filter "label=NTS_Manager=$1" --format "{{.ID}}" ) + mapfile -t NTS_containers < <( docker ps -a --filter "label=NTS_Manager" --format "{{.ID}}" ) -CONTAINERS="" + CONTAINERS="" -if [ ${#NTS_containers[@]} -gt 0 ] -then + if [ ${#NTS_containers[@]} -gt 0 ] + then - for container in "${NTS_containers[@]}" - do - CONTAINERS="$CONTAINERS $container" - done - echo "Cleaning up containers: $CONTAINERS" - docker kill $CONTAINERS > /dev/null 2>&1 - docker rm $CONTAINERS > /dev/null 2>&1 -fi + for container in "${NTS_containers[@]}" + do + CONTAINERS="$CONTAINERS $container" + done + echo "Cleaning up containers: $CONTAINERS" + docker kill $CONTAINERS > /dev/null 2>&1 + docker rm $CONTAINERS > /dev/null 2>&1 + fi + + echo "Cleaning up all NTS Managers..." + + mapfile -t NTS_containers < <( docker ps -a --filter "label=NTS-manager" --format "{{.ID}}" ) + + CONTAINERS="" + + if [ ${#NTS_containers[@]} -gt 0 ] + then + + for container in "${NTS_containers[@]}" + do + CONTAINERS="$CONTAINERS $container" + done + echo "Cleaning up containers: $CONTAINERS" + docker kill $CONTAINERS > /dev/null 2>&1 + docker rm $CONTAINERS > /dev/null 2>&1 + fi -echo "Cleaning NTS Manager $1..." -docker kill $1 > /dev/null 2>&1 -docker rm $1 > /dev/null 2>&1 +else + echo "Cleaning up containers started by the NTS Manager $1..." + + mapfile -t NTS_containers < <( docker ps -a --filter "label=NTS_Manager=$1" --format "{{.ID}}" ) + + CONTAINERS="" + + if [ ${#NTS_containers[@]} -gt 0 ] + then + + for container in "${NTS_containers[@]}" + do + CONTAINERS="$CONTAINERS $container" + done + echo "Cleaning up containers: $CONTAINERS" + docker kill $CONTAINERS > /dev/null 2>&1 + docker rm $CONTAINERS > /dev/null 2>&1 + fi + + echo "Cleaning NTS Manager $1..." + docker kill $1 > /dev/null 2>&1 + docker rm $1 > /dev/null 2>&1 +fi echo "All cleaned up!"