Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Godshell
Skynet
Commits
7e48d76e
Commit
7e48d76e
authored
Nov 29, 2014
by
Jason Frisvold
Browse files
- Remove key_type, replace with check instead
- - The head of the key file identifies the key type (RSA/DSA)
parent
a3e743aa
Changes
1
Hide whitespace changes
Inline
Side-by-side
server/skynet.py
View file @
7e48d76e
...
...
@@ -120,7 +120,6 @@ def main(argv):
server_conn
=
connect_server
(
server
[
'ip'
],
server
[
'ssh_username'
],
server
[
'key_type'
],
server
[
'ssh_key'
])
if
(
server_conn
):
...
...
@@ -174,9 +173,9 @@ def loadconfig():
def
get_servers
(
dbhandle
):
logger
.
info
(
'Loading server list'
)
sql
=
'''SELECT DISTINCT c.id, c.server_ip, c.
key_type
, c.
ssh
_key,
c.gpg_key,
c.config_dir, c.output_dir, c.ssh_username FROM cloud AS
c,
timers AS ti, target AS t, spawn AS s WHERE (ti.cloud_id = c.id
sql
=
'''SELECT DISTINCT c.id, c.server_ip, c.
ssh_key
, c.
gpg
_key,
c.config_dir, c.output_dir, c.ssh_username FROM cloud AS
c,
timers AS ti, target AS t, spawn AS s WHERE (ti.cloud_id = c.id
AND ti.spawn_id = s.id AND ti.target_id = t.id) AND
(c.last_contacted <= c.last_modified OR c.last_contacted <=
ti.last_modified OR c.last_contacted <= t.last_modified OR
...
...
@@ -197,19 +196,24 @@ def get_servers(dbhandle):
for
row
in
rows
:
logger
.
debug
(
'Database Retrieval : {0}'
.
format
(
str
(
row
)))
serverlist
.
append
({
'id'
:
row
[
0
],
'ip'
:
str
(
IPAddress
(
row
[
1
])),
'
key_type
'
:
row
[
2
],
'
ssh
_key'
:
row
[
3
],
'
gpg_key
'
:
row
[
4
],
'
config
_dir'
:
row
[
5
],
'output_dir'
:
row
[
6
],
'ssh_username'
:
row
[
7
]})
'
ssh_key
'
:
row
[
2
],
'
gpg
_key'
:
row
[
3
],
'
config_dir
'
:
row
[
4
],
'
output
_dir'
:
row
[
5
],
'ssh_username'
:
row
[
6
]})
return
serverlist
def
connect_server
(
server_ip
,
username
,
key_type
,
ssh_key
):
def
connect_server
(
server_ip
,
username
,
ssh_key
):
logger
.
info
(
'Creating SSH connection to server {0}'
.
format
(
server_ip
))
if
(
key_type
==
'RSA'
):
key_file
=
open
(
ssh_key
,
'r'
)
key_head
=
key_file
.
readline
()
key_file
.
seek
(
0
)
if
'DSA'
in
key_head
:
server_key
=
paramiko
.
DSSKey
.
from_private_key_file
(
ssh_key
)
elif
'RSA'
in
key_head
:
server_key
=
paramiko
.
RSAKey
.
from_private_key_file
(
ssh_key
)
else
:
server_key
=
paramiko
.
DSSKey
.
from_private_key_file
(
ssh_key
)
raise
Exception
(
"Unknown SSH Key Type"
)
try
:
transport
=
paramiko
.
Transport
((
server_ip
))
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment