mirror of
https://github.com/cirruslabs/orchard.git
synced 2026-10-19 08:07:58 +02:00
Introduce "orchard {port-forward, vnc} worker WORKER_NAME" (#140)
* Fix potential NPE in Client.wsRequest()
* Introduce "orchard {port-forward, vnc} worker WORKER_NAME"
* portspec.go: simplify logic and respect [LOCAL_PORT]:REMOTE_PORT format
This commit is contained in:
@@ -271,10 +271,10 @@ func (client *Client) wsRequest(
|
||||
if err != nil {
|
||||
if resp != nil {
|
||||
_ = resp.Body.Close()
|
||||
}
|
||||
|
||||
if resp.StatusCode == http.StatusNotFound {
|
||||
err = fmt.Errorf("%w (are you sure this VM exists on the controller?)", err)
|
||||
if resp.StatusCode == http.StatusNotFound {
|
||||
err = fmt.Errorf("%w (are you sure this VM exists on the controller?)", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil, err
|
||||
|
||||
@@ -4,8 +4,10 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/cirruslabs/orchard/pkg/resource/v1"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type WorkersService struct {
|
||||
@@ -65,3 +67,14 @@ func (service *WorkersService) Delete(ctx context.Context, name string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (service *WorkersService) PortForward(
|
||||
ctx context.Context,
|
||||
name string,
|
||||
port uint16,
|
||||
) (net.Conn, error) {
|
||||
return service.client.wsRequest(ctx, fmt.Sprintf("workers/%s/port-forward", url.PathEscape(name)),
|
||||
map[string]string{
|
||||
"port": strconv.FormatUint(uint64(port), 10),
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user