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
Hardik Juneja
slapos.core
Commits
6583f9fd
Commit
6583f9fd
authored
Aug 21, 2012
by
Cédric de Saint Martin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Begin to write slapos command dispatcher (draft)
parent
560385d5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
94 additions
and
13 deletions
+94
-13
setup.py
setup.py
+3
-1
slapos/entry.py
slapos/entry.py
+91
-12
No files found.
setup.py
View file @
6583f9fd
...
...
@@ -47,6 +47,9 @@ setup(name=name,
# accessing templates
entry_points
=
{
'console_scripts'
:
[
# One entry point to control them all
'slapos = slapos.entry:main'
,
# Deprecated entry points
'slapconsole = slapos.console:run'
,
'slapos-request = slapos.console:request'
,
'slapformat = slapos.format:main'
,
...
...
@@ -58,7 +61,6 @@ setup(name=name,
'slapgrid-supervisord = slapos.grid.svcbackend:supervisord'
,
'slapproxy = slapos.proxy:main'
,
'bang = slapos.bang:main'
,
'slapos = slapos.entry:main'
,
]
},
test_suite
=
"slapos.tests"
,
...
...
slapos/entry.py
View file @
6583f9fd
...
...
@@ -26,19 +26,98 @@
#
##############################################################################
import
argparse
import
sys
from
register.register
import
main
as
node_register
from
slapos.bang
import
main
as
bang
from
slapos.console
import
run
as
console
from
slapos.console
import
request
as
request
from
slapos.format
import
main
as
format
from
slapos.grid.slapgrid
import
runComputerPartition
as
instance
from
slapos.grid.slapgrid
import
runSoftwareRelease
as
software
from
slapos.grid.slapgrid
import
runUsageReport
as
report
from
slapos.grid.svcbackend
import
supervisord
from
slapos.grid.svcbackend
import
supervisorctl
from
slapos.register.register
import
main
as
register
class
EntryPointNotImplementedError
(
NotImplementedError
):
def
__init__
(
self
,
*
args
,
**
kw_args
):
NotImplementedError
.
__init__
(
self
,
*
args
,
**
kw_args
)
def
showUsage
():
# 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.
Here we could use introspection to get rid of the big "if" statements,
but we want to control every input.
"""
if
is_node
:
if
command
in
'register'
:
register
()
elif
command
==
'software'
:
software
()
elif
command
==
'instance'
:
instance
()
elif
command
==
'report'
:
report
()
elif
command
==
'bang'
:
bang
()
elif
command
==
'format'
:
format
()
elif
command
in
[
'start'
,
'stop'
,
'status'
,
'tail'
]:
supervisord
()
supervisorctl
()
else
:
supervisord
()
elif
command
==
'request'
:
request
()
elif
command
==
'supply'
:
raise
EntryPointNotImplementedError
(
command
)
elif
command
==
'start'
:
raise
EntryPointNotImplementedError
(
command
)
elif
command
==
'stop'
:
raise
EntryPointNotImplementedError
(
command
)
elif
command
==
'console'
:
console
()
else
:
return
False
def
main
():
if
len
(
sys
.
argv
)
<
3
:
print
"Usage: slapos node register NODE_NAME [options]"
print
"%s: error: Incorrect number of arguments"
%
sys
.
argv
[
0
]
return
0
"Run default configuration."
if
sys
.
argv
[
1
]
==
"node"
and
sys
.
argv
[
2
]
==
"register"
:
sys
.
argv
=
sys
.
argv
[
2
:]
node_register
()
else
:
print
"Usage: slapos node register NODE_NAME [options]"
print
"%s: error: Incorrect arguments"
%
sys
.
argv
[
0
]
"""
Main entry point of SlapOS Node. Used to dispatch commands to python
module responsible of the operation.
"""
description
=
"XXX TODO"
# Parse arguments
parser
=
argparse
.
ArgumentParser
(
description
=
description
)
parser
.
add_argument
(
'command'
)
parser
.
add_argument
(
'argument_list'
,
nargs
=
argparse
.
REMAINDER
)
# 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"
:
sys
.
argv
=
sys
.
argv
[
1
:]
is_node
=
True
else
:
is_node
=
False
namespace
=
parser
.
parse_args
()
# Set sys.argv for the sub-entry point that we will call
command_line
=
[
namespace
.
command
]
command_line
.
extend
(
namespace
.
argument_list
)
sys
.
argv
=
command_line
# 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
:
if
not
dispatch
(
namespace
.
command
,
is_node
):
parser
.
print_help
()
except
EntryPointNotImplementedError
,
exception
:
# XXX more graceful
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