diff options
author | Kiran Kamineni <kiran.k.kamineni@intel.com> | 2019-03-28 12:53:13 -0700 |
---|---|---|
committer | Kiran Kamineni <kiran.k.kamineni@intel.com> | 2019-04-03 15:31:31 -0700 |
commit | f74ad24c6034294c1915f5778adb259dd65c9208 (patch) | |
tree | 03cf8ba86d1f966b9a342b325bd2fb36bf1dcc59 /src/k8splugin/api/api.go | |
parent | e97d3fddc255b73f87a8b3dbd8fa505e34247504 (diff) |
Refactor instance code
Issue-ID: MULTICLOUD-350
Change-Id: I2574d94e4ebada1e138913b2a03549dd90906d7b
Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
Diffstat (limited to 'src/k8splugin/api/api.go')
-rw-r--r-- | src/k8splugin/api/api.go | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/src/k8splugin/api/api.go b/src/k8splugin/api/api.go index 2862a999..54147d2e 100644 --- a/src/k8splugin/api/api.go +++ b/src/k8splugin/api/api.go @@ -14,21 +14,30 @@ limitations under the License. package api import ( + "k8splugin/internal/app" "k8splugin/internal/rb" "github.com/gorilla/mux" ) -// NewRouter creates a router instance that serves the VNFInstance web methods -func NewRouter(kubeconfig string, defClient rb.DefinitionManager, - profileClient rb.ProfileManager) *mux.Router { +// NewRouter creates a router that registers the various urls that are supported +func NewRouter(defClient rb.DefinitionManager, + profileClient rb.ProfileManager, + instClient app.InstanceManager) *mux.Router { + router := mux.NewRouter() - vnfInstanceHandler := router.PathPrefix("/v1/vnf_instances").Subrouter() - vnfInstanceHandler.HandleFunc("/", CreateHandler).Methods("POST").Name("VNFCreation") - vnfInstanceHandler.HandleFunc("/{cloudRegionID}/{namespace}", ListHandler).Methods("GET") - vnfInstanceHandler.HandleFunc("/{cloudRegionID}/{namespace}/{externalVNFID}", DeleteHandler).Methods("DELETE") - vnfInstanceHandler.HandleFunc("/{cloudRegionID}/{namespace}/{externalVNFID}", GetHandler).Methods("GET") + // Setup Instance handler routes + if instClient == nil { + instClient = app.NewInstanceClient() + } + instHandler := instanceHandler{client: instClient} + instRouter := router.PathPrefix("/v1").Subrouter() + instRouter.HandleFunc("/instance", instHandler.createHandler).Methods("POST") + instRouter.HandleFunc("/instance/{instID}", instHandler.getHandler).Methods("GET") + instRouter.HandleFunc("/instance/{instID}", instHandler.deleteHandler).Methods("DELETE") + // (TODO): Fix update method + // instRouter.HandleFunc("/{vnfInstanceId}", UpdateHandler).Methods("PUT") //Setup resource bundle definition routes if defClient == nil { @@ -52,8 +61,5 @@ func NewRouter(kubeconfig string, defClient rb.DefinitionManager, resRouter.HandleFunc("/definition/{rbname}/{rbversion}/profile/{prname}", profileHandler.getHandler).Methods("GET") resRouter.HandleFunc("/definition/{rbname}/{rbversion}/profile/{prname}", profileHandler.deleteHandler).Methods("DELETE") - // (TODO): Fix update method - // vnfInstanceHandler.HandleFunc("/{vnfInstanceId}", UpdateHandler).Methods("PUT") - return router } |