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
import (
"fmt"
"strings"
"strconv"
u "nexus-client/utils"
g "nexus-client/globals"
......@@ -68,7 +67,7 @@ func (cmd *Create)Run(args []string) int {
return 1
}
nic := NicType(args[3])
usbDevs := cmd.str2UsbDevices(args[4])
usbDevs := u.Str2UsbDevices(args[4])
templateID, err := uuid.Parse(args[5])
if err != nil {
u.PrintlnErr(err)
......@@ -153,17 +152,3 @@ func (cmd *Create)Run(args []string) int {
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 {
Name string
Cpus int
Ram int
Nic string
Nic NicType
UsbDevs []string
}
func (cmd *Edit)GetName() string {
......@@ -34,13 +35,16 @@ func (cmd *Edit)PrintUsage() {
u.PrintlnErr(desc)
}
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("―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――")
const usage string = `Parameters that can be changed (at least one must be specified):
name Name of the VM.
cpus Number of CPUs, between 1 and 16.
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("")
printRegexUsageDetails()
......@@ -141,7 +145,13 @@ func (cmd *Edit)parseArgs(args []string) (*vmEditParameters, []string, error) {
}
s = getStringVal(arg, "nic=")
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
continue
}
......
......@@ -7,6 +7,7 @@ import (
"io/fs"
"bytes"
"errors"
"strings"
"net/mail"
"archive/tar"
"path/filepath"
......@@ -112,3 +113,17 @@ func IsEmail(email string) bool {
_, err := mail.ParseAddress(email)
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