Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
Vm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Jiří Kalvoda
Vm
Commits
58926502
Commit
58926502
authored
1 year ago
by
Jiří Kalvoda
Browse files
Options
Downloads
Patches
Plain Diff
vnc default configuration
parent
2091ae7d
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
vm.py
+10
-8
10 additions, 8 deletions
vm.py
with
10 additions
and
8 deletions
vm.py
+
10
−
8
View file @
58926502
...
@@ -459,20 +459,25 @@ def sshfs_clean():
...
@@ -459,20 +459,25 @@ def sshfs_clean():
def
escape_sh
(
*
arg
):
def
escape_sh
(
*
arg
):
return
"
"
.
join
(
"'"
+
s
.
replace
(
"'"
,
"'
\"
'
\"
'"
)
+
"'"
for
s
in
arg
)
return
"
"
.
join
(
"'"
+
s
.
replace
(
"'"
,
"'
\"
'
\"
'"
)
+
"'"
for
s
in
arg
)
def
get_vnc_client_env
(
vm
):
vnc_client_env
=
os
.
environ
.
copy
()
vnc_client_env
[
"
VNC_PASSWORD
"
]
=
open
(
vm_dir
(
vm
)
+
"
vnc_passwd
"
,
"
r
"
).
read
().
strip
()
return
vnc_client_env
vncviewer_args
=
[
"
-FullscreenSystemKeys=0
"
,
"
-AcceptClipboard=0
"
,
"
-SendClipboard=0
"
]
@cmd
@cmd
def
vncapp
(
vm
:
str
,
cmd
:
str
,
user
:
str
=
"
u
"
):
def
vncapp
(
vm
:
str
,
cmd
:
str
,
user
:
str
=
"
u
"
):
import
random
import
random
import
psutil
import
psutil
unit_id
=
random
.
randint
(
100000
,
999999
)
unit_id
=
random
.
randint
(
100000
,
999999
)
vm
,
user
=
extended_name
(
vm
,
user
=
user
)
vm
,
user
=
extended_name
(
vm
,
user
=
user
)
vm
=
name_to_id
(
vm
)
display_id
=
random
.
randint
(
10
,
50
)
display_id
=
random
.
randint
(
10
,
50
)
vnc_server
=
subprocess
.
Popen
(
ssh_args
(
vm
,
f
"
systemd-run --unit vncapp-vnc-
{
display_id
}
-
{
unit_id
}
--user -P bash -c
'
(cat /vnc_passwd;echo; cat /vnc_passwd; echo;echo n) | vncpasswd; vncserver :
{
display_id
}
'"
,
user
=
user
))
vnc_server
=
subprocess
.
Popen
(
ssh_args
(
vm
,
f
"
systemd-run --unit vncapp-vnc-
{
display_id
}
-
{
unit_id
}
--user -P bash -c
'
(cat /vnc_passwd;echo; cat /vnc_passwd; echo;echo n) | vncpasswd; vncserver :
{
display_id
}
'"
,
user
=
user
))
time
.
sleep
(
1
)
time
.
sleep
(
1
)
vnc_client_env
=
os
.
environ
.
copy
()
vnc_client_env
[
"
VNC_PASSWORD
"
]
=
open
(
vm_dir
(
vm
)
+
"
vnc_passwd
"
,
"
r
"
).
read
().
strip
()
app
=
subprocess
.
Popen
(
ssh_args
(
vm
,
f
"
systemd-run --unit vncapp-app-
{
display_id
}
-
{
unit_id
}
--user -P -E DISPLAY=:
{
display_id
}
bash -c
{
escape_sh
(
cmd
)
}
"
,
user
=
user
));
app
=
subprocess
.
Popen
(
ssh_args
(
vm
,
f
"
systemd-run --unit vncapp-app-
{
display_id
}
-
{
unit_id
}
--user -P -E DISPLAY=:
{
display_id
}
bash -c
{
escape_sh
(
cmd
)
}
"
,
user
=
user
));
vnc_client
=
subprocess
.
Popen
([
"
vncviewer
"
,
get_ip
(
vm
)
+
f
"
:
{
display_id
}
"
],
env
=
vnc_client_env
)
vnc_client
=
subprocess
.
Popen
([
"
vncviewer
"
,
get_ip
(
vm
)
+
f
"
:
{
display_id
}
"
,
*
vncviewer_args
],
env
=
get_
vnc_client_env
(
vm
)
)
def
on_terminate
(
proc
):
def
on_terminate
(
proc
):
if
verbose
:
print
(
f
"
KILLING ALL APPS because
{
proc
}
terminated
"
)
if
verbose
:
print
(
f
"
KILLING ALL APPS because
{
proc
}
terminated
"
)
...
@@ -489,12 +494,9 @@ def vncsession(vm: str, display_id: int =0, user: str = "u"):
...
@@ -489,12 +494,9 @@ def vncsession(vm: str, display_id: int =0, user: str = "u"):
import
psutil
import
psutil
unit_id
=
random
.
randint
(
100000
,
999999
)
unit_id
=
random
.
randint
(
100000
,
999999
)
vm
,
user
=
extended_name
(
vm
,
user
=
user
)
vm
,
user
=
extended_name
(
vm
,
user
=
user
)
vm
=
name_to_id
(
vm
)
vnc_server
=
subprocess
.
Popen
(
ssh_args
(
vm
,
f
"
systemd-run --unit vncsession-
{
display_id
}
-
{
unit_id
}
--user -P bash -c
'
(cat /vnc_passwd;echo; cat /vnc_passwd; echo;echo n) | vncpasswd; vncserver :
{
display_id
}
'"
,
user
=
user
))
vnc_server
=
subprocess
.
Popen
(
ssh_args
(
vm
,
f
"
systemd-run --unit vncsession-
{
display_id
}
-
{
unit_id
}
--user -P bash -c
'
(cat /vnc_passwd;echo; cat /vnc_passwd; echo;echo n) | vncpasswd; vncserver :
{
display_id
}
'"
,
user
=
user
))
vnc_client_env
=
os
.
environ
.
copy
()
vnc_client_env
[
"
VNC_PASSWORD
"
]
=
open
(
vm_dir
(
vm
)
+
"
vnc_passwd
"
,
"
r
"
).
read
().
strip
()
time
.
sleep
(
1
)
time
.
sleep
(
1
)
vnc_client
=
subprocess
.
Popen
([
"
vncviewer
"
,
get_ip
(
vm
)
+
f
"
:
{
display_id
}
"
],
env
=
vnc_client_env
)
vnc_client
=
subprocess
.
Popen
([
"
vncviewer
"
,
get_ip
(
vm
)
+
f
"
:
{
display_id
}
"
,
*
vncviewer_args
],
env
=
get_
vnc_client_env
(
vm
)
)
def
on_terminate
(
proc
):
def
on_terminate
(
proc
):
if
verbose
:
print
(
"
KILLING ALL APPS
"
)
if
verbose
:
print
(
"
KILLING ALL APPS
"
)
...
...
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