diff options
author | Eric Multanen <eric.w.multanen@intel.com> | 2020-03-13 17:39:40 -0700 |
---|---|---|
committer | Ritu Sood <Ritu.Sood@intel.com> | 2020-03-23 22:40:28 +0000 |
commit | 529906640a6844dd371de37631e3948d328a390b (patch) | |
tree | a8e56469d3fa70726d0a4623fecae43dc987c121 /src/ncm/api/api.go | |
parent | e201896e60374698da18cf4258448a0d97617e37 (diff) |
Add Network and Provider Network Intent API support
Add API for CRUD operations to manage network
and provider-network intent resources.
Issue-ID: MULTICLOUD-1029
Signed-off-by: Eric Multanen <eric.w.multanen@intel.com>
Change-Id: If3c71691b3825db50eacdb0ea87b0d5c436ad80f
Diffstat (limited to 'src/ncm/api/api.go')
-rw-r--r-- | src/ncm/api/api.go | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/src/ncm/api/api.go b/src/ncm/api/api.go index c26f54e9..34b46c67 100644 --- a/src/ncm/api/api.go +++ b/src/ncm/api/api.go @@ -25,7 +25,7 @@ import ( var moduleClient *moduleLib.Client -// for the given client and testClient, if the testClient is not null and +// For the given client and testClient, if the testClient is not null and // implements the client manager interface corresponding to client, then // return the testClient, otherwise return the client. func setClient(client, testClient interface{}) interface{} { @@ -37,6 +37,20 @@ func setClient(client, testClient interface{}) interface{} { return c } } + case *moduleLib.NetworkClient: + if testClient != nil && reflect.TypeOf(testClient).Implements(reflect.TypeOf((*moduleLib.NetworkManager)(nil)).Elem()) { + c, ok := testClient.(moduleLib.NetworkManager) + if ok { + return c + } + } + case *moduleLib.ProviderNetClient: + if testClient != nil && reflect.TypeOf(testClient).Implements(reflect.TypeOf((*moduleLib.ProviderNetManager)(nil)).Elem()) { + c, ok := testClient.(moduleLib.ProviderNetManager) + if ok { + return c + } + } default: fmt.Printf("unknown type %T\n", cl) } @@ -49,12 +63,11 @@ func NewRouter(testClient interface{}) *mux.Router { moduleClient = moduleLib.NewClient() + router := mux.NewRouter().PathPrefix("/v2").Subrouter() + clusterHandler := clusterHandler{ client: setClient(moduleClient.Cluster, testClient).(moduleLib.ClusterManager), } - - router := mux.NewRouter().PathPrefix("/v2").Subrouter() - router.HandleFunc("/cluster-providers", clusterHandler.createClusterProviderHandler).Methods("POST") router.HandleFunc("/cluster-providers", clusterHandler.getClusterProviderHandler).Methods("GET") router.HandleFunc("/cluster-providers/{name}", clusterHandler.getClusterProviderHandler).Methods("GET") @@ -72,5 +85,23 @@ func NewRouter(testClient interface{}) *mux.Router { router.HandleFunc("/cluster-providers/{provider-name}/clusters/{cluster-name}/kv-pairs/{kvpair}", clusterHandler.getClusterKvPairsHandler).Methods("GET") router.HandleFunc("/cluster-providers/{provider-name}/clusters/{cluster-name}/kv-pairs/{kvpair}", clusterHandler.deleteClusterKvPairsHandler).Methods("DELETE") + networkHandler := networkHandler{ + client: setClient(moduleClient.Network, testClient).(moduleLib.NetworkManager), + } + router.HandleFunc("/cluster-providers/{provider-name}/clusters/{cluster-name}/networks", networkHandler.createNetworkHandler).Methods("POST") + router.HandleFunc("/cluster-providers/{provider-name}/clusters/{cluster-name}/networks", networkHandler.getNetworkHandler).Methods("GET") + router.HandleFunc("/cluster-providers/{provider-name}/clusters/{cluster-name}/networks/{name}", networkHandler.putNetworkHandler).Methods("PUT") + router.HandleFunc("/cluster-providers/{provider-name}/clusters/{cluster-name}/networks/{name}", networkHandler.getNetworkHandler).Methods("GET") + router.HandleFunc("/cluster-providers/{provider-name}/clusters/{cluster-name}/networks/{name}", networkHandler.deleteNetworkHandler).Methods("DELETE") + + providernetHandler := providernetHandler{ + client: setClient(moduleClient.ProviderNet, testClient).(moduleLib.ProviderNetManager), + } + router.HandleFunc("/cluster-providers/{provider-name}/clusters/{cluster-name}/provider-networks", providernetHandler.createProviderNetHandler).Methods("POST") + router.HandleFunc("/cluster-providers/{provider-name}/clusters/{cluster-name}/provider-networks", providernetHandler.getProviderNetHandler).Methods("GET") + router.HandleFunc("/cluster-providers/{provider-name}/clusters/{cluster-name}/provider-networks/{name}", providernetHandler.putProviderNetHandler).Methods("PUT") + router.HandleFunc("/cluster-providers/{provider-name}/clusters/{cluster-name}/provider-networks/{name}", providernetHandler.getProviderNetHandler).Methods("GET") + router.HandleFunc("/cluster-providers/{provider-name}/clusters/{cluster-name}/provider-networks/{name}", providernetHandler.deleteProviderNetHandler).Methods("DELETE") + return router } |