Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Secure solution for nexus infrastructure
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
flg_masters
TM
Secure solution for nexus infrastructure
Commits
f60e62bc
Commit
f60e62bc
authored
2 years ago
by
Florent Gluck
Browse files
Options
Downloads
Patches
Plain Diff
Completed server-side of USB redirection
Bumped server to version 1.6.0
parent
e683dcf1
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/router/routerVMs.go
+8
-7
8 additions, 7 deletions
src/router/routerVMs.go
src/vms/vms.go
+4
-1
4 additions, 1 deletion
src/vms/vms.go
with
12 additions
and
8 deletions
src/router/routerVMs.go
+
8
−
7
View file @
f60e62bc
...
...
@@ -165,7 +165,7 @@ func (r *RouterVMs)GetFilesImportableVMs(c echo.Context) error {
// Creates a VM.
// Requires this capability:
// User cap: CAP_VM_CREATE.
// curl --cacert ca.pem -X POST https://localhost:1077/vms -H 'Content-Type: application/json' -d '{"name":"Systems Programming 2022","cpus":2,"ram":4096,"nic":"none","template":"Xubuntu_22.04"}' -H "Authorization: Bearer <AccessToken>"
// curl --cacert ca.pem -X POST https://localhost:1077/vms -H 'Content-Type: application/json' -d '{"name":"Systems Programming 2022","cpus":2,"ram":4096,"nic":"none","
usbDevs":["1307:0165","1234:abcd"],"
template":"Xubuntu_22.04"}' -H "Authorization: Bearer <AccessToken>"
func
(
r
*
RouterVMs
)
CreateVM
(
c
echo
.
Context
)
error
{
// Retrieves logged user from context.
user
,
err
:=
getLoggedUser
(
r
.
users
,
c
)
...
...
@@ -279,23 +279,24 @@ func (r *RouterVMs)RebootVM(c echo.Context) error {
// Requires to be the VM's owner, or either capability:
// User cap: CAP_VM_EDIT_ANY: any VM can be edited.
// VM access cap: CAP_VM_EDIT: any of the VMs with this cap for the logged user can be edited.
// curl --cacert ca.pem -X PUT https://localhost:1077/vms/e41f3556-ca24-4658-bd79-8c85bd6bff59 -H 'Content-Type: application/json' -d '{"name":"Edited VM","cpus":1,"ram":2048,"nic":"user"}' -H "Authorization: Bearer <AccessToken>"
// curl --cacert ca.pem -X PUT https://localhost:1077/vms/e41f3556-ca24-4658-bd79-8c85bd6bff59 -H 'Content-Type: application/json' -d '{"name":"Edited VM","cpus":1,"ram":2048,"nic":"user"
,"usbDevs":["1307:0165","1234:abcd"]
}' -H "Authorization: Bearer <AccessToken>"
func
(
r
*
RouterVMs
)
EditVMByID
(
c
echo
.
Context
)
error
{
return
r
.
performVMAction
(
c
,
caps
.
CAP_VM_EDIT_ANY
,
caps
.
CAP_VM_EDIT
,
func
(
c
echo
.
Context
,
vm
*
vms
.
VM
)
error
{
// Deserializes and validates the client's parameters.
// Given these parameters are optional, we can't use a validator on them.
// Validation is performed in vm.EditVM() instead.
type
Parameters
struct
{
Name
string
`json:"name"`
Cpus
int
`json:"cpus"`
Ram
int
`json:"ram"`
// in MB
Nic
vms
.
NicType
`json:"nic"`
Name
string
`json:"name" validate:"required,min=4,max=256"`
Cpus
int
`json:"cpus" validate:"required,gte=1,lte=16"`
Ram
int
`json:"ram" validate:"required,gte=512,lte=32768"`
Nic
vms
.
NicType
`json:"nic" validate:"required`
UsbDevs
[]
string
`json:"usbDevs" validate:"required`
}
p
:=
new
(
Parameters
)
if
err
:=
decodeJson
(
c
,
&
p
);
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
err
.
Error
())
}
if
err
:=
r
.
vms
.
EditVM
(
vm
.
ID
,
p
.
Name
,
p
.
Cpus
,
p
.
Ram
,
p
.
Nic
);
err
!=
nil
{
if
err
:=
r
.
vms
.
EditVM
(
vm
.
ID
,
p
.
Name
,
p
.
Cpus
,
p
.
Ram
,
p
.
Nic
,
p
.
UsbDevs
);
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
err
.
Error
())
}
return
c
.
JSONPretty
(
http
.
StatusOK
,
jsonMsg
(
"OK"
),
" "
)
...
...
This diff is collapsed.
Click to expand it.
src/vms/vms.go
+
4
−
1
View file @
f60e62bc
...
...
@@ -284,7 +284,7 @@ func (vms *VMs)IsTemplateUsed(templateID string) bool {
}
// Edit a VM' specs: name, cpus, ram, nic
func
(
vms
*
VMs
)
EditVM
(
vmID
uuid
.
UUID
,
name
string
,
cpus
,
ram
int
,
nic
NicType
)
error
{
func
(
vms
*
VMs
)
EditVM
(
vmID
uuid
.
UUID
,
name
string
,
cpus
,
ram
int
,
nic
NicType
,
usbDevs
[]
string
)
error
{
vm
,
err
:=
vms
.
getVMUnsafe
(
vmID
)
if
err
!=
nil
{
return
err
...
...
@@ -303,6 +303,9 @@ func (vms *VMs)EditVM(vmID uuid.UUID, name string, cpus, ram int, nic NicType) e
if
nic
!=
""
{
vm
.
Nic
=
nic
}
if
usbDevs
!=
nil
{
vm
.
UsbDevs
=
usbDevs
}
if
err
=
vm
.
validate
();
err
!=
nil
{
return
err
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment