Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
strudel2_backend
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
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hpc-team
strudel2_backend
Commits
aa6b4259
Commit
aa6b4259
authored
6 years ago
by
Chris Hines
Browse files
Options
Downloads
Patches
Plain Diff
cause tes to parse the certs to get the username rather than hardcoding it to chines :-P
parent
019d1d93
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tes/apiendpoints.py
+13
-2
13 additions, 2 deletions
tes/apiendpoints.py
tes/localtunnelstat/__init__.py
+38
-4
38 additions, 4 deletions
tes/localtunnelstat/__init__.py
with
51 additions
and
6 deletions
tes/apiendpoints.py
+
13
−
2
View file @
aa6b4259
...
...
@@ -74,12 +74,23 @@ class AddKey(Resource):
sshsess
.
refresh
()
return
"
OK
"
def
get
(
self
):
from
.localtunnelstat
import
SSHSession
sshsess
=
SSHSession
.
get_sshsession
()
return
sshsess
.
get_principals_and_hosts
()
def
get_conn_params
():
"""
Return parameters relating to the backend compute service
Retrieve them from the session (ideally)
"""
return
get_m3_params
()
params
=
get_m3_params
()
# Default assume there is only one certificate with one principal available
sshsess
=
SSHSession
.
get_sshsession
()
certs
=
sshsess
.
get_cert_contents
()
params
[
'
user
'
]
=
certs
[
0
][
'
Principals
'
][
0
]
return
params
def
get_m3_params
():
"""
...
...
@@ -89,7 +100,7 @@ def get_m3_params():
"""
params
=
{}
params
[
'
host
'
]
=
'
m3.massive.org.au
'
params
[
'
user
'
]
=
'
chines
'
#
params['user'] = 'chines'
params
[
'
cancelcmd
'
]
=
'
scancel {jobid}
'
params
[
'
statcmd
'
]
=
'
/home/chines/jsonstat.py
'
params
[
'
submitcmd
'
]
=
'
sbatch --partition=m3f
'
...
...
This diff is collapsed.
Click to expand it.
tes/localtunnelstat/__init__.py
+
38
−
4
View file @
aa6b4259
...
...
@@ -21,12 +21,13 @@ class SSHSession:
self
.
pids
=
[]
self
.
authtok
=
None
self
.
__dict__
.
update
(
kwargs
)
self
.
sshagent
=
[
'
ssh-agent
'
]
self
.
sshadd
=
[
'
ssh-add
'
]
self
.
sshagent
=
'
ssh-agent
'
self
.
sshadd
=
'
ssh-add
'
self
.
sshkeygen
=
'
ssh-keygen
'
def
start_agent
(
self
):
import
subprocess
p
=
subprocess
.
Popen
(
self
.
sshagent
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
p
=
subprocess
.
Popen
(
[
self
.
sshagent
]
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
(
stdout
,
stderr
)
=
p
.
communicate
()
for
l
in
stdout
.
decode
().
split
(
'
;
'
):
if
'
SSH_AUTH_SOCK=
'
in
l
:
...
...
@@ -51,7 +52,7 @@ class SSHSession:
certf
.
close
()
env
=
os
.
environ
.
copy
()
env
[
'
SSH_AUTH_SOCK
'
]
=
self
.
socket
cmd
=
self
.
sshadd
cmd
=
[
self
.
sshadd
]
cmd
.
append
(
keyname
)
p
=
subprocess
.
Popen
(
cmd
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
env
=
env
)
(
_
,
_
)
=
p
.
communicate
()
...
...
@@ -60,6 +61,39 @@ class SSHSession:
os
.
unlink
(
keyname
+
'
-cert.pub
'
)
os
.
unlink
(
keyname
)
def
get_cert_contents
(
self
):
res
=
[]
env
=
os
.
environ
.
copy
()
env
[
'
SSH_AUTH_SOCK
'
]
=
self
.
socket
cmd
=
[
self
.
sshadd
,
'
-L
'
]
p
=
subprocess
.
Popen
(
cmd
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
env
=
env
)
(
stdout
,
stderr
)
=
p
.
communicate
()
for
l
in
stdout
.
decode
().
splitlines
():
if
'
cert
'
in
l
:
p
=
subprocess
.
Popen
([
self
.
sshkeygen
,
'
-L
'
,
'
-f
'
,
'
-
'
],
stdout
,
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
keygenout
,
keygenerr
=
p
.
communicate
()
res
.
extend
(
SSHSession
.
parse_cert_contents
(
stdout
.
decode
().
splitlines
()))
return
res
@staticmethod
def
parse_cert_contents
(
lines
):
key
=
None
values
=
[]
res
=
{}
for
l
in
lines
:
if
'
:
'
in
l
:
if
key
is
not
None
:
res
[
key
]
=
values
values
=
[]
(
key
,
v
)
=
l
.
split
(
'
:
'
)
if
v
is
not
None
:
values
=
[
v
]
else
:
values
.
append
(
l
)
return
res
def
refresh
(
self
):
import
datetime
self
.
last
=
datetime
.
datetime
.
now
()
...
...
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