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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Stephane VAROQUI
slapos
Commits
da4c1acf
Commit
da4c1acf
authored
Jan 20, 2020
by
Bryton Lacquement
🚪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip: slapos/recipe: add Python 3 support
parent
7736231c
Changes
41
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
41 changed files
with
234 additions
and
187 deletions
+234
-187
slapos/recipe/_urlparse.py
slapos/recipe/_urlparse.py
+1
-1
slapos/recipe/accords/accords.py
slapos/recipe/accords/accords.py
+5
-4
slapos/recipe/apachephpconfigure/__init__.py
slapos/recipe/apachephpconfigure/__init__.py
+11
-9
slapos/recipe/apachephpconfigure/runner.py
slapos/recipe/apachephpconfigure/runner.py
+6
-5
slapos/recipe/boinc/__init__.py
slapos/recipe/boinc/__init__.py
+7
-6
slapos/recipe/boinc/configure.py
slapos/recipe/boinc/configure.py
+41
-39
slapos/recipe/bonjourgrid/boinc.py
slapos/recipe/bonjourgrid/boinc.py
+12
-11
slapos/recipe/bonjourgrid/condor.py
slapos/recipe/bonjourgrid/condor.py
+2
-1
slapos/recipe/bonjourgrid/configure.py
slapos/recipe/bonjourgrid/configure.py
+4
-3
slapos/recipe/certificate_authority/__init__.py
slapos/recipe/certificate_authority/__init__.py
+3
-0
slapos/recipe/condor/configure.py
slapos/recipe/condor/configure.py
+4
-3
slapos/recipe/container.py
slapos/recipe/container.py
+3
-3
slapos/recipe/erp5testnode/__init__.py
slapos/recipe/erp5testnode/__init__.py
+3
-2
slapos/recipe/free_port.py
slapos/recipe/free_port.py
+2
-1
slapos/recipe/generic_cloudooo/__init__.py
slapos/recipe/generic_cloudooo/__init__.py
+1
-0
slapos/recipe/generic_mysql/mysql.py
slapos/recipe/generic_mysql/mysql.py
+8
-7
slapos/recipe/gitinit.py
slapos/recipe/gitinit.py
+2
-1
slapos/recipe/haproxy/__init__.py
slapos/recipe/haproxy/__init__.py
+2
-1
slapos/recipe/haproxy/haproxy.py
slapos/recipe/haproxy/haproxy.py
+5
-3
slapos/recipe/lamp/__init__.py
slapos/recipe/lamp/__init__.py
+9
-10
slapos/recipe/lamp/apache.py
slapos/recipe/lamp/apache.py
+2
-1
slapos/recipe/lamp/mysql.py
slapos/recipe/lamp/mysql.py
+13
-12
slapos/recipe/lamp/runner.py
slapos/recipe/lamp/runner.py
+5
-4
slapos/recipe/librecipe/execute.py
slapos/recipe/librecipe/execute.py
+2
-1
slapos/recipe/mioga/instantiate.py
slapos/recipe/mioga/instantiate.py
+3
-2
slapos/recipe/mysql/mysql.py
slapos/recipe/mysql/mysql.py
+13
-12
slapos/recipe/neoppod.py
slapos/recipe/neoppod.py
+2
-1
slapos/recipe/nosqltestbed/__init__.py
slapos/recipe/nosqltestbed/__init__.py
+2
-2
slapos/recipe/random.py
slapos/recipe/random.py
+6
-1
slapos/recipe/re6stnet/__init__.py
slapos/recipe/re6stnet/__init__.py
+2
-1
slapos/recipe/re6stnet/re6stnet.py
slapos/recipe/re6stnet/re6stnet.py
+4
-3
slapos/recipe/readline.py
slapos/recipe/readline.py
+1
-1
slapos/recipe/redis/MyRedis2410.py
slapos/recipe/redis/MyRedis2410.py
+17
-14
slapos/recipe/simplehttpserver/__init__.py
slapos/recipe/simplehttpserver/__init__.py
+2
-1
slapos/recipe/simplehttpserver/simplehttpserver.py
slapos/recipe/simplehttpserver/simplehttpserver.py
+4
-4
slapos/recipe/simplelogger.py
slapos/recipe/simplelogger.py
+3
-2
slapos/recipe/softwaretype.py
slapos/recipe/softwaretype.py
+9
-5
slapos/recipe/switch_softwaretype.py
slapos/recipe/switch_softwaretype.py
+2
-1
slapos/recipe/trac.py
slapos/recipe/trac.py
+2
-1
slapos/recipe/zabbixagent/svcdaemon.py
slapos/recipe/zabbixagent/svcdaemon.py
+5
-4
slapos/recipe/zero_knowledge.py
slapos/recipe/zero_knowledge.py
+4
-4
No files found.
slapos/recipe/_urlparse.py
View file @
da4c1acf
...
...
@@ -24,7 +24,7 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from
url
parse
import
urlparse
from
six.moves.urllib.
parse
import
urlparse
from
slapos.recipe.librecipe
import
GenericBaseRecipe
...
...
slapos/recipe/accords/accords.py
View file @
da4c1acf
...
...
@@ -26,6 +26,7 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from
__future__
import
print_function
import
os
from
slapos
import
slap
import
signal
...
...
@@ -66,15 +67,15 @@ def runAccords(accords_conf):
signal
.
signal
(
signal
.
SIGTERM
,
sigtermHandler
)
# Launch ACCORDS, parse & broke manifest to deploy instance
print
'Starting ACCORDS and friends...'
print
(
'Starting ACCORDS and friends...'
)
subprocess
.
check_call
([
'./co-start'
],
cwd
=
accords_location
,
env
=
environment
)
print
'Parsing manifest...'
print
(
'Parsing manifest...'
)
subprocess
.
check_call
([
'./co-parser'
,
manifest_name
],
cwd
=
accords_location
,
env
=
environment
)
print
'Brokering manifest...'
print
(
'Brokering manifest...'
)
subprocess
.
check_call
([
'./co-broker'
,
manifest_name
],
cwd
=
accords_location
,
env
=
environment
)
print
'Done.'
print
(
'Done.'
)
# Parse answer
# XXX
...
...
slapos/recipe/apachephpconfigure/__init__.py
View file @
da4c1acf
...
...
@@ -54,8 +54,10 @@ class Recipe(GenericBaseRecipe):
"""Start process which can launch python scripts, move or remove files or
directories when installing software.
"""
if
not
self
.
options
.
has_key
(
'delete'
)
and
not
self
.
options
.
has_key
(
'rename'
)
and
not
\
self
.
options
.
has_key
(
'chmod'
)
and
not
self
.
options
.
has_key
(
'script'
)
and
not
self
.
options
.
has_key
(
'sql-script'
):
for
k
in
[
'delete'
,
'rename'
,
'chmod'
,
'script'
,
'sql-script'
]:
if
k
in
self
.
options
:
break
else
:
return
""
delete
=
[]
chmod
=
[]
...
...
@@ -64,7 +66,7 @@ class Recipe(GenericBaseRecipe):
rename_list
=
""
argument
=
[
self
.
options
[
'lampconfigure'
],
"-H"
,
mysql_conf
[
'mysql_host'
],
"-P"
,
mysql_conf
[
'mysql_port'
],
"-p"
,
mysql_conf
[
'mysql_password'
],
"-u"
,
mysql_conf
[
'mysql_user'
]]
if
not
self
.
options
.
has_key
(
'file_token'
)
:
if
'file_token'
not
in
self
.
options
:
argument
=
argument
+
[
"-d"
,
mysql_conf
[
'mysql_database'
],
"--table"
,
self
.
options
[
'table_name'
].
strip
(),
"--cond"
,
self
.
options
.
get
(
'constraint'
,
'1'
).
strip
()]
...
...
@@ -72,11 +74,11 @@ class Recipe(GenericBaseRecipe):
argument
=
argument
+
[
"-f"
,
self
.
options
[
'file_token'
].
strip
()]
argument
+=
[
"-t"
,
document_root
]
if
self
.
options
.
has_key
(
'delete'
)
:
if
'delete'
in
self
.
options
:
delete
=
[
"delete"
]
for
fname
in
self
.
options
[
'delete'
].
split
(
','
):
delete
.
append
(
fname
.
strip
())
if
self
.
options
.
has_key
(
'rename'
)
:
if
'rename'
in
self
.
options
:
for
fname
in
self
.
options
[
'rename'
].
split
(
','
):
if
fname
.
find
(
"=>"
)
<
0
:
old_name
=
fname
...
...
@@ -86,18 +88,18 @@ class Recipe(GenericBaseRecipe):
else
:
fname
=
fname
.
split
(
"=>"
)
cmd
=
[
"rename"
]
if
self
.
options
.
has_key
(
'rename_chmod'
)
:
if
'rename_chmod'
in
self
.
options
:
cmd
+=
[
"--chmod"
,
self
.
options
[
'rename_chmod'
].
strip
()]
rename
.
append
(
cmd
+
[
fname
[
0
].
strip
(),
fname
[
1
].
strip
()])
rename_list
+=
fname
[
0
]
+
" to "
+
fname
[
1
]
+
" "
if
self
.
options
.
has_key
(
'chmod'
)
:
if
'chmod'
in
self
.
options
:
chmod
=
[
"chmod"
,
self
.
options
[
'mode'
].
strip
()]
for
fname
in
self
.
options
[
'chmod'
].
split
(
','
):
chmod
.
append
(
fname
.
strip
())
if
self
.
options
.
has_key
(
'script'
)
and
\
if
'script'
in
self
.
options
and
\
self
.
options
[
'script'
].
strip
().
endswith
(
".py"
):
data
=
[
"run"
,
self
.
options
[
'script'
].
strip
(),
"-v"
,
mysql_conf
[
'mysql_database'
],
url
,
document_root
]
if
self
.
options
.
has_key
(
'sql-script'
)
:
if
'sql-script'
in
self
.
options
:
data
=
[
"sql"
,
self
.
options
[
'sql-script'
].
strip
(),
"-v"
,
mysql_conf
[
'mysql_database'
],
url
,
document_root
]
...
...
slapos/recipe/apachephpconfigure/runner.py
View file @
da4c1acf
from
__future__
import
print_function
import
subprocess
def
executeRunner
(
arguments
,
delete
,
rename
,
chmod
,
data
):
...
...
@@ -6,17 +7,17 @@ def executeRunner(arguments, delete, rename, chmod, data):
exist into database.
"""
if
delete
:
print
"Calling lampconfigure with 'delete' arguments"
print
(
"Calling lampconfigure with 'delete' arguments"
)
subprocess
.
call
(
arguments
+
delete
)
if
rename
:
for
parameters
in
rename
:
print
"Calling lampconfigure with 'rename' arguments"
print
(
"Calling lampconfigure with 'rename' arguments"
)
subprocess
.
call
(
arguments
+
parameters
)
if
chmod
:
print
"Calling lampconfigure with 'chmod' arguments"
print
(
"Calling lampconfigure with 'chmod' arguments"
)
subprocess
.
call
(
arguments
+
chmod
)
if
data
:
print
"Calling lampconfigure with 'run' arguments"
print
arguments
+
data
print
(
"Calling lampconfigure with 'run' arguments"
)
print
(
arguments
+
data
)
subprocess
.
call
(
arguments
+
data
)
slapos/recipe/boinc/__init__.py
View file @
da4c1acf
...
...
@@ -24,6 +24,7 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from
__future__
import
print_function
from
slapos.recipe.librecipe
import
GenericBaseRecipe
import
os
import
subprocess
...
...
@@ -177,7 +178,7 @@ class Recipe(GenericBaseRecipe):
copyright
=
self
.
copyright
,
installroot
=
self
.
installroot
))
)
path_list
.
append
(
sh_script
)
os
.
chmod
(
bash
,
0700
)
os
.
chmod
(
bash
,
0
o
700
)
#After make_project run configure_script to perform and restart apache php services
service_status
=
os
.
path
.
join
(
self
.
home
,
'.start_service'
)
...
...
@@ -234,9 +235,9 @@ class App(GenericBaseRecipe):
downloader
=
zc
.
buildout
.
download
.
Download
(
self
.
buildout
[
'buildout'
],
hash_name
=
True
,
cache
=
cache
)
path
,
_
=
downloader
(
param
,
md5sum
=
None
)
mode
=
0600
mode
=
0
o
600
if
key
==
'binary'
:
mode
=
0700
mode
=
0
o
700
os
.
chmod
(
path
,
mode
)
app
[
key
]
=
path
...
...
@@ -278,7 +279,7 @@ class App(GenericBaseRecipe):
if
not
current_app
[
'template-result'
]
or
not
current_app
[
'binary'
]
\
or
not
current_app
[
'input-file'
]
or
not
current_app
[
'template-wu'
]
\
or
not
current_app
[
'platform'
]:
print
"BOINC-APP: ERROR - Invalid argements values for % ...operation cancelled"
%
app
print
(
"BOINC-APP: ERROR - Invalid argements values for % ...operation cancelled"
%
app
)
app_list
[
app
][
version
]
=
None
continue
#write application to install
...
...
@@ -319,7 +320,7 @@ class App(GenericBaseRecipe):
dict
(
dash
=
self
.
options
[
'dash'
].
strip
()))
)
path_list
.
append
(
sh_script
)
os
.
chmod
(
bash
,
0700
)
os
.
chmod
(
bash
,
0
o
700
)
#If useful, download necessary files and update options path
start_boinc
=
os
.
path
.
join
(
home
,
'.start_boinc'
)
...
...
@@ -339,7 +340,7 @@ class App(GenericBaseRecipe):
platform
=
app_list
[
appname
][
version
][
'platform'
]
application
=
os
.
path
.
join
(
apps_dir
,
appname
,
version
,
platform
)
if
app_list
[
appname
][
version
][
'binary'
]
and
not
platform
:
print
"BOINC-APP: WARNING - Cannot specify binary without giving platform value"
print
(
"BOINC-APP: WARNING - Cannot specify binary without giving platform value"
)
app_list
[
appname
][
version
][
'binary'
]
=
''
#Binary will not be updated
parameter
=
dict
(
installroot
=
installroot
,
...
...
slapos/recipe/boinc/configure.py
View file @
da4c1acf
This diff is collapsed.
Click to expand it.
slapos/recipe/bonjourgrid/boinc.py
View file @
da4c1acf
# -*- coding: utf-8 -*-
from
__future__
import
print_function
import
os
import
sys
import
re
...
...
@@ -36,10 +37,10 @@ def createAccount(config, base_cmd):
def
runBoinc
(
config
):
if
len
(
sys
.
argv
)
<
2
:
print
"Argument Error: uses %s project_url"
%
sys
.
argv
[
0
]
print
(
"Argument Error: uses %s project_url"
%
sys
.
argv
[
0
])
exit
(
1
)
if
type
(
config
)
==
type
(
""
):
print
"Error: bonjourgrid.xml parsing error, file not exist or corrupted"
print
(
"Error: bonjourgrid.xml parsing error, file not exist or corrupted"
)
exit
(
1
)
#XXX Using define values here for Boinc Master URL
config
[
'project_url'
]
=
sys
.
argv
[
1
]
...
...
@@ -53,7 +54,7 @@ def runBoinc(config):
client_config
=
os
.
path
.
join
(
config
[
'boinc_install_dir'
],
'client_state.xml'
)
while
not
os
.
path
.
exists
(
client_config
):
time
.
sleep
(
5
)
print
"Search for file '%r'..."
%
client_config
print
(
"Search for file '%r'..."
%
client_config
)
time
.
sleep
(
10
)
try
:
#Scan client state xml to find client ipv4 adress
...
...
@@ -64,21 +65,21 @@ def runBoinc(config):
'--passwd'
,
config
[
'boinc_passwd'
]]
#Create Account for current instance on BOINC master
print
"Create account for current client..."
print
(
"Create account for current client..."
)
key
=
createAccount
(
config
,
base_cmd
)
config
[
'key'
]
=
key
print
"Done. The account key is %s"
%
key
print
(
"Done. The account key is %s"
%
key
)
#Attach project to Boinc Master
print
"Attach client to Boinc Master at %s "
%
config
[
'project_url'
]
print
(
"Attach client to Boinc Master at %s "
%
config
[
'project_url'
])
try
:
joinProject
(
config
,
base_cmd
)
except
Exception
,
e
:
print
e
print
"Done! Waiting for Boinc Client now..."
except
Exception
,
e
:
except
Exception
as
e
:
print
(
e
)
print
(
"Done! Waiting for Boinc Client now..."
)
except
Exception
as
e
:
#An error occure!!!
os
.
kill
(
boinc
.
pid
,
signal
.
SIGTERM
)
print
e
print
(
e
)
#wait for Boinc client execution
boinc
.
wait
()
slapos/recipe/bonjourgrid/condor.py
View file @
da4c1acf
# -*- coding: utf-8 -*-
from
__future__
import
print_function
import
os
import
sys
import
re
...
...
@@ -33,7 +34,7 @@ def updateCondorWrapper(folder, hostname, ipv6):
def
runCondor
(
config
):
if
len
(
sys
.
argv
)
<
2
:
print
"Argument Error: uses %s hostname"
%
sys
.
argv
[
0
]
print
(
"Argument Error: uses %s hostname"
%
sys
.
argv
[
0
])
exit
(
1
)
hostname
=
sys
.
argv
[
1
]
...
...
slapos/recipe/bonjourgrid/configure.py
View file @
da4c1acf
...
...
@@ -25,6 +25,7 @@
#
##############################################################################
from
__future__
import
print_function
import
os
import
subprocess
import
time
...
...
@@ -40,7 +41,7 @@ def runProcess(args, file):
return
process
.
pid
def
launchScript
(
args
):
print
"Sleep for a few second..."
print
(
"Sleep for a few second..."
)
time
.
sleep
(
10
)
pid_list
=
[]
bg_pid
=
os
.
path
.
join
(
args
[
'bg_base'
],
'pid'
)
...
...
@@ -63,6 +64,6 @@ def launchScript(args):
pid_list
.
append
(
runProcess
(
args
,
file
))
for
pid
in
pid_list
:
print
"Parent waiting for process child: %s "
%
pid
print
(
"Parent waiting for process child: %s "
%
pid
)
result
=
os
.
waitpid
(
pid
,
0
)
print
"Done..."
,
result
print
(
"Done..."
,
result
)
slapos/recipe/certificate_authority/__init__.py
View file @
da4c1acf
...
...
@@ -26,6 +26,7 @@
##############################################################################
import
os
import
hashlib
import
six
from
six.moves
import
configparser
import
tempfile
...
...
@@ -108,6 +109,8 @@ class Request(Recipe):
request_needed
=
True
name
=
self
.
options
[
'name'
]
if
six
.
PY3
and
type
(
name
)
is
str
:
name
=
name
.
encode
(
"utf-8"
)
hash_
=
hashlib
.
sha512
(
name
).
hexdigest
()
key
=
os
.
path
.
join
(
self
.
ca_private
,
hash_
+
self
.
ca_key_ext
)
certificate
=
os
.
path
.
join
(
self
.
ca_certs
,
hash_
+
self
.
ca_crt_ext
)
...
...
slapos/recipe/condor/configure.py
View file @
da4c1acf
...
...
@@ -25,6 +25,7 @@
#
##############################################################################
from
__future__
import
print_function
import
os
import
subprocess
import
time
...
...
@@ -32,9 +33,9 @@ import time
def
submitJob
(
submit
,
submit_file
,
appdir
,
appname
,
sig_install
):
"""Run condor_submit (if needed) for job deployment"""
time
.
sleep
(
10
)
print
"Check if needed to submit %s job's"
%
appname
print
(
"Check if needed to submit %s job's"
%
appname
)
if
not
os
.
path
.
exists
(
sig_install
):
print
"Nothing for install or update...Exited"
print
(
"Nothing for install or update...Exited"
)
return
# '-a', "log = out.log", '-a', "error = error.log",
launch_args
=
submit
,
'-verbose'
,
submit_file
...
...
@@ -42,7 +43,7 @@ def submitJob(submit, submit_file, appdir, appname, sig_install):
stderr
=
subprocess
.
STDOUT
,
cwd
=
appdir
)
result
=
process
.
communicate
()[
0
]
if
process
.
returncode
is
None
or
process
.
returncode
!=
0
:
print
"Failed to execute condor_submit.
\
n
The error was: %s"
%
result
print
(
"Failed to execute condor_submit.
\
n
The error was: %s"
%
result
)
else
:
os
.
unlink
(
sig_install
)
...
...
slapos/recipe/container.py
View file @
da4c1acf
...
...
@@ -25,7 +25,7 @@
#
##############################################################################
import
ConfigP
arser
from
six.moves
import
configp
arser
import
uuid
import
os
import
subprocess
...
...
@@ -47,7 +47,7 @@ class Recipe(GenericSlapRecipe):
container_uuid
=
None
if
os
.
path
.
exists
(
config_filename
):
config
=
ConfigP
arser
.
ConfigParser
()
config
=
configp
arser
.
ConfigParser
()
config
.
read
(
config_filename
)
if
config
.
has_option
(
'requested'
,
'name'
):
container_uuid
=
uuid
.
UUID
(
hex
=
config
.
get
(
'requested'
,
'name'
))
...
...
@@ -68,7 +68,7 @@ class Recipe(GenericSlapRecipe):
self
.
logger
.
info
(
"Putting slapcontainer configuration file..."
)
config
=
ConfigP
arser
.
ConfigParser
()
config
=
configp
arser
.
ConfigParser
()
config
.
add_section
(
'requested'
)
config
.
set
(
'requested'
,
'status'
,
self
.
computer_partition
.
getState
())
...
...
slapos/recipe/erp5testnode/__init__.py
View file @
da4c1acf
...
...
@@ -30,13 +30,14 @@ import json
import
os
from
slapos.recipe.librecipe
import
GenericBaseRecipe
import
six
class
Recipe
(
GenericBaseRecipe
):
def
install
(
self
):
self
.
path_list
=
[]
options
=
self
.
options
.
copy
()
del
options
[
'recipe'
]
CONFIG
=
{
k
.
replace
(
'-'
,
'_'
):
v
for
k
,
v
in
options
.
iteritems
(
)}
CONFIG
=
{
k
.
replace
(
'-'
,
'_'
):
v
for
k
,
v
in
six
.
iteritems
(
options
)}
CONFIG
[
'PATH'
]
=
os
.
environ
[
'PATH'
]
if
self
.
options
[
'instance-dict'
]:
...
...
@@ -44,7 +45,7 @@ class Recipe(GenericBaseRecipe):
config_instance_dict
.
add_section
(
'instance_dict'
)
instance_dict
=
json
.
loads
(
self
.
options
[
'instance-dict'
])
for
k
,
v
in
instance_dict
.
iteritems
(
):
for
k
,
v
in
six
.
iteritems
(
instance_dict
):
config_instance_dict
.
set
(
'instance_dict'
,
k
,
v
)
value
=
io
.
StringIO
()
config_instance_dict
.
write
(
value
)
...
...
slapos/recipe/free_port.py
View file @
da4c1acf
...
...
@@ -29,6 +29,7 @@ from six.moves import configparser
import
os
import
netaddr
import
socket
from
six.moves
import
range
class
Recipe
(
object
):
"""
...
...
@@ -89,7 +90,7 @@ class Recipe(object):
This algorithm thus returns always the same value with the same parameters in
a standard environment.
"""
for
port
in
x
range
(
self
.
minimum
,
self
.
maximum
):
for
port
in
range
(
self
.
minimum
,
self
.
maximum
):
sock
=
socket
.
socket
(
self
.
inet_family
,
socket
.
SOCK_STREAM
)
try
:
sock
.
bind
((
self
.
ip
,
port
))
...
...
slapos/recipe/generic_cloudooo/__init__.py
View file @
da4c1acf
...
...
@@ -27,6 +27,7 @@
from
functools
import
cmp_to_key
import
zc.buildout
from
slapos.recipe.librecipe
import
GenericBaseRecipe
from
six.moves
import
range
@
cmp_to_key
def
compareMimetypeEntryPair
(
a
,
b
):
...
...
slapos/recipe/generic_mysql/mysql.py
View file @
da4c1acf
from
__future__
import
print_function
import
os
import
subprocess
import
time
...
...
@@ -19,31 +20,31 @@ def updateMysql(mysql_upgrade_binary, mysql_binary, mysql_script_file):
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
)
result
=
mysql_upgrade
.
communicate
()[
0
]
if
mysql_upgrade
.
returncode
:
print
"Command %r failed with result:
\
n
%s"
%
(
mysql_upgrade_binary
,
result
)
print
(
"Command %r failed with result:
\
n
%s"
%
(
mysql_upgrade_binary
,
result
)
)
break
print
"MySQL database upgraded with result:
\
n
%s"
%
result
print
(
"MySQL database upgraded with result:
\
n
%s"
%
result
)
mysql
=
subprocess
.
Popen
(
mysql_list
,
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
)
result
=
mysql
.
communicate
(
mysql_script
)[
0
]
if
mysql
.
returncode
:
print
'Command %r failed with:
\
n
%s'
%
(
mysql_list
,
result
)
print
(
'Command %r failed with:
\
n
%s'
%
(
mysql_list
,
result
)
)
break
# import timezone database
mysql_tzinfo_to_sql
=
subprocess
.
Popen
(
mysql_tzinfo_to_sql_list
,
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
timezone_sql
=
mysql_tzinfo_to_sql
.
communicate
()[
0
]
if
mysql_tzinfo_to_sql
.
returncode
!=
0
:
print
'Command %r failed with:
\
n
%s'
%
(
mysql_tzinfo_to_sql_list
,
result
)
print
(
'Command %r failed with:
\
n
%s'
%
(
mysql_tzinfo_to_sql_list
,
result
)
)
break
mysql
=
subprocess
.
Popen
(
mysql_list
+
(
'mysql'
,),
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
)
result
=
mysql
.
communicate
(
timezone_sql
)[
0
]
if
mysql
.
returncode
:
print
'Command %r failed with:
\
n
%s'
%
(
mysql_list
,
result
)
print
(
'Command %r failed with:
\
n
%s'
%
(
mysql_list
,
result
)
)
break
print
'SlapOS initialisation script succesfully applied on database.'
print
(
'SlapOS initialisation script succesfully applied on database.'
)
return
print
'Sleeping for %ss and retrying'
%
sleep
print
(
'Sleeping for %ss and retrying'
%
sleep
)
sys
.
stdout
.
flush
()
sys
.
stderr
.
flush
()
time
.
sleep
(
sleep
)
slapos/recipe/gitinit.py
View file @
da4c1acf
...
...
@@ -30,13 +30,14 @@ import os
from
subprocess
import
check_call
from
slapos.recipe.librecipe
import
GenericBaseRecipe
import
six
class
Recipe
(
GenericBaseRecipe
):
def
install
(
self
):
repolist
=
json
.
loads
(
self
.
options
[
'repos'
])
for
repo
,
desc
in
repolist
.
iteritems
(
):
for
repo
,
desc
in
six
.
iteritems
(
repolist
):
absolute_path
=
os
.
path
.
join
(
self
.
options
[
'base-directory'
],
'%s.git'
%
repo
)
if
not
os
.
path
.
exists
(
absolute_path
):
check_call
([
self
.
options
[
'git-binary'
],
'init'
,
...
...
slapos/recipe/haproxy/__init__.py
View file @
da4c1acf
...
...
@@ -25,6 +25,7 @@
#
##############################################################################
from
slapos.recipe.librecipe
import
GenericBaseRecipe
import
six
class
Recipe
(
GenericBaseRecipe
):
"""
...
...
@@ -95,7 +96,7 @@ class Recipe(GenericBaseRecipe):
# FIXME: maxconn must be provided per-backend, not globally
maxconn
=
self
.
options
[
'maxconn'
]
i
=
0
for
name
,
(
port
,
backend_list
)
in
backend_dict
.
iteritems
(
):
for
name
,
(
port
,
backend_list
)
in
six
.
iteritems
(
backend_dict
):
server_snippet
+=
self
.
substituteTemplate
(
listen_snippet_filename
,
{
'name'
:
name
,
...
...
slapos/recipe/haproxy/haproxy.py
View file @
da4c1acf
from
__future__
import
print_function
import
socket
from
six.moves
import
input
try
:
import
readline
except
ImportError
:
...
...
@@ -7,9 +9,9 @@ except ImportError:
def
haproxyctl
(
socket_path
):
while
True
:
try
:
l
=
raw_
input
(
'> '
)
l
=
input
(
'> '
)
except
EOFError
:
print
print
()
break
if
l
==
'quit'
:
break
...
...
@@ -20,5 +22,5 @@ def haproxyctl(socket_path):
r
=
s
.
recv
(
1024
)
if
not
r
:
break
print
r
print
(
r
)
s
.
close
()
slapos/recipe/lamp/__init__.py
View file @
da4c1acf
...
...
@@ -130,7 +130,7 @@ class BaseRecipe(BaseSlapRecipe):
'template/apache.in'
),
apache_config
))
self
.
path_list
.
append
(
config_file
)
php_ini
=
pkg_resources
.
resource_filename
(
__name__
,
'template/php.ini.in'
)
if
self
.
options
.
has_key
(
'php_ini'
)
:
if
'php_ini'
in
self
.
options
:
php_ini
=
os
.
path
.
join
(
self
.
options
[
'php_ini'
],
'php.ini.in'
)
self
.
path_list
.
append
(
self
.
createConfigurationFile
(
'php.ini'
,
self
.
substituteTemplate
(
php_ini
,
dict
(
tmp_directory
=
self
.
tmp_directory
))))
...
...
@@ -161,8 +161,7 @@ class BaseRecipe(BaseSlapRecipe):
"""Start process which can launch python scripts, move or remove files or
directories when installing software.
"""
if
not
self
.
options
.
has_key
(
'delete'
)
and
not
self
.
options
.
has_key
(
'rename'
)
and
not
\
self
.
options
.
has_key
(
'chmod'
)
and
not
self
.
options
.
has_key
(
'script'
):
if
'delete'
not
in
self
.
options
and
'rename'
not
in
self
.
options
and
'chmod'
not
in
self
.
options
and
'script'
not
in
self
.
options
:
return
""
delete
=
[]
chmod
=
[]
...
...
@@ -172,7 +171,7 @@ class BaseRecipe(BaseSlapRecipe):
argument
=
[
self
.
options
[
'lampconfigure_directory'
].
strip
(),
"-H"
,
mysql_conf
[
'mysql_host'
],
"-P"
,
mysql_conf
[
'mysql_port'
],
"-p"
,
mysql_conf
[
'mysql_password'
],
"-u"
,
mysql_conf
[
'mysql_user'
]]
if
not
self
.
options
.
has_key
(
'file_token'
)
:
if
'file_token'
not
in
self
.
options
:
argument
=
argument
+
[
"-d"
,
mysql_conf
[
'mysql_database'
],
"--table"
,
self
.
options
[
'table_name'
].
strip
(),
"--cond"
,
self
.
options
[
'constraint'
].
strip
()]
...
...
@@ -180,11 +179,11 @@ class BaseRecipe(BaseSlapRecipe):
argument
=
argument
+
[
"-f"
,
self
.
options
[
'file_token'
].
strip
()]
argument
+=
[
"-t"
,
document_root
]
if
self
.
options
.
has_key
(
'delete'
)
:
if
'delete'
in
self
.
options
:
delete
=
[
"delete"
]
for
fname
in
self
.
options
[
'delete'
].
split
(
','
):
delete
.
append
(
fname
.
strip
())
if
self
.
options
.
has_key
(
'rename'
)
:
if
'rename'
in
self
.
options
:
for
fname
in
self
.
options
[
'rename'
].
split
(
','
):
if
fname
.
find
(
"=>"
)
<
0
:
old_name
=
fname
...
...
@@ -194,15 +193,15 @@ class BaseRecipe(BaseSlapRecipe):
else
:
fname
=
fname
.
split
(
"=>"
)
cmd
=
[
"rename"
]
if
self
.
options
.
has_key
(
'rename_chmod'
)
:
if
'rename_chmod'
in
self
.
options
:
cmd
+=
[
"--chmod"
,
self
.
options
[
'rename_chmod'
].
strip
()]
rename
.
append
(
cmd
+
[
fname
[
0
].
strip
(),
fname
[
1
].
strip
()])
rename_list
+=
fname
[
0
]
+
" to "
+
fname
[
1
]
+
" "
if
self
.
options
.
has_key
(
'chmod'
)
:
if
'chmod'
in
self
.
options
:
chmod
=
[
"chmod"
,
self
.
options
[
'mode'
].
strip
()]
for
fname
in
self
.
options
[
'chmod'
].
split
(
','
):
chmod
.
append
(
fname
.
strip
())
if
self
.
options
.
has_key
(
'script'
)
and
\
if
'script'
in
self
.
options
and
\
self
.
options
[
'script'
].
strip
().
endswith
(
".py"
):
data
=
[
"run"
,
self
.
options
[
'script'
].
strip
(),
"-v"
,
mysql_conf
[
'mysql_database'
],
url
,
document_root
]
self
.
path_list
.
extend
(
zc
.
buildout
.
easy_install
.
scripts
(
...
...
@@ -237,7 +236,7 @@ class Simple(BaseRecipe):
if
not
renamed
==
""
:
connectionDict
[
'rename'
]
=
renamed
self
.
setConnectionDict
(
connectionDict
)
if
self
.
options
.
has_key
(
'template'
)
and
self
.
options
.
has_key
(
'configuration'
)
:
if
'template'
in
self
.
options
and
'configuration'
in
self
.
options
:
self
.
createConfiguration
(
self
.
options
[
'template'
],
document_root
,
self
.
options
[
'configuration'
],
mysql_conf
)
return
self
.
path_list
...
...
slapos/recipe/lamp/apache.py
View file @
da4c1acf
from
__future__
import
print_function
import
os
import
sys
import
time
...
...
@@ -10,7 +11,7 @@ def runApache(args):
ready
=
True
for
f
in
conf
.
get
(
'required_path_list'
,
[]):
if
not
os
.
path
.
exists
(
f
):
print
'File %r does not exists, sleeping for %s'
%
(
f
,
sleep
)
print
(
'File %r does not exists, sleeping for %s'
%
(
f
,
sleep
)
)
ready
=
False
if
ready
:
break
...
...
slapos/recipe/lamp/mysql.py
View file @
da4c1acf
from
__future__
import
print_function
import
os
import
subprocess
import
time
...
...
@@ -20,15 +21,15 @@ def runMysql(args):
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
)
result
=
popen
.
communicate
()[
0
]
if
popen
.
returncode
is
None
or
popen
.
returncode
!=
0
:
print
"Failed to initialise server.
\
n
The error was: %s"
%
result
print
"Waiting for %ss and retrying"
%
sleep
print
(
"Failed to initialise server.
\
n
The error was: %s"
%
result
)
print
(
"Waiting for %ss and retrying"
%
sleep
)
time
.
sleep
(
sleep
)
else
:
print
"Mysql properly initialised"
print
(
"Mysql properly initialised"
)
break
else
:
print
"MySQL already initialised"
print
"Starting %r"
%
mysqld_wrapper_list
[
0
]
print
(
"MySQL already initialised"
)
print
(
"Starting %r"
%
mysqld_wrapper_list
[
0
])
sys
.
stdout
.
flush
()
sys
.
stderr
.
flush
()
os
.
execl
(
mysqld_wrapper_list
[
0
],
*
mysqld_wrapper_list
)
...
...
@@ -46,13 +47,13 @@ def updateMysql(args):
if
mysql_upgrade
.
returncode
is
None
:
mysql_upgrade
.
kill
()
if
mysql_upgrade
.
returncode
!=
0
and
not
'is already upgraded'
in
result
:
print
"Command %r failed with result:
\
n
%s"
%
(
mysql_upgrade_list
,
result
)
print
'Sleeping for %ss and retrying'
%
sleep
print
(
"Command %r failed with result:
\
n
%s"
%
(
mysql_upgrade_list
,
result
)
)
print
(
'Sleeping for %ss and retrying'
%
sleep
)
else
:
if
mysql_upgrade
.
returncode
==
0
:
print
"MySQL database upgraded with result:
\
n
%s"
%
result
print
(
"MySQL database upgraded with result:
\
n
%s"
%
result
)
else
:
print
"No need to upgrade MySQL database"
print
(
"No need to upgrade MySQL database"
)
mysql_script
=
conf
.
get
(
'mysql_script'
)
if
mysql_script
:
mysql_list
=
[
conf
[
'mysql_binary'
].
strip
(),
'--no-defaults'
,
'-B'
,
'--user=root'
,
'--socket=%s'
%
conf
[
'socket'
]]
...
...
@@ -62,11 +63,11 @@ def updateMysql(args):
if
mysql
.
returncode
is
None
:
mysql
.
kill
()
if
mysql
.
returncode
!=
0
:
print
'Command %r failed with:
\
n
%s'
%
(
mysql_list
,
result
)
print
'Sleeping for %ss and retrying'
%
sleep
print
(
'Command %r failed with:
\
n
%s'
%
(
mysql_list
,
result
)
)
print
(
'Sleeping for %ss and retrying'
%
sleep
)
else
:
is_succeed
=
True
print
'SlapOS initialisation script succesfully applied on database.'
print
(
'SlapOS initialisation script succesfully applied on database.'
)
sys
.
stdout
.
flush
()
sys
.
stderr
.
flush
()
time
.
sleep
(
sleep
)
slapos/recipe/lamp/runner.py
View file @
da4c1acf
from
__future__
import
print_function
import
sys
import
subprocess
...
...
@@ -8,20 +9,20 @@ def executeRunner(args):
"""
arguments
,
delete
,
rename
,
chmod
,
data
=
args
if
delete
!=
[]:
print
"Calling lampconfigure with 'delete' arguments"
print
(
"Calling lampconfigure with 'delete' arguments"
)
result
=
subprocess
.
Popen
(
arguments
+
delete
)
result
.
wait
()
if
rename
!=
[]:
for
parameters
in
rename
:
print
"Calling lampconfigure with 'rename' arguments"
print
(
"Calling lampconfigure with 'rename' arguments"
)
result
=
subprocess
.
Popen
(
arguments
+
parameters
)
result
.
wait
()
if
chmod
!=
[]:
print
"Calling lampconfigure with 'chmod' arguments"
print
(
"Calling lampconfigure with 'chmod' arguments"
)
result
=
subprocess
.
Popen
(
arguments
+
chmod
)
result
.
wait
()
if
data
!=
[]:
print
"Calling lampconfigure with 'run' arguments"
print
(
"Calling lampconfigure with 'run' arguments"
)
result
=
subprocess
.
Popen
(
arguments
+
data
)
result
.
wait
()
return
slapos/recipe/librecipe/execute.py
View file @
da4c1acf
...
...
@@ -8,6 +8,7 @@ from collections import defaultdict
from
inotify_simple
import
INotify
,
flags
import
six
from
six.moves
import
range
def
_wait_files_creation
(
file_list
):
# Establish a list of directory and subfiles.
...
...
@@ -66,7 +67,7 @@ def generic_exec(args, extra_environ=None, wait_list=None,
else
:
# With chained shebangs, several paths may be inserted at the beginning.
n
=
len
(
args
)
for
i
in
x
range
(
1
+
len
(
running
)
-
n
):
for
i
in
range
(
1
+
len
(
running
)
-
n
):
if
args
==
running
[
i
:
n
+
i
]:
sys
.
exit
(
"Already running with pid %s."
%
pid
)
with
open
(
pidfile
,
'w'
)
as
f
:
...
...
slapos/recipe/mioga/instantiate.py
View file @
da4c1acf
...
...
@@ -25,6 +25,7 @@
#
##############################################################################
from
__future__
import
print_function
import
os
import
pprint
import
re
...
...
@@ -215,7 +216,7 @@ Include conf/extra/httpd-autoindex.conf
if
not
stat
.
S_ISFIFO
(
os
.
stat
(
fifo
).
st_mode
):
raise
Exception
(
"The file "
+
fifo
+
" exists but is not a FIFO."
)
else
:
os
.
mkfifo
(
fifo
,
0600
)
os
.
mkfifo
(
fifo
,
0
o
600
)
site_perl_bin
=
os
.
path
.
join
(
self
.
options
[
'site_perl'
],
'bin'
)
mioga_conf_path
=
os
.
path
.
join
(
mioga_base
,
'conf'
,
'Mioga.conf'
)
...
...
@@ -253,7 +254,7 @@ Include conf/extra/httpd-autoindex.conf
pass
os
.
chdir
(
former_directory
)
print
"Mioga instantiate.py::install finished!"
print
(
"Mioga instantiate.py::install finished!"
)
return
path_list
...
...
slapos/recipe/mysql/mysql.py
View file @
da4c1acf
from
__future__
import
print_function
import
os
import
subprocess
import
time
...
...
@@ -20,15 +21,15 @@ def runMysql(conf):
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
,
cwd
=
conf
[
'cwd'
])
result
=
popen
.
communicate
()[
0
]
if
popen
.
returncode
is
None
or
popen
.
returncode
!=
0
:
print
"Failed to initialise server.
\
n
The error was: %s"
%
result
print
"Waiting for %ss and retrying"
%
sleep
print
(
"Failed to initialise server.
\
n
The error was: %s"
%
result
)
print
(
"Waiting for %ss and retrying"
%
sleep
)
time
.
sleep
(
sleep
)
else
:
print
"Mysql properly initialised"
print
(
"Mysql properly initialised"
)
break
else
:
print
"MySQL already initialised"
print
"Starting %r"
%
mysqld_wrapper_list
[
0
]
print
(
"MySQL already initialised"
)
print
(
"Starting %r"
%
mysqld_wrapper_list
[
0
])
sys
.
stdout
.
flush
()
sys
.
stderr
.
flush
()
os
.
execl
(
mysqld_wrapper_list
[
0
],
*
mysqld_wrapper_list
)
...
...
@@ -45,13 +46,13 @@ def updateMysql(conf):
if
mysql_upgrade
.
returncode
is
None
:
mysql_upgrade
.
kill
()
if
mysql_upgrade
.
returncode
!=
0
and
not
'is already upgraded'
in
result
:
print
"Command %r failed with result:
\
n
%s"
%
(
mysql_upgrade_list
,
result
)
print
'Sleeping for %ss and retrying'
%
sleep
print
(
"Command %r failed with result:
\
n
%s"
%
(
mysql_upgrade_list
,
result
)
)
print
(
'Sleeping for %ss and retrying'
%
sleep
)
else
:
if
mysql_upgrade
.
returncode
==
0
:
print
"MySQL database upgraded with result:
\
n
%s"
%
result
print
(
"MySQL database upgraded with result:
\
n
%s"
%
result
)
else
:
print
"No need to upgrade MySQL database"
print
(
"No need to upgrade MySQL database"
)
mysql_list
=
[
conf
[
'mysql_binary'
].
strip
(),
'--no-defaults'
,
'-B'
,
'--user=root'
,
'--socket=%s'
%
conf
[
'socket'
]]
mysql
=
subprocess
.
Popen
(
mysql_list
,
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
)
...
...
@@ -59,11 +60,11 @@ def updateMysql(conf):
if
mysql
.
returncode
is
None
:
mysql
.
kill
()
if
mysql
.
returncode
!=
0
:
print
'Command %r failed with:
\
n
%s'
%
(
mysql_list
,
result
)
print
'Sleeping for %ss and retrying'
%
sleep
print
(
'Command %r failed with:
\
n
%s'
%
(
mysql_list
,
result
)
)
print
(
'Sleeping for %ss and retrying'
%
sleep
)
else
:
is_succeed
=
True
print
'SlapOS initialisation script succesfully applied on database.'
print
(
'SlapOS initialisation script succesfully applied on database.'
)
sys
.
stdout
.
flush
()
sys
.
stderr
.
flush
()
time
.
sleep
(
sleep
)
slapos/recipe/neoppod.py
View file @
da4c1acf
...
...
@@ -28,6 +28,7 @@ import os
import
shlex
from
zc.buildout
import
UserError
from
.librecipe
import
GenericBaseRecipe
import
six
class
Cluster
(
object
):
...
...
@@ -41,7 +42,7 @@ class Cluster(object):
for
node
in
sorted
(
options
[
'nodes'
].
split
()):
node
=
buildout
[
node
]
node_list
.
append
(
node
)
for
k
,
v
in
result_dict
.
iteritems
(
):
for
k
,
v
in
six
.
iteritems
(
result_dict
):
x
=
node
[
k
]
if
x
:
v
.
append
(
x
)
...
...
slapos/recipe/nosqltestbed/__init__.py
View file @
da4c1acf
...
...
@@ -37,8 +37,8 @@ class NoSQLTestBed(BaseSlapRecipe):
def
_install
(
self
):
self
.
parameter_dict
=
self
.
computer_partition
.
getInstanceParameterDict
()
try
:
entry_point
=
pkg_resources
.
iter_entry_points
(
group
=
'slapos.recipe.nosqltestbed.plugin'
,
name
=
self
.
parameter_dict
.
get
(
'plugin'
,
'kumo'
))
.
next
(
)
entry_point
=
next
(
pkg_resources
.
iter_entry_points
(
group
=
'slapos.recipe.nosqltestbed.plugin'
,
name
=
self
.
parameter_dict
.
get
(
'plugin'
,
'kumo'
)))
plugin_class
=
entry_point
.
load
()
testbed
=
plugin_class
()
...
...
slapos/recipe/random.py
View file @
da4c1acf
...
...
@@ -35,9 +35,11 @@ from __future__ import absolute_import
import
errno
import
os
import
random
import
six
import
string
from
.librecipe
import
GenericBaseRecipe
from
.publish_early
import
volatileOptions
from
six.moves
import
range
class
Integer
(
object
):
"""
...
...
@@ -174,7 +176,10 @@ class Password(object):
fd
=
os
.
open
(
self
.
storage_path
,
os
.
O_CREAT
|
os
.
O_EXCL
|
os
.
O_WRONLY
|
os
.
O_TRUNC
,
0o600
)
try
:
os
.
write
(
fd
,
self
.
passwd
)
passwd
=
self
.
passwd
if
six
.
PY3
and
type
(
passwd
)
is
str
:
passwd
=
passwd
.
encode
(
'utf-8'
)
os
.
write
(
fd
,
passwd
)
finally
:
os
.
close
(
fd
)
if
not
self
.
create_once
:
...
...
slapos/recipe/re6stnet/__init__.py
View file @
da4c1acf
...
...
@@ -34,6 +34,7 @@ import string, random
import
json
import
traceback
from
slapos
import
slap
from
six.moves
import
range
class
Recipe
(
GenericBaseRecipe
):
...
...
@@ -154,7 +155,7 @@ class Recipe(GenericBaseRecipe):
hash_path
=
os
.
path
.
join
(
self
.
options
[
'conf-dir'
],
'%s-hash'
%
length
)
if
not
os
.
path
.
exists
(
hash_path
):
pool
=
string
.
letters
+
string
.
digits
hash_string
=
''
.
join
(
random
.
choice
(
pool
)
for
i
in
x
range
(
length
))
hash_string
=
''
.
join
(
random
.
choice
(
pool
)
for
i
in
range
(
length
))
self
.
writeFile
(
hash_path
,
hash_string
)
else
:
hash_string
=
self
.
readFile
(
hash_path
)
...
...
slapos/recipe/re6stnet/re6stnet.py
View file @
da4c1acf
# -*- coding: utf-8 -*-
import
httplib
import
six.moves.http_client
import
logging
import
json
import
os
...
...
@@ -8,6 +8,7 @@ import slapos
import
traceback
import
logging
from
re6st
import
registry
import
six
log
=
logging
.
getLogger
(
'SLAPOS-RE6STNET'
)
logging
.
basicConfig
(
level
=
logging
.
INFO
)
...
...
@@ -93,7 +94,7 @@ def requestRemoveToken(client, token_base_path):
reference
=
reference_key
.
split
(
'.'
)[
0
]
try
:
result
=
client
.
deleteToken
(
token
)
except
httplib
.
NOT_FOUND
:
except
six
.
moves
.
http_client
.
NOT_FOUND
:
# Token is alread removed.
result
=
True
except
Exception
:
...
...
@@ -128,7 +129,7 @@ def checkService(client, token_base_path, token_json, computer_partition):
return
# Check token status
for
slave_reference
,
token
in
token_dict
.
iteritems
(
):
for
slave_reference
,
token
in
six
.
iteritems
(
token_dict
):
log
.
info
(
"%s %s"
%
(
slave_reference
,
token
))
status_file
=
os
.
path
.
join
(
token_base_path
,
'%s.status'
%
slave_reference
)
if
not
os
.
path
.
exists
(
status_file
):
...
...
slapos/recipe/readline.py
View file @
da4c1acf
...
...
@@ -46,7 +46,7 @@ class Recipe(object):
try
:
with
open
(
storage_path
)
as
f
:
readline
=
f
.
readline
()
except
IOError
,
e
:
except
IOError
as
e
:
if
e
.
errno
!=
errno
.
ENOENT
:
raise
readline
=
None
...
...
slapos/recipe/redis/MyRedis2410.py
View file @
da4c1acf
from
__future__
import
with_statement
import
six
from
six.moves
import
range
from
six.moves
import
zip
"Core exceptions raised by the Redis client"
...
...
@@ -85,7 +88,7 @@ class PythonParser(object):
# no length, read a full line
return
self
.
_fp
.
readline
()[:
-
2
]
except
(
socket
.
error
,
socket
.
timeout
)
,
e
:
except
(
socket
.
error
,
socket
.
timeout
)
as
e
:
raise
ConnectionError
(
"Error while reading from socket: %s"
%
\
(
e
.
args
,))
...
...
@@ -110,7 +113,7 @@ class PythonParser(object):
return
response
# int value
elif
byte
==
':'
:
return
long
(
response
)
return
int
(
response
)
# bulk response
elif
byte
==
'$'
:
length
=
int
(
response
)
...
...
@@ -123,7 +126,7 @@ class PythonParser(object):
length
=
int
(
response
)
if
length
==
-
1
:
return
None
return
[
self
.
read_response
()
for
i
in
x
range
(
length
)]
return
[
self
.
read_response
()
for
i
in
range
(
length
)]
raise
InvalidResponse
(
"Protocol Error"
)
class
HiredisParser
(
object
):
...
...
@@ -151,7 +154,7 @@ class HiredisParser(object):
while
response
is
False
:
try
:
buffer
=
self
.
_sock
.
recv
(
4096
)
except
(
socket
.
error
,
socket
.
timeout
)
,
e
:
except
(
socket
.
error
,
socket
.
timeout
)
as
e
:
raise
ConnectionError
(
"Error while reading from socket: %s"
%
\
(
e
.
args
,))
if
not
buffer
:
...
...
@@ -197,7 +200,7 @@ class Connection(object):
return
try
:
sock
=
self
.
_connect
()
except
socket
.
error
,
e
:
except
socket
.
error
as
e
:
raise
ConnectionError
(
self
.
_error_message
(
e
))
self
.
_sock
=
sock
...
...
@@ -253,7 +256,7 @@ class Connection(object):
self
.
connect
()
try
:
self
.
_sock
.
sendall
(
command
)
except
socket
.
error
,
e
:
except
socket
.
error
as
e
:
self
.
disconnect
()
if
len
(
e
.
args
)
==
1
:
_errno
,
errmsg
=
'UNKNOWN'
,
e
.
args
[
0
]
...
...
@@ -470,7 +473,7 @@ def zset_score_pairs(response, **options):
return
response
score_cast_func
=
options
.
get
(
'score_cast_func'
,
float
)
it
=
iter
(
response
)
return
zip
(
it
,
imap
(
score_cast_func
,
it
))
return
list
(
zip
(
it
,
imap
(
score_cast_func
,
it
)
))
def
int_or_none
(
response
):
if
response
is
None
:
...
...
@@ -513,7 +516,7 @@ class StrictRedis(object):
string_keys_to_dict
(
# these return OK, or int if redis-server is >=1.3.4
'LPUSH RPUSH'
,
lambda
r
:
isinstance
(
r
,
long
)
and
r
or
r
==
'OK'
lambda
r
:
isinstance
(
r
,
int
)
and
r
or
r
==
'OK'
),
string_keys_to_dict
(
'ZSCORE ZINCRBY'
,
float_or_none
),
string_keys_to_dict
(
...
...
@@ -824,7 +827,7 @@ class StrictRedis(object):
def
mset
(
self
,
mapping
):
"Sets each key in the ``mapping`` dict to its corresponding value"
items
=
[]
for
pair
in
mapping
.
iteritems
(
):
for
pair
in
six
.
iteritems
(
mapping
):
items
.
extend
(
pair
)
return
self
.
execute_command
(
'MSET'
,
*
items
)
...
...
@@ -834,7 +837,7 @@ class StrictRedis(object):
none of the keys are already set
"""
items
=
[]
for
pair
in
mapping
.
iteritems
(
):
for
pair
in
six
.
iteritems
(
mapping
):
items
.
extend
(
pair
)
return
self
.
execute_command
(
'MSETNX'
,
*
items
)
...
...
@@ -1218,7 +1221,7 @@ class StrictRedis(object):
raise
RedisError
(
"ZADD requires an equal number of "
"values and scores"
)
pieces
.
extend
(
args
)
for
pair
in
kwargs
.
iteritems
(
):
for
pair
in
six
.
iteritems
(
kwargs
):
pieces
.
append
(
pair
[
1
])
pieces
.
append
(
pair
[
0
])
return
self
.
execute_command
(
'ZADD'
,
name
,
*
pieces
)
...
...
@@ -1383,7 +1386,7 @@ class StrictRedis(object):
def
_zaggregate
(
self
,
command
,
dest
,
keys
,
aggregate
=
None
):
pieces
=
[
command
,
dest
,
len
(
keys
)]
if
isinstance
(
keys
,
dict
):
keys
,
weights
=
keys
.
keys
(),
keys
.
values
(
)
keys
,
weights
=
list
(
keys
.
keys
()),
list
(
keys
.
values
()
)
else
:
weights
=
None
pieces
.
extend
(
keys
)
...
...
@@ -1446,7 +1449,7 @@ class StrictRedis(object):
if
not
mapping
:
raise
DataError
(
"'hmset' with 'mapping' of length 0"
)
items
=
[]
for
pair
in
mapping
.
iteritems
(
):
for
pair
in
six
.
iteritems
(
mapping
):
items
.
extend
(
pair
)
return
self
.
execute_command
(
'HMSET'
,
name
,
*
items
)
...
...
@@ -1540,7 +1543,7 @@ class Redis(StrictRedis):
raise
RedisError
(
"ZADD requires an equal number of "
"values and scores"
)
pieces
.
extend
(
reversed
(
args
))
for
pair
in
kwargs
.
iteritems
(
):
for
pair
in
six
.
iteritems
(
kwargs
):
pieces
.
append
(
pair
[
1
])
pieces
.
append
(
pair
[
0
])
return
self
.
execute_command
(
'ZADD'
,
name
,
*
pieces
)
...
...
slapos/recipe/simplehttpserver/__init__.py
View file @
da4c1acf
...
...
@@ -27,6 +27,7 @@
from
slapos.recipe.librecipe
import
GenericBaseRecipe
import
string
,
random
import
os
from
six.moves
import
range
class
Recipe
(
GenericBaseRecipe
):
...
...
@@ -35,7 +36,7 @@ class Recipe(GenericBaseRecipe):
base_path
=
options
[
'base-path'
]
if
options
.
get
(
'use-hash-url'
,
'True'
)
in
[
'true'
,
'True'
]:
pool
=
string
.
letters
+
string
.
digits
hash_string
=
''
.
join
(
random
.
choice
(
pool
)
for
i
in
x
range
(
64
))
hash_string
=
''
.
join
(
random
.
choice
(
pool
)
for
i
in
range
(
64
))
path
=
os
.
path
.
join
(
base_path
,
hash_string
)
if
os
.
path
.
exists
(
base_path
):
...
...
slapos/recipe/simplehttpserver/simplehttpserver.py
View file @
da4c1acf
# -*- coding: utf-8 -*-
from
SimpleHTTPServer
import
SimpleHTTPRequestHandler
from
BaseHTTPServer
import
HTTPServer
from
six.moves.
SimpleHTTPServer
import
SimpleHTTPRequestHandler
from
six.moves.
BaseHTTPServer
import
HTTPServer
import
ssl
import
os
import
logging
...
...
@@ -46,7 +46,7 @@ class ServerHandler(SimpleHTTPRequestHandler):
name
=
form
[
'path'
].
value
content
=
form
[
'content'
].
value
method
=
'a'
if
form
.
has_key
(
'clear'
)
and
form
[
'clear'
].
value
==
'1'
:
if
'clear'
in
form
and
form
[
'clear'
].
value
==
'1'
:
method
=
'w'
self
.
writeFile
(
name
,
content
,
method
)
self
.
respond
(
200
,
type
=
self
.
headers
[
'Content-Type'
])
...
...
@@ -97,7 +97,7 @@ def run(args):
httpd
=
server
((
host
,
port
),
Handler
)
scheme
=
'http'
if
args
.
has_key
(
'cert-file'
)
and
args
.
has_key
(
'key-file'
)
and
\
if
'cert-file'
in
args
and
'key-file'
in
args
and
\
os
.
path
.
exists
(
args
[
'cert-file'
])
and
os
.
path
.
exists
(
args
[
'key-file'
]):
scheme
=
'https'
httpd
.
socket
=
ssl
.
wrap_socket
(
httpd
.
socket
,
...
...
slapos/recipe/simplelogger.py
View file @
da4c1acf
...
...
@@ -24,6 +24,7 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from
__future__
import
print_function
import
sys
import
time
...
...
@@ -33,8 +34,8 @@ def log(filename):
prefix
=
time
.
strftime
(
'%Y-%m-%d.%H:%M.%s:'
)
with
open
(
filename
,
'a'
)
as
logfile
:
for
line
in
sys
.
stdin
:
print
>>
logfile
,
prefix
,
line
,
print
>>
logfile
,
prefix
,
'------------------------'
print
(
prefix
,
line
,
end
=
' '
,
file
=
logfile
)
print
(
prefix
,
'------------------------'
,
file
=
logfile
)
class
Recipe
(
GenericBaseRecipe
):
...
...
slapos/recipe/softwaretype.py
View file @
da4c1acf
...
...
@@ -28,7 +28,7 @@
import
os
import
sys
import
copy
from
ConfigP
arser
import
ConfigParser
from
six.moves.configp
arser
import
ConfigParser
import
json
import
subprocess
import
slapos.slap
...
...
@@ -38,6 +38,7 @@ import errno
import
re
import
zc.buildout
import
six
class
SlapConfigParser
(
ConfigParser
,
object
):
"""
...
...
@@ -138,9 +139,9 @@ class Recipe:
for
name
,
ip
in
self
.
parameter_dict
[
'ip_list'
]:
if
name
:
return
name
raise
AttributeError
,
"Not network interface found"
raise
AttributeError
(
"Not network interface found"
)
def
mkdir_p
(
self
,
path
,
mode
=
0700
):
def
mkdir_p
(
self
,
path
,
mode
=
0
o
700
):
"""
Creates a directory and its parents, if needed.
NB: If the directory already exists, it does not change its permission.
...
...
@@ -193,7 +194,10 @@ class Recipe:
raise
zc
.
buildout
.
UserError
(
"The specified buildout config file %r does "
"not exist."
%
instance_file_path
)
buildout
=
SlapConfigParser
()
try
:
buildout
=
SlapConfigParser
(
strict
=
False
)
except
TypeError
:
buildout
=
SlapConfigParser
()
with
open
(
instance_file_path
)
as
instance_path
:
buildout
.
readfp
(
instance_path
)
...
...
@@ -231,7 +235,7 @@ class Recipe:
# Copy/paste slap_connection
buildout
.
add_section
(
'slap-connection'
)
for
key
,
value
in
s
elf
.
buildout
[
'slap_connection'
].
iteritems
(
):
for
key
,
value
in
s
ix
.
iteritems
(
self
.
buildout
[
'slap_connection'
]
):
# XXX: Waiting for SlapBaseRecipe to use dash instead of underscores
buildout
.
set
(
'slap-connection'
,
key
.
replace
(
'_'
,
'-'
),
value
)
# XXX: Needed for lxc. Use non standard API
...
...
slapos/recipe/switch_softwaretype.py
View file @
da4c1acf
...
...
@@ -26,6 +26,7 @@
##############################################################################
import
os
,
subprocess
,
sys
import
six
class
Recipe
:
...
...
@@ -41,7 +42,7 @@ class Recipe:
# XXX-Antoine: We gotta find a better way to do this. I tried to check
# out how slapgrid-cp was running buildout. But it is worse than that.
args
=
sys
.
argv
[:]
for
x
in
s
elf
.
buildout
[
"slap-connection"
].
iteritems
(
):
for
x
in
s
ix
.
iteritems
(
self
.
buildout
[
"slap-connection"
]
):
args
.
append
(
"slap-connection:%s=%s"
%
x
)
for
x
in
"directory"
,
"eggs-directory"
,
"develop-eggs-directory"
:
args
.
append
(
"buildout:%s=%s"
%
(
x
,
self
.
buildout
[
"buildout"
][
x
]))
...
...
slapos/recipe/trac.py
View file @
da4c1acf
...
...
@@ -32,6 +32,7 @@ import shutil
import
json
from
slapos.recipe.librecipe
import
GenericBaseRecipe
import
six
class
Recipe
(
GenericBaseRecipe
):
...
...
@@ -141,7 +142,7 @@ class Recipe(GenericBaseRecipe):
self
.
logger
.
info
(
"Finished initializing %s reposiroty"
%
svn_repo
)
repolist
=
json
.
loads
(
self
.
options
.
get
(
'git-project-list'
,
'{}'
))
for
repo
,
desc
in
repolist
.
iteritems
(
):
for
repo
,
desc
in
six
.
iteritems
(
repolist
):
absolute_path
=
os
.
path
.
join
(
self
.
options
[
'git-dir'
],
'%s.git'
%
repo
)
if
not
os
.
path
.
exists
(
absolute_path
):
self
.
logger
.
info
(
"Initializing %s GIT repository..."
%
repo
)
...
...
slapos/recipe/zabbixagent/svcdaemon.py
View file @
da4c1acf
from
__future__
import
print_function
import
os
import
subprocess
import
time
...
...
@@ -16,7 +17,7 @@ def get_pid(filename):
pid_file
=
None
def
sig_handler
(
s
,
frame
):
print
"Killing on signal %s:"
%
s
,
print
(
"Killing on signal %s:"
%
s
,
end
=
' '
)
global
pid_file
if
pid_file
is
not
None
:
pid
=
get_pid
(
pid_file
)
...
...
@@ -33,11 +34,11 @@ def sig_handler(s, frame):
except
Exception
:
pass
else
:
print
'with SIGKILL...'
,
print
(
'with SIGKILL...'
,
end
=
' '
)
os
.
kill
(
pid
,
signal
.
SIGKILL
)
else
:
raise
ValueError
(
'Pid is none.'
)
print
'done.'
print
(
'done.'
)
sys
.
exit
(
0
)
signal
.
signal
(
signal
.
SIGINT
,
sig_handler
)
...
...
@@ -51,7 +52,7 @@ def svcdaemon(args):
global
pid_file
pid_file
=
args
[
0
][
'pid_file'
]
subprocess
.
check_call
(
real_binary
)
print
'Started %r'
%
real_binary
print
(
'Started %r'
%
real_binary
)
while
True
:
time
.
sleep
(
5
)
pid
=
get_pid
(
pid_file
)
...
...
slapos/recipe/zero_knowledge.py
View file @
da4c1acf
...
...
@@ -25,7 +25,7 @@
#
##############################################################################
import
ConfigP
arser
import
six.moves.configp
arser
import
os
import
zc.buildout
...
...
@@ -53,7 +53,7 @@ class WriteRecipe(GenericBaseRecipe):
def
install
(
self
):
# Set up the parser, and write config file if needed
self
.
parser
=
ConfigP
arser
.
ConfigParser
()
self
.
parser
=
six
.
moves
.
configp
arser
.
ConfigParser
()
try
:
self
.
parser
.
read
(
self
.
path
)
#clean_options(options)
...
...
@@ -63,7 +63,7 @@ class WriteRecipe(GenericBaseRecipe):
with
open
(
self
.
path
,
'w'
)
as
file
:
self
.
parser
.
write
(
file
)
# If the file or section do not exist
except
(
ConfigP
arser
.
NoSectionError
,
IOError
)
as
e
:
except
(
six
.
moves
.
configp
arser
.
NoSectionError
,
IOError
)
as
e
:
self
.
full_install
()
def
full_install
(
self
):
...
...
@@ -94,7 +94,7 @@ class ReadRecipe(GenericBaseRecipe):
self
.
path
=
options
[
'file-path'
].
strip
()
# Set up the parser, and write config file if needed
self
.
parser
=
ConfigP
arser
.
ConfigParser
()
self
.
parser
=
six
.
moves
.
configp
arser
.
ConfigParser
()
if
os
.
path
.
exists
(
self
.
path
):
self
.
parser
.
read
(
self
.
path
)
for
section
in
self
.
parser
.
sections
():
...
...
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