當前位置: 首頁>>代碼示例>>Golang>>正文


Golang remotecommand.ServeExec函數代碼示例

本文整理匯總了Golang中k8s/io/kubernetes/pkg/kubelet/server/remotecommand.ServeExec函數的典型用法代碼示例。如果您正苦於以下問題:Golang ServeExec函數的具體用法?Golang ServeExec怎麽用?Golang ServeExec使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了ServeExec函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: fakeServer

func fakeServer(t *testing.T, testName string, exec bool, stdinData, stdoutData, stderrData, errorData string, tty bool, messageCount int, serverProtocols []string) http.HandlerFunc {
	return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		executor := &fakeExecutor{
			t:            t,
			testName:     testName,
			errorData:    errorData,
			stdoutData:   stdoutData,
			stderrData:   stderrData,
			expectStdin:  len(stdinData) > 0,
			tty:          tty,
			messageCount: messageCount,
			exec:         exec,
		}

		opts, err := remotecommand.NewOptions(req)
		require.NoError(t, err)
		if exec {
			cmd := req.URL.Query()[api.ExecCommandParamm]
			remotecommand.ServeExec(w, req, executor, "pod", "uid", "container", cmd, opts, 0, 10*time.Second, serverProtocols)
		} else {
			remotecommand.ServeAttach(w, req, executor, "pod", "uid", "container", opts, 0, 10*time.Second, serverProtocols)
		}

		if e, a := strings.Repeat(stdinData, messageCount), executor.stdinReceived.String(); e != a {
			t.Errorf("%s: stdin: expected %q, got %q", testName, e, a)
		}
	})
}
開發者ID:nak3,項目名稱:kubernetes,代碼行數:28,代碼來源:remotecommand_test.go

示例2: getExec

// getExec handles requests to run a command inside a container.
func (s *Server) getExec(request *restful.Request, response *restful.Response) {
	params := getRequestParams(request)
	pod, ok := s.host.GetPodByName(params.podNamespace, params.podName)
	if !ok {
		response.WriteError(http.StatusNotFound, fmt.Errorf("pod does not exist"))
		return
	}

	podFullName := kubecontainer.GetPodFullName(pod)
	redirect, err := s.host.GetExec(podFullName, params.podUID, params.containerName, params.cmd, params.streamOpts)
	if err != nil {
		response.WriteError(streaming.HTTPStatus(err), err)
		return
	}
	if redirect != nil {
		http.Redirect(response.ResponseWriter, request.Request, redirect.String(), http.StatusFound)
		return
	}

	remotecommand.ServeExec(response.ResponseWriter,
		request.Request,
		s.host,
		podFullName,
		params.podUID,
		params.containerName,
		s.host.StreamingConnectionIdleTimeout(),
		remotecommand.DefaultStreamCreationTimeout,
		remotecommand.SupportedStreamingProtocols)
}
開發者ID:eljefedelrodeodeljefe,項目名稱:kubernetes,代碼行數:30,代碼來源:server.go

示例3: serveExec

func (s *server) serveExec(req *restful.Request, resp *restful.Response) {
	containerID := req.PathParameter("containerID")
	if containerID == "" {
		resp.WriteError(http.StatusBadRequest, errors.New("missing required containerID path parameter"))
		return
	}

	streamOpts, err := remotecommand.NewOptions(req.Request)
	if err != nil {
		resp.WriteError(http.StatusBadRequest, err)
		return
	}
	cmd := req.Request.URL.Query()[api.ExecCommandParamm]

	remotecommand.ServeExec(
		resp.ResponseWriter,
		req.Request,
		s.runtime,
		"", // unused: podName
		"", // unusued: podUID
		containerID,
		cmd,
		streamOpts,
		s.config.StreamIdleTimeout,
		s.config.StreamCreationTimeout,
		s.config.SupportedProtocols)
}
開發者ID:nak3,項目名稱:kubernetes,代碼行數:27,代碼來源:server.go

示例4: serveExec

func (s *server) serveExec(req *restful.Request, resp *restful.Response) {
	token := req.PathParameter("token")
	cachedRequest, ok := s.cache.Consume(token)
	if !ok {
		http.NotFound(resp.ResponseWriter, req.Request)
		return
	}
	exec, ok := cachedRequest.(*runtimeapi.ExecRequest)
	if !ok {
		http.NotFound(resp.ResponseWriter, req.Request)
		return
	}

	streamOpts := &remotecommand.Options{
		Stdin:  exec.GetStdin(),
		Stdout: true,
		Stderr: !exec.GetTty(),
		TTY:    exec.GetTty(),
	}

	remotecommand.ServeExec(
		resp.ResponseWriter,
		req.Request,
		s.runtime,
		"", // unused: podName
		"", // unusued: podUID
		exec.GetContainerId(),
		exec.GetCmd(),
		streamOpts,
		s.config.StreamIdleTimeout,
		s.config.StreamCreationTimeout,
		s.config.SupportedProtocols)
}
開發者ID:kubernetes,項目名稱:kubernetes,代碼行數:33,代碼來源:server.go

示例5: serveExec

func (s *server) serveExec(req *restful.Request, resp *restful.Response) {
	containerID := req.PathParameter("containerID")
	if containerID == "" {
		resp.WriteError(http.StatusBadRequest, errors.New("missing required containerID path parameter"))
		return
	}

	remotecommand.ServeExec(
		resp.ResponseWriter,
		req.Request,
		s.runtime,
		"", // unused: podName
		"", // unusued: podUID
		containerID,
		s.config.StreamIdleTimeout,
		s.config.StreamCreationTimeout,
		s.config.SupportedProtocols)
}
開發者ID:alex-mohr,項目名稱:kubernetes,代碼行數:18,代碼來源:server.go

示例6: getExec

// getExec handles requests to run a command inside a container.
func (s *Server) getExec(request *restful.Request, response *restful.Response) {
	podNamespace, podID, uid, container := getContainerCoordinates(request)
	pod, ok := s.host.GetPodByName(podNamespace, podID)
	if !ok {
		response.WriteError(http.StatusNotFound, fmt.Errorf("pod does not exist"))
		return
	}

	remotecommand.ServeExec(response.ResponseWriter,
		request.Request,
		s.host,
		kubecontainer.GetPodFullName(pod),
		uid,
		container,
		s.host.StreamingConnectionIdleTimeout(),
		remotecommand.DefaultStreamCreationTimeout,
		remotecommand.SupportedStreamingProtocols)
}
開發者ID:ZenoRewn,項目名稱:origin,代碼行數:19,代碼來源:server.go


注:本文中的k8s/io/kubernetes/pkg/kubelet/server/remotecommand.ServeExec函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。