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
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
Carlos Ramos Carreño
slapos.core
Commits
293ee237
Commit
293ee237
authored
Oct 03, 2012
by
Cédric de Saint Martin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make main entry point usable
parent
d03a487a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
34 deletions
+28
-34
slapos/entry.py
slapos/entry.py
+28
-34
No files found.
slapos/entry.py
View file @
293ee237
...
@@ -41,6 +41,9 @@ from slapos.grid.svcbackend import supervisord
...
@@ -41,6 +41,9 @@ from slapos.grid.svcbackend import supervisord
from
slapos.grid.svcbackend
import
supervisorctl
from
slapos.grid.svcbackend
import
supervisorctl
from
slapos.register.register
import
main
as
register
from
slapos.register.register
import
main
as
register
GLOBAL_SLAPOS_CONFIGURATION
=
'/etc/opt/slapos/slapos.cfg'
USER_SLAPOS_CONFIGURATION
=
'~/.slapos/slapos.cfg'
class
EntryPointNotImplementedError
(
NotImplementedError
):
class
EntryPointNotImplementedError
(
NotImplementedError
):
def
__init__
(
self
,
*
args
,
**
kw_args
):
def
__init__
(
self
,
*
args
,
**
kw_args
):
NotImplementedError
.
__init__
(
self
,
*
args
,
**
kw_args
)
NotImplementedError
.
__init__
(
self
,
*
args
,
**
kw_args
)
...
@@ -50,6 +53,9 @@ def checkSlaposCfg ():
...
@@ -50,6 +53,9 @@ def checkSlaposCfg ():
Check if a slapos configuration file was given as a argument.
Check if a slapos configuration file was given as a argument.
If a slapos configuration file is given it return True else False
If a slapos configuration file is given it return True else False
"""
"""
# XXX-Cedric: dangerous but quick way to achieve way to not provide
# configuration file for each command without changing underlying code.
# It the long term, it should be done in a better way (no guessing).
for
element
in
sys
.
argv
:
for
element
in
sys
.
argv
:
if
'.cfg'
in
element
:
if
'.cfg'
in
element
:
if
os
.
path
.
exists
(
element
):
if
os
.
path
.
exists
(
element
):
...
@@ -86,47 +92,39 @@ def call(fun, config=False, option=[]):
...
@@ -86,47 +92,39 @@ def call(fun, config=False, option=[]):
if
not
checkSlaposCfg
():
if
not
checkSlaposCfg
():
sys
.
argv
=
[
sys
.
argv
[
0
]]
+
[
config
]
+
sys
.
argv
[
1
:]
sys
.
argv
=
[
sys
.
argv
[
0
]]
+
[
config
]
+
sys
.
argv
[
1
:]
fun
()
fun
()
sys
.
exit
(
0
)
def
showUsage
():
def
dispatch
(
command
,
is_node_command
):
# We are out of option. We have to admit it: no other option than error.
# XXX Real error message
sys
.
exit
(
1
)
def
dispatch
(
command
,
is_node
):
""" Dispatch to correct SlapOS module.
""" Dispatch to correct SlapOS module.
Here we could use introspection to get rid of the big "if" statements,
Here we could use introspection to get rid of the big "if" statements,
but we want to control every input.
but we want to control every input.
Here we give default option and configuration file if they are needed
Here we give default option and configuration file if they are needed, i.e
If configuration file is not given: define it arbitrarily, and so on.
"""
"""
# XXX console_config =
if
is_node_command
:
if
is_node
:
if
command
==
'register'
:
config
=
'/etc/opt/slapos/slapos.cfg'
if
command
in
'register'
:
call
(
register
)
call
(
register
)
elif
command
==
'software'
:
elif
command
==
'software'
:
call
(
software
,
config
=
config
,
call
(
software
,
config
=
GLOBAL_SLAPOS_CONFIGURATION
,
option
=
[
'--logfile /opt/slapos/slapgrid-sr.log'
,
option
=
[
'--pidfile /opt/slapos/slapgrid-sr.pid'
,
'-c'
])
'--pidfile /opt/slapos/slapgrid-sr.pid'
])
elif
command
==
'instance'
:
elif
command
==
'instance'
:
call
(
instance
,
config
=
config
,
call
(
instance
,
config
=
GLOBAL_SLAPOS_CONFIGURATION
,
option
=
[
'--logfile /opt/slapos/slapgrid-cp.log'
,
option
=
[
'--pidfile /opt/slapos/slapgrid-cp.pid'
,
'-c'
])
'--pidfile /opt/slapos/slapgrid-cp.pid'
])
elif
command
==
'report'
:
elif
command
==
'report'
:
call
(
report
,
config
=
config
,
call
(
report
,
config
=
GLOBAL_SLAPOS_CONFIGURATION
,
option
=
[
'--
logfile /opt/slapos/slapgrid-ur.log
'
])
option
=
[
'--
pidfile /opt/slapos/slapgrid-ur.pid'
,
'-c
'
])
elif
command
==
'bang'
:
elif
command
==
'bang'
:
call
(
bang
,
config
=
True
)
call
(
bang
,
config
=
True
)
elif
command
==
'format'
:
elif
command
==
'format'
:
call
(
format
,
config
=
config
,
call
(
format
,
config
=
GLOBAL_SLAPOS_CONFIGURATION
,
option
=
[
'--log_file /opt/slapos/slapformat.log'
])
option
=
[
'--log_file /opt/slapos/slapformat.log'
])
elif
command
in
[
'start'
,
'stop'
,
'status'
,
'tail'
]:
elif
command
in
[
'start'
,
'stop'
,
'status'
,
'tail'
]:
supervisord
()
supervisord
()
supervisorctl
()
supervisorctl
()
else
:
else
:
supervisord
()
return
False
elif
command
==
'request'
:
elif
command
==
'request'
:
config
=
'~/.slapos/slapos.cfg'
call
(
request
,
config
=
USER_SLAPOS_CONFIGURATION
)
call
(
request
,
config
=
config
)
elif
command
==
'supply'
:
elif
command
==
'supply'
:
raise
EntryPointNotImplementedError
(
command
)
raise
EntryPointNotImplementedError
(
command
)
elif
command
==
'start'
:
elif
command
==
'start'
:
...
@@ -143,16 +141,17 @@ def main():
...
@@ -143,16 +141,17 @@ def main():
Main entry point of SlapOS Node. Used to dispatch commands to python
Main entry point of SlapOS Node. Used to dispatch commands to python
module responsible of the operation.
module responsible of the operation.
"""
"""
description
=
"XXX TODO"
# XXX-Cedric: add "description" for parser.
# Parse arguments
# Parse arguments
parser
=
argparse
.
ArgumentParser
(
description
=
description
)
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'command'
)
parser
.
add_argument
(
'command'
)
# XXX-Cedric: "slapos node" should display "supervisorctl status".
# Currently it does nothing
parser
.
add_argument
(
'argument_list'
,
nargs
=
argparse
.
REMAINDER
)
parser
.
add_argument
(
'argument_list'
,
nargs
=
argparse
.
REMAINDER
)
# If "node" arg is the first: we strip it and set a switch
# If "node" arg is the first: we strip it and set a switch
# XXX do it with argparse
if
len
(
sys
.
argv
)
>
1
and
sys
.
argv
[
1
]
==
"node"
:
if
len
(
sys
.
argv
)
>
1
and
sys
.
argv
[
1
]
==
"node"
:
sys
.
argv
=
sys
.
argv
[
1
:]
sys
.
argv
=
sys
.
argv
[
1
:]
is_node
=
True
is_node
=
True
else
:
else
:
is_node
=
False
is_node
=
False
...
@@ -163,14 +162,9 @@ def main():
...
@@ -163,14 +162,9 @@ def main():
command_line
.
extend
(
namespace
.
argument_list
)
command_line
.
extend
(
namespace
.
argument_list
)
sys
.
argv
=
command_line
sys
.
argv
=
command_line
dispatch
(
namespace
.
command
,
is_node
)
# If configuration file is not given: define it arbitrarily
# If client commands: use ~/.slapos.cfg
# If node commands: use /etc/opt/slapos/slapos.cfg
# XXX TODO
try
:
try
:
if
not
dispatch
(
namespace
.
command
,
is_node
):
if
not
dispatch
(
namespace
.
command
,
is_node
):
parser
.
print_help
()
parser
.
print_help
()
sys
.
exit
(
1
)
except
EntryPointNotImplementedError
,
exception
:
except
EntryPointNotImplementedError
,
exception
:
# XXX more graceful
print
'Not yet implemented: %s. Please use old-style commands.'
%
exception
print
'Not implemented: %s'
%
exception
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