Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Rafael Monnerat
slapos.core
Commits
8cedfd1f
Commit
8cedfd1f
authored
Aug 10, 2011
by
Antoine Catton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert the report and promises factorization of code
parent
02bd813a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
50 deletions
+42
-50
slapos/grid/slapgrid.py
slapos/grid/slapgrid.py
+42
-50
No files found.
slapos/grid/slapgrid.py
View file @
8cedfd1f
...
@@ -64,8 +64,6 @@ MANDATORY_PARAMETER_LIST = [
...
@@ -64,8 +64,6 @@ MANDATORY_PARAMETER_LIST = [
'software_root'
,
'software_root'
,
]
]
DEFAULT_PROMISE_TIMEOUT
=
3
def
parseArgumentTupleAndReturnSlapgridObject
(
*
argument_tuple
):
def
parseArgumentTupleAndReturnSlapgridObject
(
*
argument_tuple
):
"""Parses arguments either from command line, from method parameters or from
"""Parses arguments either from command line, from method parameters or from
...
@@ -109,7 +107,7 @@ def parseArgumentTupleAndReturnSlapgridObject(*argument_tuple):
...
@@ -109,7 +107,7 @@ def parseArgumentTupleAndReturnSlapgridObject(*argument_tuple):
parser
.
add_argument
(
"-v"
,
"--verbose"
,
action
=
"store_true"
,
default
=
False
,
parser
.
add_argument
(
"-v"
,
"--verbose"
,
action
=
"store_true"
,
default
=
False
,
help
=
"Be verbose."
)
help
=
"Be verbose."
)
parser
.
add_argument
(
"--promise-timeout"
,
parser
.
add_argument
(
"--promise-timeout"
,
type
=
int
,
default
=
DEFAULT_PROMISE_TIMEOUT
,
type
=
int
,
default
=
3
,
help
=
"Promise timeout in seconds."
)
help
=
"Promise timeout in seconds."
)
parser
.
add_argument
(
"configuration_file"
,
nargs
=
1
,
type
=
argparse
.
FileType
(),
parser
.
add_argument
(
"configuration_file"
,
nargs
=
1
,
type
=
argparse
.
FileType
(),
help
=
"SlapOS configuration file."
)
help
=
"SlapOS configuration file."
)
...
@@ -275,7 +273,7 @@ class Slapgrid(object):
...
@@ -275,7 +273,7 @@ class Slapgrid(object):
master_ca_file
=
None
,
master_ca_file
=
None
,
certificate_repository_path
=
None
,
certificate_repository_path
=
None
,
console
=
False
,
console
=
False
,
promise_timeout
=
DEFAULT_PROMISE_TIMEOUT
):
promise_timeout
=
3
):
"""Makes easy initialisation of class parameters"""
"""Makes easy initialisation of class parameters"""
# Parses arguments
# Parses arguments
self
.
software_root
=
os
.
path
.
abspath
(
software_root
)
self
.
software_root
=
os
.
path
.
abspath
(
software_root
)
...
@@ -302,7 +300,7 @@ class Slapgrid(object):
...
@@ -302,7 +300,7 @@ class Slapgrid(object):
os
.
path
.
join
(
self
.
instance_etc_directory
,
'supervisord.conf.d'
)
os
.
path
.
join
(
self
.
instance_etc_directory
,
'supervisord.conf.d'
)
self
.
console
=
console
self
.
console
=
console
self
.
buildout
=
buildout
self
.
buildout
=
buildout
self
.
promise_timeout
=
DEFAULT_PROMISE_TIMEOUT
self
.
promise_timeout
=
promise_timeout
def
checkEnvironmentAndCreateStructure
(
self
):
def
checkEnvironmentAndCreateStructure
(
self
):
"""Checks for software_root and instance_root existence, then creates
"""Checks for software_root and instance_root existence, then creates
...
@@ -477,14 +475,22 @@ class Slapgrid(object):
...
@@ -477,14 +475,22 @@ class Slapgrid(object):
# Get the list of promises
# Get the list of promises
promise_dir
=
os
.
path
.
join
(
instance_path
,
'etc'
,
'promise'
)
promise_dir
=
os
.
path
.
join
(
instance_path
,
'etc'
,
'promise'
)
if
os
.
path
.
exists
(
promise_dir
)
and
os
.
path
.
isdir
(
promise_dir
):
if
os
.
path
.
exists
(
promise_dir
)
and
os
.
path
.
isdir
(
promise_dir
):
commands_to_run
=
[
os
.
path
.
join
(
promise_dir
,
command
)
for
command
in
os
.
listdir
(
promise_dir
)]
cwd
=
instance_path
cwd
=
instance_path
promises_list
=
os
.
listdir
(
promise_dir
)
# Check whether every promise is kept
# Check whether every promise is kept
for
process_handler
,
command
in
\
for
promise
in
promises_list
:
self
.
_runCommandsAsUserAndYieldPopen
(
commands_to_run
,
(
uid
,
gid
),
cwd
):
command
=
os
.
path
.
join
(
promise_dir
,
promise
)
kw
=
dict
()
if
not
self
.
console
:
kw
.
update
(
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
)
process_handler
=
SlapPopen
(
command
,
preexec_fn
=
lambda
:
dropPrivileges
(
uid
,
gid
),
cwd
=
cwd
,
env
=
None
,
**
kw
)
time
.
sleep
(
self
.
promise_timeout
)
time
.
sleep
(
self
.
promise_timeout
)
...
@@ -519,23 +525,6 @@ class Slapgrid(object):
...
@@ -519,23 +525,6 @@ class Slapgrid(object):
return
False
return
False
def
_runCommandsAsUserAndYieldPopen
(
self
,
commands_list
,
user
,
cwd
):
uid
,
gid
=
user
for
command
in
commands_list
:
kw
=
dict
()
if
not
self
.
console
:
kw
.
update
(
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
)
process_handler
=
SlapPopen
(
command
,
preexec_fn
=
lambda
:
dropPrivileges
(
uid
,
gid
),
cwd
=
cwd
,
env
=
None
,
**
kw
)
yield
(
process_handler
,
command
)
def
agregateAndSendUsage
(
self
):
def
agregateAndSendUsage
(
self
):
"""Will agregate usage from each Computer Partition.
"""Will agregate usage from each Computer Partition.
"""
"""
...
@@ -558,13 +547,6 @@ class Slapgrid(object):
...
@@ -558,13 +547,6 @@ class Slapgrid(object):
else
:
else
:
script_list_to_run
=
[]
script_list_to_run
=
[]
uid
,
gid
=
None
,
None
stat_info
=
os
.
stat
(
instance_path
)
#stat sys call to get statistics informations
uid
=
stat_info
.
st_uid
gid
=
stat_info
.
st_gid
#We now generate the pseudorandom name for the xml file
#We now generate the pseudorandom name for the xml file
# and we add it in the invocation_list
# and we add it in the invocation_list
f
=
tempfile
.
NamedTemporaryFile
()
f
=
tempfile
.
NamedTemporaryFile
()
...
@@ -573,19 +555,30 @@ class Slapgrid(object):
...
@@ -573,19 +555,30 @@ class Slapgrid(object):
name_xml
)
name_xml
)
failed_script_list
=
[]
failed_script_list
=
[]
for
script
in
script_list_to_run
:
commands_to_run
=
[
(
os
.
path
.
join
(
instance_path
,
'etc'
,
'report'
,
script
),
invocation_list
=
[]
path_to_slapreport
,
invocation_list
.
append
(
os
.
path
.
join
(
instance_path
,
'etc'
,
'report'
,
)
script
))
for
script
in
script_list_to_run
]
#We add the xml_file name in the invocation_list
#f = tempfile.NamedTemporaryFile()
cwd
=
os
.
path
.
join
(
instance_path
,
'etc'
,
'report'
)
#name_xml = '%s.%s' % ('slapreport', os.path.basename(f.name))
#path_to_slapreport = os.path.join(instance_path, 'var', name_xml)
for
process_handler
,
command
in
\
self
.
_runCommandsAsUserAndYieldPopen
(
commands_to_run
,
invocation_list
.
append
(
path_to_slapreport
)
(
uid
,
gid
),
cwd
):
#Dropping privileges
uid
,
gid
=
None
,
None
stat_info
=
os
.
stat
(
instance_path
)
#stat sys call to get statistics informations
uid
=
stat_info
.
st_uid
gid
=
stat_info
.
st_gid
kw
=
dict
()
if
not
self
.
console
:
kw
.
update
(
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
)
process_handler
=
SlapPopen
(
invocation_list
,
preexec_fn
=
lambda
:
dropPrivileges
(
uid
,
gid
),
cwd
=
os
.
path
.
join
(
instance_path
,
'etc'
,
'report'
),
env
=
None
,
**
kw
)
result
=
process_handler
.
communicate
()[
0
]
result
=
process_handler
.
communicate
()[
0
]
if
self
.
console
:
if
self
.
console
:
result
=
'Please consult messages above'
result
=
'Please consult messages above'
...
@@ -593,10 +586,9 @@ class Slapgrid(object):
...
@@ -593,10 +586,9 @@ class Slapgrid(object):
process_handler
.
kill
()
process_handler
.
kill
()
if
process_handler
.
returncode
!=
0
:
if
process_handler
.
returncode
!=
0
:
clean_run
=
False
clean_run
=
False
failed_script_list
.
append
(
"Script %r failed with %s."
%
(
script
,
failed_script_list
.
append
(
"Script %r failed with %s."
%
(
script
,
result
))
result
))
logger
.
warning
(
"Failed to run %r, the result was.
\
n
%s"
%
logger
.
warning
(
"Failed to run %r, the result was.
\
n
%s"
%
(
command
,
result
))
(
invocation_list
,
result
))
if
len
(
failed_script_list
):
if
len
(
failed_script_list
):
computer_partition
.
error
(
'
\
n
'
.
join
(
failed_script_list
))
computer_partition
.
error
(
'
\
n
'
.
join
(
failed_script_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