Add network topology APIs
Signed-off-by: Zhengyi Lai <zheng1@yunify.com>
This commit is contained in:
56
pkg/kapis/network/v1alpha2/register.go
Normal file
56
pkg/kapis/network/v1alpha2/register.go
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
Copyright 2020 The KubeSphere authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package v1alpha2
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
restful "github.com/emicklei/go-restful"
|
||||
restfulspec "github.com/emicklei/go-restful-openapi"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"kubesphere.io/kubesphere/pkg/apiserver/runtime"
|
||||
"kubesphere.io/kubesphere/pkg/constants"
|
||||
)
|
||||
|
||||
const GroupName = "network.kubesphere.io"
|
||||
|
||||
var GroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha2"}
|
||||
|
||||
func AddToContainer(c *restful.Container) error {
|
||||
webservice := runtime.NewWebService(GroupVersion)
|
||||
|
||||
webservice.Route(webservice.GET("/namespaces/{namespace}/topology").
|
||||
To(getNamespaceTopology).
|
||||
Metadata(restfulspec.KeyOpenAPITags, []string{constants.NetworkTopologyTag}).
|
||||
Doc("Get the topology with specifying a namespace").
|
||||
Param(webservice.PathParameter("namespace", "name of the namespace").Required(true)).
|
||||
Returns(http.StatusOK, "ok", TopologyResponse{}).
|
||||
Writes(TopologyResponse{})).Produces(restful.MIME_JSON)
|
||||
|
||||
webservice.Route(webservice.GET("/namespaces/{namespace}/topology/{node_id}").
|
||||
To(getNamespaceNodeTopology).
|
||||
Metadata(restfulspec.KeyOpenAPITags, []string{constants.NetworkTopologyTag}).
|
||||
Doc("Get the topology with specifying a node id in the whole topology and specifying a namespace").
|
||||
Param(webservice.PathParameter("namespace", "name of the namespace").Required(true)).
|
||||
Param(webservice.PathParameter("node_id", "id of the node in the whole topology").Required(true)).
|
||||
Returns(http.StatusOK, "ok", NodeResponse{}).
|
||||
Writes(NodeResponse{})).Produces(restful.MIME_JSON)
|
||||
|
||||
c.Add(webservice)
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user