aboutsummaryrefslogtreecommitdiffstats
path: root/src/ncm/api/api.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/ncm/api/api.go')
-rw-r--r--src/ncm/api/api.go39
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
}