forked from kubevirt/kubevirt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
virt-api.go
45 lines (38 loc) · 1.45 KB
/
virt-api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"flag"
"github.com/emicklei/go-restful"
"github.com/emicklei/go-restful/swagger"
"golang.org/x/net/context"
"k8s.io/client-go/pkg/runtime/schema"
"kubevirt.io/kubevirt/pkg/api/v1"
"kubevirt.io/kubevirt/pkg/logging"
"kubevirt.io/kubevirt/pkg/virt-api/rest"
"log"
"net/http"
"strconv"
)
func main() {
logging.InitializeLogging("virt-api")
swaggerui := flag.String("swagger-ui", "third_party/swagger-ui", "swagger-ui location")
host := flag.String("listen", "0.0.0.0", "Address and port where to listen on")
port := flag.Int("port", 8183, "Port to listen on")
flag.Parse()
ctx := context.Background()
gvr := schema.GroupVersionResource{Group: v1.GroupVersion.Group, Version: v1.GroupVersion.Version, Resource: "vms"}
gvk := schema.GroupVersionKind{Group: v1.GroupVersion.Group, Version: v1.GroupVersion.Version, Kind: "VM"}
// FIXME the whole NewResponseHandler is just a hack, see the method itself for details
err := rest.AddGenericResourceProxy(rest.WebService, ctx, gvr, &v1.VM{}, rest.NewResponseHandler(gvk, &v1.VM{}))
if err != nil {
log.Fatal(err)
}
config := swagger.Config{
WebServices: restful.RegisteredWebServices(), // you control what services are visible
WebServicesUrl: "http://localhost:8183",
ApiPath: "/apidocs.json",
SwaggerPath: "/apidocs/",
SwaggerFilePath: *swaggerui,
}
swagger.InstallSwaggerService(config)
log.Fatal(http.ListenAndServe(*host+":"+strconv.Itoa(*port), nil))
}