Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jean-Paul Smets
slapos
Commits
f48b3df2
Commit
f48b3df2
authored
Nov 05, 2012
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
indentation, minor cleanup
parent
1bc4cc64
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
33 deletions
+36
-33
slapos/recipe/pbs.py
slapos/recipe/pbs.py
+36
-33
No files found.
slapos/recipe/pbs.py
View file @
f48b3df2
...
...
@@ -24,14 +24,15 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from
json
import
loads
as
unjson
from
hashlib
import
sha512
from
urlparse
import
urlparse
import
inspect
import
json
import
os
import
signal
import
subprocess
import
sys
import
signal
import
inspect
import
urlparse
from
slapos.recipe.librecipe
import
GenericSlapRecipe
from
slapos.recipe.dropbear
import
KnownHostsFile
...
...
@@ -43,8 +44,7 @@ from slapos import slap as slapmodule
def
promise
(
args
):
def
failed_ssh
(
partition
,
ssh
):
# Bad python 2 syntax, looking forward python 3 to have print(file=)
print
>>
sys
.
stderr
,
"SSH Connection failed"
sys
.
stderr
.
write
(
"SSH Connection failed
\
n
"
)
try
:
ssh
.
terminate
()
except
:
...
...
@@ -75,16 +75,20 @@ def promise(args):
slap
=
slapmodule
.
slap
()
slap
.
initializeConnection
(
args
[
'server_url'
],
key_file
=
args
.
get
(
'key_file'
),
cert_file
=
args
.
get
(
'cert_file'
))
key_file
=
args
.
get
(
'key_file'
),
cert_file
=
args
.
get
(
'cert_file'
))
partition
=
slap
.
registerComputerPartition
(
args
[
'computer_id'
],
args
[
'partition_id'
])
ssh
=
subprocess
.
Popen
([
args
[
'ssh_client'
],
'%(user)s@%(host)s/%(port)s'
%
args
],
stdin
=
subprocess
.
PIPE
,
stdout
=
open
(
os
.
devnull
,
'w'
),
stderr
=
open
(
os
.
devnull
,
'w'
))
# Rdiff Backup protocol quit command
quitcommand
=
'q'
+
chr
(
255
)
+
chr
(
0
)
*
7
ssh_cmdline
=
[
args
[
'ssh_client'
],
'%(user)s@%(host)s/%(port)s'
%
args
]
ssh
=
subprocess
.
Popen
(
ssh_cmdline
,
stdin
=
subprocess
.
PIPE
,
stdout
=
open
(
os
.
devnull
),
stderr
=
open
(
os
.
devnull
))
ssh
.
stdin
.
write
(
quitcommand
)
ssh
.
stdin
.
flush
()
ssh
.
stdin
.
close
()
...
...
@@ -113,7 +117,7 @@ class Recipe(GenericSlapRecipe, Notify, Callback):
promise_path
=
os
.
path
.
join
(
self
.
options
[
'promises-directory'
],
url_hash
)
parsed_url
=
urlparse
(
url
)
parsed_url
=
urlparse
.
urlparse
(
url
)
promise_dict
=
self
.
promise_base_dict
.
copy
()
promise_dict
.
update
(
user
=
parsed_url
.
username
,
host
=
parsed_url
.
hostname
,
...
...
@@ -165,15 +169,14 @@ class Recipe(GenericSlapRecipe, Notify, Callback):
if
'notify'
in
entry
:
feed_url
=
'%s/get/%s'
%
(
self
.
options
[
'notifier-url'
],
entry
[
'notification-id'
])
wrapper
=
self
.
createNotifier
(
self
.
options
[
'notifier-binary'
],
wrapper
=
wrapper_basepath
,
executable
=
wrapper_path
,
log
=
os
.
path
.
join
(
self
.
options
[
'feeds'
],
entry
[
'notification-id'
]),
title
=
entry
.
get
(
'title'
,
'Untitled'
),
notification_url
=
entry
[
'notify'
],
feed_url
=
feed_url
,
)
wrapper
=
self
.
createNotifier
(
notifier_binary
=
self
.
options
[
'notifier-binary'
],
wrapper
=
wrapper_basepath
,
executable
=
wrapper_path
,
log
=
os
.
path
.
join
(
self
.
options
[
'feeds'
],
entry
[
'notification-id'
]),
title
=
entry
.
get
(
'title'
,
'Untitled'
),
notification_url
=
entry
[
'notify'
],
feed_url
=
feed_url
,
)
path_list
.
append
(
wrapper
)
#self.setConnectionDict(dict(feed_url=feed_url), entry['slave_reference'])
...
...
@@ -188,30 +191,29 @@ class Recipe(GenericSlapRecipe, Notify, Callback):
return
path_list
def
_install
(
self
):
path_list
=
[]
if
self
.
optionIsTrue
(
'client'
,
True
):
self
.
logger
.
info
(
"Client mode"
)
slap_connection
=
self
.
buildout
[
'slap-connection'
]
self
.
promise_base_dict
=
dict
(
server_url
=
slap_connection
[
'server-url'
],
computer_id
=
slap_connection
[
'computer-id'
],
cert_file
=
slap_connection
.
get
(
'cert-file'
),
key_file
=
slap_connection
.
get
(
'key-file'
),
partition_id
=
slap_connection
[
'partition-id'
],
ssh_client
=
self
.
options
[
'sshclient-binary'
],
)
slaves
=
unjson
(
self
.
options
[
'slave-instance-list'
])
self
.
promise_base_dict
=
{
'server_url'
:
slap_connection
[
'server-url'
],
'computer_id'
:
slap_connection
[
'computer-id'
],
'cert_file'
:
slap_connection
.
get
(
'cert-file'
),
'key_file'
:
slap_connection
.
get
(
'key-file'
),
'partition_id'
:
slap_connection
[
'partition-id'
],
'ssh_client'
:
self
.
options
[
'sshclient-binary'
],
}
slaves
=
json
.
loads
(
self
.
options
[
'slave-instance-list'
])
known_hosts
=
KnownHostsFile
(
self
.
options
[
'known-hosts'
])
with
known_hosts
:
# XXX this API could be cleaner
for
slave
in
slaves
:
path_list
.
extend
(
self
.
add_slave
(
slave
,
known_hosts
))
else
:
self
.
logger
.
info
(
"Server mode"
)
...
...
@@ -224,3 +226,4 @@ class Recipe(GenericSlapRecipe, Notify, Callback):
path_list
.
append
(
wrapper
)
return
path_list
Write
Preview
Markdown
is supported
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