Skip to content
Snippets Groups Projects
Commit ff2838ab authored by Florent Gluck's avatar Florent Gluck
Browse files

Completed client-side of USB redirection

Bumped client to version 1.6.0
parent 181fa563
No related branches found
No related tags found
No related merge requests found
...@@ -2,7 +2,6 @@ package cmdVM ...@@ -2,7 +2,6 @@ package cmdVM
import ( import (
"fmt" "fmt"
"strings"
"strconv" "strconv"
u "nexus-client/utils" u "nexus-client/utils"
g "nexus-client/globals" g "nexus-client/globals"
...@@ -68,7 +67,7 @@ func (cmd *Create)Run(args []string) int { ...@@ -68,7 +67,7 @@ func (cmd *Create)Run(args []string) int {
return 1 return 1
} }
nic := NicType(args[3]) nic := NicType(args[3])
usbDevs := cmd.str2UsbDevices(args[4]) usbDevs := u.Str2UsbDevices(args[4])
templateID, err := uuid.Parse(args[5]) templateID, err := uuid.Parse(args[5])
if err != nil { if err != nil {
u.PrintlnErr(err) u.PrintlnErr(err)
...@@ -153,17 +152,3 @@ func (cmd *Create)Run(args []string) int { ...@@ -153,17 +152,3 @@ func (cmd *Create)Run(args []string) int {
return statusCode return statusCode
} }
// Convert a string of USB devices of the form "1fc9:001d,067b:2303"
// into a slice of string where each element is a string of the form "1fc9:001d".
// Returns an empty slice if the input string is "none".
func (cmd *Create)str2UsbDevices(s string) []string {
usbDevs := []string{}
if s != "none" {
devs := strings.Split(s, ",") // Extracts USB devices
for _, dev := range devs {
usbDevs = append(usbDevs, dev)
}
}
return usbDevs
}
...@@ -16,7 +16,8 @@ type vmEditParameters struct { ...@@ -16,7 +16,8 @@ type vmEditParameters struct {
Name string Name string
Cpus int Cpus int
Ram int Ram int
Nic string Nic NicType
UsbDevs []string
} }
func (cmd *Edit)GetName() string { func (cmd *Edit)GetName() string {
...@@ -34,13 +35,16 @@ func (cmd *Edit)PrintUsage() { ...@@ -34,13 +35,16 @@ func (cmd *Edit)PrintUsage() {
u.PrintlnErr(desc) u.PrintlnErr(desc)
} }
u.PrintlnErr("―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――") u.PrintlnErr("―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――")
u.PrintlnErr("USAGE: "+cmd.GetName()+" [ID ...] [regex ...] [name=\"new name\"] [cpus=n] [ram=n] [nic=none/user]") u.PrintlnErr("USAGE: "+cmd.GetName()+" [ID ...] [regex ...] [name=...] [cpus=...] [ram=...] [nic=...] [usb=...]")
u.PrintlnErr("―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――") u.PrintlnErr("―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――")
const usage string = `Parameters that can be changed (at least one must be specified): const usage string = `Parameters that can be changed (at least one must be specified):
name Name of the VM. name Name of the VM.
cpus Number of CPUs, between 1 and 16. cpus Number of CPUs, between 1 and 16.
ram Amount of RAM in MB, between 512 and 32768. ram Amount of RAM in MB, between 512 and 32768.
nic Network interface, either "none" (no network) or "user" (network access).` nic Network interface, either "none" (no network) or "user" (network access).
usb List of USB devices exposed in the VM; either "none" or a list of comma separated
vendorID:productID (4-digit hex number), each specifying a USB device; example
exposing two USB devices: 1fc9:001d,067b:2303`
u.PrintlnErr(usage) u.PrintlnErr(usage)
u.PrintlnErr("") u.PrintlnErr("")
printRegexUsageDetails() printRegexUsageDetails()
...@@ -141,7 +145,13 @@ func (cmd *Edit)parseArgs(args []string) (*vmEditParameters, []string, error) { ...@@ -141,7 +145,13 @@ func (cmd *Edit)parseArgs(args []string) (*vmEditParameters, []string, error) {
} }
s = getStringVal(arg, "nic=") s = getStringVal(arg, "nic=")
if s != "" { if s != "" {
vmParams.Nic = s vmParams.Nic = NicType(s)
atLeastOneArg = true
continue
}
s = getStringVal(arg, "usb=")
if s != "" {
vmParams.UsbDevs = u.Str2UsbDevices(s)
atLeastOneArg = true atLeastOneArg = true
continue continue
} }
......
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
"io/fs" "io/fs"
"bytes" "bytes"
"errors" "errors"
"strings"
"net/mail" "net/mail"
"archive/tar" "archive/tar"
"path/filepath" "path/filepath"
...@@ -112,3 +113,17 @@ func IsEmail(email string) bool { ...@@ -112,3 +113,17 @@ func IsEmail(email string) bool {
_, err := mail.ParseAddress(email) _, err := mail.ParseAddress(email)
return err == nil return err == nil
} }
// Convert a string of USB devices of the form "1fc9:001d,067b:2303"
// into a slice of string where each element is a string of the form "1fc9:001d".
// Returns an empty slice if the input string is "none".
func Str2UsbDevices(s string) []string {
usbDevs := []string{}
if s != "none" {
devs := strings.Split(s, ",") // Extracts USB devices
for _, dev := range devs {
usbDevs = append(usbDevs, dev)
}
}
return usbDevs
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment