-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
vsock.go
39 lines (32 loc) · 1.04 KB
/
vsock.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
package rest
import (
"fmt"
restful "github.com/emicklei/go-restful/v3"
"k8s.io/apimachinery/pkg/api/errors"
v1 "kubevirt.io/api/core/v1"
"kubevirt.io/client-go/kubecli"
"kubevirt.io/client-go/log"
"kubevirt.io/kubevirt/pkg/util"
)
func (app *SubresourceAPIApp) VSOCKRequestHandler(request *restful.Request, response *restful.Response) {
streamer := NewRawStreamer(
app.FetchVirtualMachineInstance,
validateVMIForVSOCK,
app.virtHandlerDialer(func(vmi *v1.VirtualMachineInstance, conn kubecli.VirtHandlerConn) (string, error) {
tls := "true"
if request.QueryParameter("tls") != "" {
tls = request.QueryParameter("tls")
}
return conn.VSOCKURI(vmi, request.QueryParameter("port"), tls)
}),
)
streamer.Handle(request, response)
}
func validateVMIForVSOCK(vmi *v1.VirtualMachineInstance) *errors.StatusError {
if !util.IsAutoAttachVSOCK(vmi) {
err := fmt.Errorf("VSOCK is not attached.")
log.Log.Object(vmi).Reason(err).Error("Can't establish Vsock connection.")
return errors.NewBadRequest(err.Error())
}
return nil
}