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
Vincent Bechu
slapos
Commits
dc839285
Commit
dc839285
authored
Nov 16, 2011
by
Antoine Catton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Switch rdiff backup recipe to slave instance based recipe.
parent
2ca33d24
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
120 additions
and
41 deletions
+120
-41
slapos/recipe/dropbear.py
slapos/recipe/dropbear.py
+26
-0
slapos/recipe/rdiffbackup.py
slapos/recipe/rdiffbackup.py
+94
-41
No files found.
slapos/recipe/dropbear.py
View file @
dc839285
...
@@ -28,6 +28,32 @@ import os
...
@@ -28,6 +28,32 @@ import os
import
itertools
import
itertools
from
slapos.recipe.librecipe
import
GenericBaseRecipe
from
slapos.recipe.librecipe
import
GenericBaseRecipe
class
KnownHostsFile
(
dict
):
def
__init__
(
self
,
filename
):
self
.
_filename
=
filename
def
_load
(
self
):
if
os
.
path
.
exists
(
self
.
_filename
):
with
open
(
self
.
_filename
,
'r'
)
as
keyfile
:
for
line
in
keyfile
:
host
,
key
=
[
column
.
strip
()
for
column
in
line
.
split
(
' '
,
1
)]
self
[
host
]
=
key
def
_dump
(
self
):
with
open
(
self
.
_filename
,
'w'
)
as
keyfile
:
for
key
,
value
in
self
.
items
():
keyfile
.
write
(
'%(host)s %(key)s
\
n
'
%
{
'host'
:
key
,
'key'
:
value
})
def
__enter__
(
self
):
self
.
_load
()
def
__exit__
(
self
,
exc_type
,
exc_value
,
traceback
):
self
.
_dump
()
class
AuthorizedKeysFile
(
object
):
class
AuthorizedKeysFile
(
object
):
def
__init__
(
self
,
filename
):
def
__init__
(
self
,
filename
):
...
...
slapos/recipe/rdiffbackup.py
View file @
dc839285
...
@@ -24,11 +24,15 @@
...
@@ -24,11 +24,15 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# 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
os
import
os
import
subprocess
import
subprocess
import
sys
import
sys
from
slapos.recipe.librecipe
import
GenericBaseRecipe
from
slapos.recipe.librecipe
import
GenericBaseRecipe
from
slapos.recipe.dropbear
import
KnownHostsFile
from
slapos
import
slap
as
slapmodule
from
slapos
import
slap
as
slapmodule
...
@@ -41,9 +45,7 @@ def promise(args):
...
@@ -41,9 +45,7 @@ def promise(args):
# Rdiff Backup protocol quit command
# Rdiff Backup protocol quit command
quitcommand
=
'q'
+
chr
(
255
)
+
chr
(
0
)
*
7
quitcommand
=
'q'
+
chr
(
255
)
+
chr
(
0
)
*
7
ssh_cmdline
=
[
args
[
'ssh_client'
],
'-T'
,
ssh_cmdline
=
[
args
[
'ssh_client'
],
'%(user)s@%(host)s/%(port)s'
%
args
]
'-i'
,
args
[
'key'
],
'-y'
,
'%(user)s@%(host)s/%(port)s'
%
args
]
ssh
=
subprocess
.
Popen
(
ssh_cmdline
,
stdin
=
subprocess
.
PIPE
,
ssh
=
subprocess
.
Popen
(
ssh_cmdline
,
stdin
=
subprocess
.
PIPE
,
stdout
=
open
(
os
.
devnull
),
stderr
=
open
(
os
.
devnull
))
stdout
=
open
(
os
.
devnull
),
stderr
=
open
(
os
.
devnull
))
...
@@ -58,55 +60,106 @@ def promise(args):
...
@@ -58,55 +60,106 @@ def promise(args):
return
ssh
.
returncode
return
ssh
.
returncode
class
Recipe
(
GenericBaseRecipe
):
class
Recipe
(
GenericBaseRecipe
):
def
install
(
self
):
def
add_slave
(
self
,
entry
,
known_hosts_file
):
path_list
=
[]
url
=
entry
.
get
(
'url'
)
if
url
is
None
:
url
=
''
# We assume that thanks to sha512 there's no collisions
url_hash
=
sha512
(
url
).
hexdigest
()
name_hash
=
sha512
(
entry
[
'name'
]).
hexdigest
()
promise_path
=
os
.
path
.
join
(
self
.
options
[
'promises-directory'
],
url_hash
)
parsed_url
=
urlparse
(
url
)
promise_dict
=
self
.
promise_base_dict
.
copy
()
promise_dict
.
update
(
user
=
parsed_url
.
username
,
host
=
parsed_url
.
hostname
,
port
=
parsed_url
.
port
)
promise
=
self
.
createPythonScript
(
promise_path
,
__name__
+
'.promise'
,
promise_dict
)
path_list
.
append
(
promise
)
host
=
parsed_url
.
hostname
known_hosts_file
[
host
]
=
entry
[
'server-key'
]
remote_schema
=
'%(ssh)s -p %%s %(user)s@%(host)s'
%
\
{
'ssh'
:
self
.
options
[
'sshclient-binary'
],
'user'
:
parsed_url
.
username
,
'host'
:
parsed_url
.
hostname
,
}
command
=
[
self
.
options
[
'rdiffbackup-binary'
]]
command
=
[
self
.
options
[
'rdiffbackup-binary'
]]
command
.
extend
([
'--remote-schema'
,
remote_schema
])
remote_directory
=
'%(port)s::%(path)s'
%
{
'port'
:
parsed_url
.
port
,
'path'
:
parsed_url
.
path
}
local_directory
=
self
.
createDirectory
(
self
.
options
[
'directory'
],
name_hash
)
if
entry
[
'type'
]
==
'push'
:
command
.
extend
([
'--restore-as-of'
,
'now'
])
command
.
extend
([
local_directory
,
remote_directory
])
else
:
command
.
extend
([
remote_directory
,
local_directory
])
wrapper
=
self
.
createPythonScript
(
os
.
path
.
join
(
self
.
options
[
'wrappers-directory'
],
url_hash
),
'slapos.recipe.librecipe.execute.execute'
,
command
)
path_list
.
append
(
wrapper
)
cron_entry
=
os
.
path
.
join
(
self
.
options
[
'cron-entries'
],
url_hash
)
with
open
(
cron_entry
,
'w'
)
as
cron_entry_file
:
cron_entry_file
.
write
(
'%s %s'
%
(
entry
[
'frequency'
],
wrapper
))
path_list
.
append
(
cron_entry
)
return
path_list
def
install
(
self
):
path_list
=
[]
if
self
.
optionIsTrue
(
'client'
,
True
):
if
self
.
optionIsTrue
(
'client'
,
True
):
self
.
logger
.
info
(
"Client mode"
)
self
.
logger
.
info
(
"Client mode"
)
# XXX-Antoine: Automaticaly accept unknown key with -y
slap_connection
=
self
.
buildout
[
'slap-connection'
]
# we should generate a known_host file.
self
.
promise_base_dict
=
dict
(
remote_schema
=
'%(ssh)s -i %%s -T -y %(user)s@%(host)s/%(port)s'
%
\
server_url
=
slap_connection
[
'server-url'
],
{
computer_id
=
slap_connection
[
'computer-id'
],
'ssh'
:
self
.
options
[
'sshclient-binary'
],
cert_file
=
slap_connection
.
get
(
'cert-file'
),
'user'
:
self
.
options
[
'user'
],
key_file
=
slap_connection
.
get
(
'key-file'
),
'host'
:
self
.
options
[
'host'
],
partition_id
=
slap_connection
[
'partition-id'
],
'port'
:
self
.
options
[
'port'
],
ssh_client
=
self
.
options
[
'sshclient-binary'
],
}
)
command
.
extend
([
'--remote-schema'
,
remote_schema
])
slaves
=
unjson
(
self
.
buildout
[
'slap-parameter'
][
'slave_instance_list'
])
command
.
append
(
'%(key)s::%(path)s'
%
{
'key'
:
self
.
options
[
'key'
],
known_hosts
=
KnownHostsFile
(
self
.
options
[
'known-hosts'
])
'path'
:
self
.
options
[
'path'
]})
with
known_hosts
:
command
.
append
(
self
.
options
[
'localpath'
])
for
slave
in
slaves
:
path_list
.
extend
(
self
.
add_slave
(
slave
,
known_hosts
))
if
'promise'
in
self
.
options
:
slap_connection
=
self
.
buildout
[
'slap-connection'
]
self
.
createPythonScript
(
self
.
options
[
'promise'
],
__name__
+
'.promise'
,
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'
],
user
=
self
.
options
[
'user'
],
host
=
self
.
options
[
'host'
],
port
=
self
.
options
[
'port'
],
key
=
self
.
options
[
'key'
],
),
)
else
:
else
:
command
=
[
self
.
options
[
'rdiffbackup-binary'
]]
self
.
logger
.
info
(
"Server mode"
)
self
.
logger
.
info
(
"Server mode"
)
command
.
extend
([
'--restrict'
,
self
.
options
[
'path'
]])
command
.
extend
([
'--restrict'
,
self
.
options
[
'path'
]])
command
.
append
(
'--server'
)
command
.
append
(
'--server'
)
wrapper
=
self
.
createPythonScript
(
wrapper
=
self
.
createPythonScript
(
self
.
options
[
'wrapper'
],
self
.
options
[
'wrapper'
],
'slapos.recipe.librecipe.execute.execute'
,
'slapos.recipe.librecipe.execute.execute'
,
command
)
command
)
path_list
.
append
(
wrapper
)
return
[
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