Skip to content

Commit

Permalink
Add Screenshot method to client-go
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Mohr <[email protected]>
  • Loading branch information
rmohr committed Sep 20, 2022
1 parent 5ae5f4c commit 750889e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions staging/src/kubevirt.io/api/core/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2117,6 +2117,10 @@ type AddVolumeOptions struct {
DryRun []string `json:"dryRun,omitempty"`
}

type ScreenshotOptions struct {
MoveCursor bool `json:"moveCursor"`
}

// RemoveVolumeOptions is provided when dynamically hot unplugging volume and disk
type RemoveVolumeOptions struct {
// Name represents the name that maps to both the disk and volume that
Expand Down
1 change: 1 addition & 0 deletions staging/src/kubevirt.io/client-go/kubecli/kubevirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ type VirtualMachineInstanceInterface interface {
SerialConsole(name string, options *SerialConsoleOptions) (StreamInterface, error)
USBRedir(vmiName string) (StreamInterface, error)
VNC(name string) (StreamInterface, error)
Screenshot(name string, options *v1.ScreenshotOptions) ([]byte, error)
PortForward(name string, port int, protocol string) (StreamInterface, error)
Pause(name string, pauseOptions *v1.PauseOptions) error
Unpause(name string, unpauseOptions *v1.UnpauseOptions) error
Expand Down
15 changes: 15 additions & 0 deletions staging/src/kubevirt.io/client-go/kubecli/vmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,21 @@ func (v *vmis) FilesystemList(name string) (v1.VirtualMachineInstanceFileSystemL
return fsList, err
}

func (v *vmis) Screenshot(name string, screenshotOptions *v1.ScreenshotOptions) ([]byte, error) {
moveCursor := "false"
if screenshotOptions.MoveCursor == true {
moveCursor = "true"
}

uri := fmt.Sprintf(vmiSubresourceURL, v1.ApiStorageVersion, v.namespace, name, "vnc/screenshot")
res := v.restClient.Get().RequestURI(v.adaptUriForHostPath(uri)).Param("moveCursor", moveCursor).Do(context.Background())
raw, err := res.Raw()
if err != nil {
return nil, res.Error()
}
return raw, nil
}

func (v *vmis) AddVolume(name string, addVolumeOptions *v1.AddVolumeOptions) error {
uri := fmt.Sprintf(vmiSubresourceURL, v1.ApiStorageVersion, v.namespace, name, "addvolume")

Expand Down

0 comments on commit 750889e

Please sign in to comment.