Final works on vagrant voltha-base box with BUILD.md and Makefile

Change-Id: Id4b1e1a5dbc07eb15a106a5bb86967dceb978f15
diff --git a/vagrant-base/Makefile b/vagrant-base/Makefile
index ba025c6..b0c7f65 100644
--- a/vagrant-base/Makefile
+++ b/vagrant-base/Makefile
@@ -30,6 +30,48 @@
 PROTOC_DOWNLOAD_URI := $(PROTOC_DOWNLOAD_PREFIX)/v$(PROTOC_VERSION)/$(PROTOC_TARBALL)
 PROTOC_BUILD_TMP_DIR := "/tmp/protobuf-build-$(shell uname -s | tr '[:upper:]' '[:lower:]')"
 
+TOKEN_FILE := vagrant-token
+TOKEN := `cat $(TOKEN_FILE)`
+
+VAGRANT_VOLTHA_BASE_INFO="$(shell vagrant box list | grep voltha-base | tail -n 1 | cut -d ',' -f 2 | cut -d ' ' -f 2)"
+CURRENT_VERSION=`echo $(VAGRANT_VOLTHA_BASE_INFO) | cut -d ')' -f 1`
+CURRENT_VERSION_DYNAMIC=`echo $$(vagrant box list | grep voltha-base | tail -n 1 | cut -d ',' -f 2 | cut -d ' ' -f 2) | cut -d ')' -f 1`
+TIME := $(shell date +"%y%m%d.%H%M%S.0")
+VERSION := `echo $(TIME)`
+VERSION_DYNAMIC := `echo $$(date +"%y%m%d.%H%M%S.0")`
+
+default: build
+
+build: add-update-voltha-base build-core
+
+print-info:
+	@echo "TOKEN ---------------------->  "$(TOKEN)
+	@echo "TIME ----------------------->  "$(TIME)
+	@echo "VERSION -------------------->  "$(VERSION)
+	@echo "VERSION_DYNAMIC ------------>  "$(VERSION_DYNAMIC)
+	@echo "CURRENT_VERSION ------------>  "$(CURRENT_VERSION)
+	@echo "CURRENT_VERSION_DYNAMIC ---->  "$(CURRENT_VERSION_DYNAMIC)
+
+help:
+	@echo
+	@echo "Usage: make [<target>] [VERSION='X.X.X']"
+	@echo "where available targets are:"
+	@echo
+	@echo "help                 : Print this help"
+	@echo "build                : Build the Voltha-base vagrant box and upload it to Vagrant Cloud (default target)"
+	@echo "build-core           : Execute the main tasks to build theVoltha-base vagrant box and upload it to Vagrant Cloud (default target)"
+	@echo "clean                : Stop/Remove the Voltha-base virtual machine"
+	@echo "start-message        : Print Voltha-base banner"
+	@echo "update-voltha-base   : Update the Voltha-base (voltha/voltha-base) box to the latest version"
+	@echo "test-voltha-base     : Test the Voltha-base vagrant image"
+	@echo "run-voltha-base      : Run the Voltha-base (vagrant up)"
+	@echo "package-voltha-base  : Package the Voltha-base vagrant image to a .box package"
+	@echo "create-version       : Create a new version on Vagrant Cloud"
+	@echo "create-provider      : Create & assign an provider to a version on Vagrant Cloud"
+	@echo "upload-package       : Upload a package.box file to Vagrant Cloud and assign it to a version and provider"
+	@echo "release-version      : Release a verson as the available version of the Voltha-base on Vagrant Cloud"
+	@echo
+
 $(PROTOC):
 	@echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
 	@echo "It looks like you don't have protocol buffer tools installed."
@@ -50,4 +92,88 @@
 	    cd $(PROTOC_DIR); \
 	    ./configure --prefix=$(PROTOC_PREFIX); \
 	    make; \
-	    sudo make install
\ No newline at end of file
+	    sudo make install
+
+build-core: banner run-voltha-base package-voltha-base create-version create-provider upload-package release-version clean update-voltha-base
+
+add-update-voltha-base:
+	@echo "Adding/Updating voltha-base vagrant box"; \
+	vagrant box update --box voltha/voltha-base || vagrant box add voltha/voltha-base
+
+update-voltha-base:
+	@echo "Updating voltha-base vagrant box"; \
+	vagrant box update --box voltha/voltha-base
+
+add-voltha-base:
+	@echo "Adding voltha-base vagrant box"; \
+	vagrant box add voltha/voltha-base
+
+remove-voltha-base:
+	@echo "Removing all the voltha-base vagrant box versions"; \
+	vagrant box remove voltha/voltha-base --all
+
+banner:
+	@echo
+	@echo "|------------------------------------------------------------------------|"
+	@echo "|  _    ______  __  ________  ______           ____   ______ _____ ____  |"
+	@echo "| | |  / / __ \/ / /_  __/ / / / /| |         / ___ \/ ___  / ____/ ___| |"
+	@echo "| | | / / / / / /   / / / /_/ / /_| |  ___   / /__/ / /__/ / /___  /___  |"
+	@echo "| | |/ / /_/ / /___/ / / __  / ___  | |___| / /__/ / ___   \__  / /____  |"
+	@echo "| |___/\____/_____/_/ /_/ /_/_/  |__|      /______/_/  /_/\____/_______| |"
+	@echo "|                                                                        |"
+	@echo "|------------------------------------------------------------------------|"
+	@echo "|                MAKING & UPLOADING VOLTHA-BASE VAGRANT BOX              |"
+	@echo "|------------------------------------------------------------------------|"
+	@echo
+	@echo "VERSION ----> $(VERSION)"
+
+test-voltha-base:
+	@echo "Testing the recently created voltha-base"; \
+	vagrant up; \
+		./test_script.sh
+
+run-voltha-base:
+	@echo "Running voltha-base vagrant box"
+	@echo "Stopping any running voltha-base vagrant box"; \
+	vagrant halt; \
+		vagrant destroy -f; \
+		vagrant up
+
+package-voltha-base:
+	@echo "Packaging vagrant VM"
+	@echo "Removing previous package.box, if exists"; \
+	rm package.box; \
+		vagrant package
+
+create-version:
+	@echo "Creating a new version on Vagrant Cloud"
+	@echo "Version: $(VERSION)"
+	curl https://atlas.hashicorp.com/api/v1/box/voltha/voltha-base/versions \
+		-X POST -H "X-Atlas-Token: $(TOKEN)" \
+		-d version[version]=$(VERSION) \
+		-d version[description]='This is the new version' | jq
+
+create-provider:
+	@echo "Creating a provider for the new version on Vagrant Cloud"
+	@echo "We have virtualbox as provider"; \
+	curl https://atlas.hashicorp.com/api/v1/box/voltha/voltha-base/version/$(VERSION)/providers \
+		-X POST -H "X-Atlas-Token: $(TOKEN)" \
+		-d provider[name]='virtualbox' | jq
+
+upload-package:
+	@echo "Uploading the new package.box on Vagrant Cloud"; \
+	echo $(VERSION); \
+		url=$(shell curl https://atlas.hashicorp.com/api/v1/box/voltha/voltha-base/version/$(VERSION)/provider/virtualbox/upload?access_token=$(TOKEN) | jq '.["upload_path"]'); \
+			echo $$url; \
+			echo 'WAIT FOR IT....'; \
+			curl -X PUT --upload-file package.box $$url
+
+release-version:
+	@echo "Releasing the version, so the box will be accessible to all users"; \
+	curl https://atlas.hashicorp.com/api/v1/box/voltha/voltha-base/version/$(VERSION)/release \
+		-X PUT -H "X-Atlas-Token: $(TOKEN)" | jq
+
+clean:
+	@echo "Cleaning up the voltha-base vagrant image"; \
+	vagrant halt; \
+		vagrant destroy -f