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
Gabriel Monnerat
slapos.core
Commits
d134c8ef
Commit
d134c8ef
authored
Apr 29, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
naming consistency between arguments, configuration parser, merged
options, specific configuration instances.
parent
78fc0861
Changes
30
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
30 changed files
with
246 additions
and
242 deletions
+246
-242
slapos/bang.py
slapos/bang.py
+7
-7
slapos/cache.py
slapos/cache.py
+2
-2
slapos/cli/bang.py
slapos/cli/bang.py
+2
-2
slapos/cli/cache.py
slapos/cli/cache.py
+2
-2
slapos/cli/config.py
slapos/cli/config.py
+3
-3
slapos/cli/console.py
slapos/cli/console.py
+3
-3
slapos/cli/format.py
slapos/cli/format.py
+5
-5
slapos/cli/register.py
slapos/cli/register.py
+3
-3
slapos/cli/remove.py
slapos/cli/remove.py
+3
-3
slapos/cli/request.py
slapos/cli/request.py
+4
-4
slapos/cli/slapgrid.py
slapos/cli/slapgrid.py
+2
-2
slapos/cli/supervisorctl.py
slapos/cli/supervisorctl.py
+2
-2
slapos/cli/supervisord.py
slapos/cli/supervisord.py
+2
-2
slapos/cli/supply.py
slapos/cli/supply.py
+3
-3
slapos/cli_legacy/bang.py
slapos/cli_legacy/bang.py
+3
-3
slapos/cli_legacy/cache.py
slapos/cli_legacy/cache.py
+3
-3
slapos/cli_legacy/console.py
slapos/cli_legacy/console.py
+3
-2
slapos/cli_legacy/entry.py
slapos/cli_legacy/entry.py
+19
-19
slapos/cli_legacy/format.py
slapos/cli_legacy/format.py
+7
-7
slapos/cli_legacy/register.py
slapos/cli_legacy/register.py
+3
-3
slapos/cli_legacy/remove.py
slapos/cli_legacy/remove.py
+3
-2
slapos/cli_legacy/request.py
slapos/cli_legacy/request.py
+4
-3
slapos/cli_legacy/slapgrid.py
slapos/cli_legacy/slapgrid.py
+3
-3
slapos/cli_legacy/supply.py
slapos/cli_legacy/supply.py
+3
-2
slapos/cli_legacy/util.py
slapos/cli_legacy/util.py
+3
-3
slapos/client.py
slapos/client.py
+20
-19
slapos/format.py
slapos/format.py
+75
-75
slapos/grid/slapgrid.py
slapos/grid/slapgrid.py
+4
-5
slapos/register/register.py
slapos/register/register.py
+42
-42
slapos/tests/entry.py
slapos/tests/entry.py
+8
-8
No files found.
slapos/bang.py
View file @
d134c8ef
...
...
@@ -31,15 +31,15 @@
import
slapos.slap.slap
def
do_bang
(
config
,
message
):
computer_id
=
config
.
get
(
'slapos'
,
'computer_id'
)
master_url
=
config
.
get
(
'slapos'
,
'master_url'
)
if
config
.
has_option
(
'slapos'
,
'key_file'
):
key_file
=
config
.
get
(
'slapos'
,
'key_file'
)
def
do_bang
(
config
p
,
message
):
computer_id
=
config
p
.
get
(
'slapos'
,
'computer_id'
)
master_url
=
config
p
.
get
(
'slapos'
,
'master_url'
)
if
config
p
.
has_option
(
'slapos'
,
'key_file'
):
key_file
=
config
p
.
get
(
'slapos'
,
'key_file'
)
else
:
key_file
=
None
if
config
.
has_option
(
'slapos'
,
'cert_file'
):
cert_file
=
config
.
get
(
'slapos'
,
'cert_file'
)
if
config
p
.
has_option
(
'slapos'
,
'cert_file'
):
cert_file
=
config
p
.
get
(
'slapos'
,
'cert_file'
)
else
:
cert_file
=
None
slap
=
slapos
.
slap
.
slap
()
...
...
slapos/cache.py
View file @
d134c8ef
...
...
@@ -15,8 +15,8 @@ def maybe_md5(s):
return
re
.
match
(
'[0-9a-f]{32}'
,
s
)
def
do_lookup
(
config
,
software_url
):
cache_dir
=
config
.
get
(
'networkcache'
,
'download-binary-dir-url'
)
def
do_lookup
(
config
p
,
software_url
):
cache_dir
=
config
p
.
get
(
'networkcache'
,
'download-binary-dir-url'
)
if
maybe_md5
(
software_url
):
md5
=
software_url
...
...
slapos/cli/bang.py
View file @
d134c8ef
...
...
@@ -17,5 +17,5 @@ class BangCommand(ConfigCommand):
return
ap
def
take_action
(
self
,
args
):
config
=
self
.
fetch_config
(
args
)
do_bang
(
config
,
args
.
message
)
config
p
=
self
.
fetch_config
(
args
)
do_bang
(
config
p
,
args
.
message
)
slapos/cli/cache.py
View file @
d134c8ef
...
...
@@ -18,5 +18,5 @@ class CacheLookupCommand(ConfigCommand):
return
ap
def
take_action
(
self
,
args
):
config
=
self
.
fetch_config
(
args
)
do_lookup
(
config
,
args
.
software_url
)
config
p
=
self
.
fetch_config
(
args
)
do_lookup
(
config
p
,
args
.
software_url
)
slapos/cli/config.py
View file @
d134c8ef
...
...
@@ -42,15 +42,15 @@ class ConfigCommand(Command):
else
:
return
None
config
=
ConfigParser
.
SafeConfigParser
()
if
config
.
read
(
cfg_path
)
!=
[
cfg_path
]:
config
p
=
ConfigParser
.
SafeConfigParser
()
if
config
p
.
read
(
cfg_path
)
!=
[
cfg_path
]:
# bad permission, etc.
if
required
:
raise
ConfigError
(
'Cannot parse configuration file: %s'
%
cfg_path
)
else
:
return
None
return
config
return
config
p
def
fetch_config
(
self
,
args
):
if
args
.
cfg
:
...
...
slapos/cli/console.py
View file @
d134c8ef
...
...
@@ -38,7 +38,7 @@ class ConsoleCommand(ClientConfigCommand):
return
ap
def
take_action
(
self
,
args
):
config
uration_parser
=
self
.
fetch_config
(
args
)
conf
ig
=
ClientConfig
(
args
,
configuration_parser
)
local
=
init
(
conf
ig
)
config
p
=
self
.
fetch_config
(
args
)
conf
=
ClientConfig
(
args
,
configp
)
local
=
init
(
conf
)
do_console
(
local
)
slapos/cli/format.py
View file @
d134c8ef
...
...
@@ -56,21 +56,21 @@ class FormatCommand(ConfigCommand):
return
ap
def
take_action
(
self
,
args
):
config
uration_parser
=
self
.
fetch_config
(
args
)
config
p
=
self
.
fetch_config
(
args
)
conf
ig
=
FormatConfig
(
logger
=
self
.
log
)
conf
=
FormatConfig
(
logger
=
self
.
log
)
try
:
conf
ig
.
setConfig
(
args
,
configuration_parser
)
conf
.
setConfig
(
args
,
configp
)
except
UsageError
as
err
:
sys
.
stderr
.
write
(
err
.
message
+
'
\
n
'
)
sys
.
stderr
.
write
(
"For help use --help
\
n
"
)
sys
.
exit
(
1
)
tracing_monkeypatch
(
conf
ig
)
tracing_monkeypatch
(
conf
)
try
:
do_format
(
conf
ig
=
config
)
do_format
(
conf
=
conf
)
except
:
self
.
log
.
exception
(
'Uncaught exception:'
)
raise
slapos/cli/register.py
View file @
d134c8ef
...
...
@@ -69,9 +69,9 @@ class RegisterCommand(Command):
# ap.error('Please enter your login with your password')
try
:
conf
ig
=
RegisterConfig
(
logger
=
self
.
log
)
conf
ig
.
setConfig
(
args
)
return_code
=
do_register
(
conf
ig
)
conf
=
RegisterConfig
(
logger
=
self
.
log
)
conf
.
setConfig
(
args
)
return_code
=
do_register
(
conf
)
except
SystemExit
,
err
:
# Catch exception raised by optparse
# XXX returning exception with sys.exit?
...
...
slapos/cli/remove.py
View file @
d134c8ef
...
...
@@ -22,7 +22,7 @@ class RemoveCommand(ClientConfigCommand):
return
ap
def
take_action
(
self
,
args
):
config
uration_parser
=
self
.
fetch_config
(
args
)
conf
ig
=
ClientConfig
(
args
,
configuration_parser
)
local
=
init
(
conf
ig
)
config
p
=
self
.
fetch_config
(
args
)
conf
=
ClientConfig
(
args
,
configp
)
local
=
init
(
conf
)
do_remove
(
args
.
software_url
,
args
.
node
,
local
)
slapos/cli/request.py
View file @
d134c8ef
...
...
@@ -55,8 +55,8 @@ class RequestCommand(ClientConfigCommand):
args
.
node
=
parse_option_dict
(
args
.
node
)
args
.
configuration
=
parse_option_dict
(
args
.
configuration
)
config
uration_parser
=
self
.
fetch_config
(
args
)
conf
ig
=
ClientConfig
(
args
,
configuration_parser
)
config
p
=
self
.
fetch_config
(
args
)
conf
=
ClientConfig
(
args
,
configp
)
local
=
init
(
conf
ig
)
do_request
(
conf
ig
,
local
)
local
=
init
(
conf
)
do_request
(
conf
,
local
)
slapos/cli/slapgrid.py
View file @
d134c8ef
...
...
@@ -70,8 +70,8 @@ class SlapgridCommand(ConfigCommand):
return
ap
def
take_action
(
self
,
args
):
config
=
self
.
fetch_config
(
args
)
options
=
merged_options
(
args
,
config
)
config
p
=
self
.
fetch_config
(
args
)
options
=
merged_options
(
args
,
config
p
)
check_missing_parameters
(
options
)
check_missing_files
(
options
)
...
...
slapos/cli/supervisorctl.py
View file @
d134c8ef
...
...
@@ -22,8 +22,8 @@ class SupervisorctlCommand(ConfigCommand):
return
ap
def
take_action
(
self
,
args
):
config
=
self
.
fetch_config
(
args
)
instance_root
=
config
.
get
(
'slapos'
,
'instance_root'
)
config
p
=
self
.
fetch_config
(
args
)
instance_root
=
config
p
.
get
(
'slapos'
,
'instance_root'
)
configuration_file
=
os
.
path
.
join
(
instance_root
,
'etc'
,
'supervisord.conf'
)
launchSupervisord
(
socket
=
os
.
path
.
join
(
instance_root
,
'supervisord.socket'
),
configuration_file
=
configuration_file
,
...
...
slapos/cli/supervisord.py
View file @
d134c8ef
...
...
@@ -12,8 +12,8 @@ class SupervisordCommand(ConfigCommand):
log
=
logging
.
getLogger
(
__name__
)
def
take_action
(
self
,
args
):
config
=
self
.
fetch_config
(
args
)
instance_root
=
config
.
get
(
'slapos'
,
'instance_root'
)
config
p
=
self
.
fetch_config
(
args
)
instance_root
=
config
p
.
get
(
'slapos'
,
'instance_root'
)
launchSupervisord
(
socket
=
os
.
path
.
join
(
instance_root
,
'supervisord.socket'
),
configuration_file
=
os
.
path
.
join
(
instance_root
,
'etc'
,
'supervisord.conf'
),
logger
=
self
.
log
)
slapos/cli/supply.py
View file @
d134c8ef
...
...
@@ -22,7 +22,7 @@ class SupplyCommand(ClientConfigCommand):
return
ap
def
take_action
(
self
,
args
):
config
uration_parser
=
self
.
fetch_config
(
args
)
conf
ig
=
ClientConfig
(
args
,
configuration_parser
)
local
=
init
(
conf
ig
)
config
p
=
self
.
fetch_config
(
args
)
conf
=
ClientConfig
(
args
,
configp
)
local
=
init
(
conf
)
do_supply
(
args
.
software_url
,
args
.
node
,
local
)
slapos/cli_legacy/bang.py
View file @
d134c8ef
...
...
@@ -42,6 +42,6 @@ def main(*args):
args
=
ap
.
parse_args
(
list
(
args
))
else
:
args
=
ap
.
parse_args
()
config
=
ConfigParser
.
SafeConfigParser
()
config
.
readfp
(
args
.
configuration_file
)
do_bang
(
config
,
args
.
message
)
config
p
=
ConfigParser
.
SafeConfigParser
()
config
p
.
readfp
(
args
.
configuration_file
)
do_bang
(
config
p
,
args
.
message
)
slapos/cli_legacy/cache.py
View file @
d134c8ef
...
...
@@ -12,7 +12,7 @@ def cache_lookup():
ap
.
add_argument
(
"software_url"
,
help
=
"Your software url or MD5 hash"
)
args
=
ap
.
parse_args
()
config
=
ConfigParser
.
SafeConfigParser
()
config
.
read
(
args
.
configuration_file
)
config
p
=
ConfigParser
.
SafeConfigParser
()
config
p
.
read
(
args
.
configuration_file
)
do_lookup
(
config
,
args
.
software_url
)
do_lookup
(
config
p
,
args
.
software_url
)
slapos/cli_legacy/console.py
View file @
d134c8ef
...
...
@@ -44,6 +44,7 @@ examples :
if
not
os
.
path
.
isfile
(
args
.
configuration_file
):
ap
.
error
(
"%s: Not found or not a regular file."
%
args
.
configuration_file
)
config
=
ClientConfig
(
args
,
get_config_parser
(
args
.
configuration_file
))
local
=
init
(
config
)
configp
=
get_config_parser
(
args
.
configuration_file
)
conf
=
ClientConfig
(
args
,
configp
)
local
=
init
(
conf
)
do_console
(
local
)
slapos/cli_legacy/entry.py
View file @
d134c8ef
...
...
@@ -73,9 +73,9 @@ def checkSlaposCfg():
for
element
in
sys
.
argv
:
if
'.cfg'
in
element
:
if
os
.
path
.
exists
(
element
):
config
=
ConfigParser
.
SafeConfigParser
()
config
.
read
(
element
)
if
config
.
has_section
(
'slapos'
):
config
p
=
ConfigParser
.
SafeConfigParser
()
config
p
.
read
(
element
)
if
config
p
.
has_section
(
'slapos'
):
return
True
return
False
...
...
@@ -96,7 +96,7 @@ def checkOption(option):
return
True
def
call
(
fun
,
config
=
False
,
option
=
None
):
def
call
(
fun
,
config
_path
=
False
,
option
=
None
):
"""
Add missing options to sys.argv
Add config if asked and it is missing
...
...
@@ -106,9 +106,9 @@ def call(fun, config=False, option=None):
option
=
[]
for
element
in
option
:
checkOption
(
element
)
if
config
:
if
config
_path
:
if
not
checkSlaposCfg
():
sys
.
argv
=
[
sys
.
argv
[
0
]]
+
[
os
.
path
.
expanduser
(
config
)]
+
sys
.
argv
[
1
:]
sys
.
argv
=
[
sys
.
argv
[
0
]]
+
[
os
.
path
.
expanduser
(
config
_path
)]
+
sys
.
argv
[
1
:]
fun
()
sys
.
exit
(
0
)
...
...
@@ -129,34 +129,34 @@ def dispatch(command, is_node_command):
if
command
==
'register'
:
call
(
register
)
elif
command
==
'software'
:
call
(
software
,
config
=
GLOBAL_SLAPOS_CONFIGURATION
,
call
(
software
,
config
_path
=
GLOBAL_SLAPOS_CONFIGURATION
,
option
=
[
'--pidfile /opt/slapos/slapgrid-sr.pid'
])
elif
command
==
'instance'
:
call
(
instance
,
config
=
GLOBAL_SLAPOS_CONFIGURATION
,
call
(
instance
,
config
_path
=
GLOBAL_SLAPOS_CONFIGURATION
,
option
=
[
'--pidfile /opt/slapos/slapgrid-cp.pid'
])
elif
command
==
'report'
:
call
(
report
,
config
=
GLOBAL_SLAPOS_CONFIGURATION
,
call
(
report
,
config
_path
=
GLOBAL_SLAPOS_CONFIGURATION
,
option
=
[
'--pidfile /opt/slapos/slapgrid-ur.pid'
])
elif
command
==
'bang'
:
call
(
bang
,
config
=
GLOBAL_SLAPOS_CONFIGURATION
)
call
(
bang
,
config
_path
=
GLOBAL_SLAPOS_CONFIGURATION
)
elif
command
==
'format'
:
call
(
format
,
config
=
GLOBAL_SLAPOS_CONFIGURATION
,
option
=
[
'-c'
,
'-v'
])
call
(
format
,
config
_path
=
GLOBAL_SLAPOS_CONFIGURATION
,
option
=
[
'-c'
,
'-v'
])
elif
command
==
'supervisord'
:
call
(
supervisord
,
config
=
GLOBAL_SLAPOS_CONFIGURATION
)
call
(
supervisord
,
config
_path
=
GLOBAL_SLAPOS_CONFIGURATION
)
elif
command
==
'supervisorctl'
:
call
(
supervisorctl
,
config
=
GLOBAL_SLAPOS_CONFIGURATION
)
call
(
supervisorctl
,
config
_path
=
GLOBAL_SLAPOS_CONFIGURATION
)
elif
command
in
[
'start'
,
'stop'
,
'restart'
,
'status'
,
'tail'
]:
# Again, too hackish
sys
.
argv
[
-
2
:
-
2
]
=
[
command
]
call
(
supervisorctl
,
config
=
GLOBAL_SLAPOS_CONFIGURATION
)
call
(
supervisorctl
,
config
_path
=
GLOBAL_SLAPOS_CONFIGURATION
)
else
:
return
False
elif
command
==
'request'
:
call
(
request
,
config
=
USER_SLAPOS_CONFIGURATION
)
call
(
request
,
config
_path
=
USER_SLAPOS_CONFIGURATION
)
elif
command
==
'supply'
:
call
(
supply
,
config
=
USER_SLAPOS_CONFIGURATION
)
call
(
supply
,
config
_path
=
USER_SLAPOS_CONFIGURATION
)
elif
command
==
'remove'
:
call
(
remove
,
config
=
USER_SLAPOS_CONFIGURATION
)
call
(
remove
,
config
_path
=
USER_SLAPOS_CONFIGURATION
)
elif
command
==
'start'
:
raise
EntryPointNotImplementedError
(
command
)
elif
command
==
'stop'
:
...
...
@@ -164,9 +164,9 @@ def dispatch(command, is_node_command):
elif
command
==
'destroy'
:
raise
EntryPointNotImplementedError
(
command
)
elif
command
==
'console'
:
call
(
console
,
config
=
USER_SLAPOS_CONFIGURATION
)
call
(
console
,
config
_path
=
USER_SLAPOS_CONFIGURATION
)
elif
command
==
'cache-lookup'
:
call
(
cache_lookup
,
config
=
GLOBAL_SLAPOS_CONFIGURATION
)
call
(
cache_lookup
,
config
_path
=
GLOBAL_SLAPOS_CONFIGURATION
)
else
:
return
False
...
...
slapos/cli_legacy/format.py
View file @
d134c8ef
...
...
@@ -107,23 +107,23 @@ def main(*args):
else
:
logger
.
setLevel
(
logging
.
INFO
)
conf
ig
=
FormatConfig
(
logger
=
logger
)
conf
=
FormatConfig
(
logger
=
logger
)
config
uration_parser
=
ConfigParser
.
SafeConfigParser
()
if
config
uration_parser
.
read
(
args
.
configuration_file
)
!=
[
args
.
configuration_file
]:
config
p
=
ConfigParser
.
SafeConfigParser
()
if
config
p
.
read
(
args
.
configuration_file
)
!=
[
args
.
configuration_file
]:
raise
UsageError
(
'Cannot find or parse configuration file: %s'
%
args
.
configuration_file
)
try
:
conf
ig
.
setConfig
(
args
,
configuration_parser
)
conf
.
setConfig
(
args
,
configp
)
except
UsageError
as
exc
:
sys
.
stderr
.
write
(
exc
.
message
+
'
\
n
'
)
sys
.
stderr
.
write
(
"For help use --help
\
n
"
)
sys
.
exit
(
1
)
tracing_monkeypatch
(
conf
ig
)
tracing_monkeypatch
(
conf
)
try
:
do_format
(
conf
ig
=
config
)
do_format
(
conf
=
conf
)
except
:
conf
ig
.
logger
.
exception
(
'Uncaught exception:'
)
conf
.
logger
.
exception
(
'Uncaught exception:'
)
raise
slapos/cli_legacy/register.py
View file @
d134c8ef
...
...
@@ -97,9 +97,9 @@ def main():
logger
.
addHandler
(
handler
)
try
:
conf
ig
=
RegisterConfig
(
logger
=
logger
)
conf
ig
.
setConfig
(
args
)
return_code
=
do_register
(
conf
ig
)
conf
=
RegisterConfig
(
logger
=
logger
)
conf
.
setConfig
(
args
)
return_code
=
do_register
(
conf
)
except
SystemExit
as
exc
:
# Catch exception raised by optparse
# XXX returning exception with sys.exit?
...
...
slapos/cli_legacy/remove.py
View file @
d134c8ef
...
...
@@ -16,6 +16,7 @@ def remove():
help
=
'Target node'
)
args
=
ap
.
parse_args
()
config
=
ClientConfig
(
args
,
get_config_parser
(
args
.
configuration_file
))
local
=
init
(
config
)
configp
=
get_config_parser
(
args
.
configuration_file
)
conf
=
ClientConfig
(
args
,
configp
)
local
=
init
(
conf
)
do_remove
(
args
.
software_url
,
args
.
node
,
local
)
slapos/cli_legacy/request.py
View file @
d134c8ef
...
...
@@ -50,6 +50,7 @@ def request():
if
args
.
node
:
args
.
node
=
argToDict
(
args
.
node
)
config
=
ClientConfig
(
args
,
get_config_parser
(
args
.
configuration_file
))
local
=
init
(
config
)
do_request
(
config
,
local
)
configp
=
get_config_parser
(
args
.
configuration_file
)
conf
=
ClientConfig
(
args
,
configp
)
local
=
init
(
conf
)
do_request
(
conf
,
local
)
slapos/cli_legacy/slapgrid.py
View file @
d134c8ef
...
...
@@ -115,10 +115,10 @@ def parseArgumentTupleAndReturnSlapgridObject(*argument_tuple):
"""
args
=
parse_arguments
(
*
argument_tuple
)
config
=
ConfigParser
.
SafeConfigParser
()
config
.
readfp
(
args
.
configuration_file
)
config
p
=
ConfigParser
.
SafeConfigParser
()
config
p
.
readfp
(
args
.
configuration_file
)
options
=
merged_options
(
args
,
config
)
options
=
merged_options
(
args
,
config
p
)
logger
=
setup_logger
(
options
)
...
...
slapos/cli_legacy/supply.py
View file @
d134c8ef
...
...
@@ -19,6 +19,7 @@ def supply():
help
=
'Target node'
)
args
=
ap
.
parse_args
()
config
=
ClientConfig
(
args
,
get_config_parser
(
args
.
configuration_file
))
local
=
init
(
config
)
configp
=
get_config_parser
(
args
.
configuration_file
)
conf
=
ClientConfig
(
args
,
configp
)
local
=
init
(
conf
)
do_supply
(
args
.
software_url
,
args
.
node
,
local
)
slapos/cli_legacy/util.py
View file @
d134c8ef
...
...
@@ -5,9 +5,9 @@ import os
def
get_config_parser
(
path
):
config
uration_parser
=
ConfigParser
.
SafeConfigParser
()
config
p
=
ConfigParser
.
SafeConfigParser
()
path
=
os
.
path
.
expanduser
(
path
)
if
not
os
.
path
.
isfile
(
path
):
raise
OSError
(
'Specified configuration file %s does not exist. Exiting.'
%
path
)
config
uration_parser
.
read
(
path
)
return
config
uration_parser
config
p
.
read
(
path
)
return
config
p
slapos/client.py
View file @
d134c8ef
...
...
@@ -37,24 +37,25 @@ from slapos.slap import ResourceNotReady
class
ClientConfig
(
object
):
def
__init__
(
self
,
option_dict
,
configuration_parser
=
None
):
def
__init__
(
self
,
args
,
configp
=
None
):
# XXX configp cannot possibly be optional
"""
Set options given by parameters.
"""
# Set options parameters
for
option
,
value
in
option_dict
.
__dict__
.
items
():
setattr
(
self
,
option
,
value
)
for
key
,
value
in
args
.
__dict__
.
items
():
setattr
(
self
,
key
,
value
)
# Merges the arguments and configuration
try
:
configuration_dict
=
dict
(
config
uration_parser
.
items
(
'slapconsole'
))
configuration_dict
=
dict
(
config
p
.
items
(
'slapconsole'
))
except
ConfigParser
.
NoSectionError
:
pass
else
:
for
key
in
configuration_dict
:
if
not
getattr
(
self
,
key
,
None
):
setattr
(
self
,
key
,
configuration_dict
[
key
])
configuration_dict
=
dict
(
config
uration_parser
.
items
(
'slapos'
))
configuration_dict
=
dict
(
config
p
.
items
(
'slapos'
))
master_url
=
configuration_dict
.
get
(
'master_url'
,
None
)
# Backward compatibility, if no key and certificate given in option
# take one from slapos configuration
...
...
@@ -77,18 +78,18 @@ class ClientConfig(object):
if
self
.
cert_file
:
self
.
cert_file
=
os
.
path
.
expanduser
(
self
.
cert_file
)
def
init
(
conf
ig
):
def
init
(
conf
):
"""Initialize Slap instance, connect to server and create
aliases to common software releases"""
# XXX check certificate and key existence
slap
=
slapos
.
slap
.
slap
()
slap
.
initializeConnection
(
conf
ig
.
master_url
,
key_file
=
conf
ig
.
key_file
,
cert_file
=
config
.
cert_file
)
slap
.
initializeConnection
(
conf
.
master_url
,
key_file
=
conf
.
key_file
,
cert_file
=
conf
.
cert_file
)
local
=
globals
().
copy
()
local
[
'slap'
]
=
slap
# Create aliases as global variables
try
:
alias
=
conf
ig
.
alias
.
split
(
'
\
n
'
)
alias
=
conf
.
alias
.
split
(
'
\
n
'
)
except
AttributeError
:
alias
=
[]
software_list
=
[]
...
...
@@ -113,19 +114,19 @@ def init(config):
return
local
def
do_request
(
conf
ig
,
local
):
def
do_request
(
conf
,
local
):
# Request instance
print
(
"Requesting %s..."
%
conf
ig
.
reference
)
if
conf
ig
.
software_url
in
local
:
conf
ig
.
software_url
=
local
[
config
.
software_url
]
print
(
"Requesting %s..."
%
conf
.
reference
)
if
conf
.
software_url
in
local
:
conf
.
software_url
=
local
[
conf
.
software_url
]
try
:
partition
=
local
[
'slap'
].
registerOpenOrder
().
request
(
software_release
=
conf
ig
.
software_url
,
partition_reference
=
conf
ig
.
reference
,
partition_parameter_kw
=
conf
ig
.
configuration
,
software_type
=
conf
ig
.
type
,
filter_kw
=
conf
ig
.
node
,
shared
=
conf
ig
.
slave
software_release
=
conf
.
software_url
,
partition_reference
=
conf
.
reference
,
partition_parameter_kw
=
conf
.
configuration
,
software_type
=
conf
.
type
,
filter_kw
=
conf
.
node
,
shared
=
conf
.
slave
)
print
"Instance requested.
\
n
State is : %s."
%
partition
.
getState
()
print
"Connection parameters of instance are:"
...
...
slapos/format.py
View file @
d134c8ef
This diff is collapsed.
Click to expand it.
slapos/grid/slapgrid.py
View file @
d134c8ef
...
...
@@ -122,12 +122,11 @@ def check_missing_files(options):
raise
RuntimeError
(
'Directory %r does not exist'
%
d
)
def
merged_options
(
args
,
config
):
options
=
{}
def
merged_options
(
args
,
config
p
):
options
=
dict
(
configp
.
items
(
'slapos'
))
options
=
dict
(
config
.
items
(
'slapos'
))
if
config
.
has_section
(
'networkcache'
):
options
.
update
(
dict
(
config
.
items
(
'networkcache'
)))
if
configp
.
has_section
(
'networkcache'
):
options
.
update
(
dict
(
configp
.
items
(
'networkcache'
)))
for
key
,
value
in
vars
(
args
).
iteritems
():
if
value
is
not
None
:
options
[
key
]
=
value
...
...
slapos/register/register.py
View file @
d134c8ef
...
...
@@ -77,7 +77,7 @@ def get_computer_name(certificate):
return
certificate
[
k
:
i
]
def
save_former_config
(
conf
ig
):
def
save_former_config
(
conf
):
"""Save former configuration if found"""
# Check for config file in /etc/opt/slapos/
if
os
.
path
.
exists
(
'/etc/opt/slapos/slapos.cfg'
):
...
...
@@ -95,7 +95,7 @@ def save_former_config(config):
saved
+=
'.1'
else
:
break
conf
ig
.
logger
.
info
(
"Former slapos configuration detected in %s moving to %s"
%
(
former
,
saved
))
conf
.
logger
.
info
(
"Former slapos configuration detected in %s moving to %s"
%
(
former
,
saved
))
shutil
.
move
(
former
,
saved
)
...
...
@@ -111,11 +111,11 @@ def get_slapos_conf_example():
return
path
def
slapconfig
(
conf
ig
):
def
slapconfig
(
conf
):
"""Base Function to configure slapos in /etc/opt/slapos"""
dry_run
=
conf
ig
.
dry_run
dry_run
=
conf
.
dry_run
# Create slapos configuration directory if needed
slap_conf_dir
=
os
.
path
.
normpath
(
conf
ig
.
slapos_configuration
)
slap_conf_dir
=
os
.
path
.
normpath
(
conf
.
slapos_configuration
)
# Make sure everybody can read slapos configuration directory:
# Add +x to directories in path
...
...
@@ -128,23 +128,23 @@ def slapconfig(config):
directory
=
os
.
path
.
dirname
(
directory
)
if
not
os
.
path
.
exists
(
slap_conf_dir
):
conf
ig
.
logger
.
info
(
"Creating directory: %s"
%
slap_conf_dir
)
conf
.
logger
.
info
(
"Creating directory: %s"
%
slap_conf_dir
)
if
not
dry_run
:
os
.
mkdir
(
slap_conf_dir
,
0o711
)
user_certificate_repository_path
=
os
.
path
.
join
(
slap_conf_dir
,
'ssl'
)
if
not
os
.
path
.
exists
(
user_certificate_repository_path
):
conf
ig
.
logger
.
info
(
"Creating directory: %s"
%
user_certificate_repository_path
)
conf
.
logger
.
info
(
"Creating directory: %s"
%
user_certificate_repository_path
)
if
not
dry_run
:
os
.
mkdir
(
user_certificate_repository_path
,
0o711
)
key_file
=
os
.
path
.
join
(
user_certificate_repository_path
,
'key'
)
cert_file
=
os
.
path
.
join
(
user_certificate_repository_path
,
'certificate'
)
for
src
,
dst
in
[
(
conf
ig
.
key
,
key_file
),
(
conf
ig
.
certificate
,
cert_file
)
(
conf
.
key
,
key_file
),
(
conf
.
certificate
,
cert_file
)
]:
conf
ig
.
logger
.
info
(
"Copying to %r, and setting minimum privileges"
%
dst
)
conf
.
logger
.
info
(
"Copying to %r, and setting minimum privileges"
%
dst
)
if
not
dry_run
:
with
open
(
dst
,
'w'
)
as
destination
:
destination
.
write
(
''
.
join
(
src
))
...
...
@@ -153,41 +153,41 @@ def slapconfig(config):
certificate_repository_path
=
os
.
path
.
join
(
slap_conf_dir
,
'ssl'
,
'partition_pki'
)
if
not
os
.
path
.
exists
(
certificate_repository_path
):
conf
ig
.
logger
.
info
(
"Creating directory: %s"
%
certificate_repository_path
)
conf
.
logger
.
info
(
"Creating directory: %s"
%
certificate_repository_path
)
if
not
dry_run
:
os
.
mkdir
(
certificate_repository_path
,
0o711
)
# Put slapos configuration file
slap_conf_file
=
os
.
path
.
join
(
slap_conf_dir
,
'slapos.cfg'
)
conf
ig
.
logger
.
info
(
"Creating slap configuration: %s"
%
slap_conf_file
)
conf
.
logger
.
info
(
"Creating slap configuration: %s"
%
slap_conf_file
)
# Get example configuration file
slapos_cfg_example
=
get_slapos_conf_example
()
conf_parser
=
ConfigParser
.
RawConfigParser
()
conf_parser
.
read
(
slapos_cfg_example
)
new_configp
=
ConfigParser
.
RawConfigParser
()
new_configp
.
read
(
slapos_cfg_example
)
os
.
remove
(
slapos_cfg_example
)
for
section
,
key
,
value
in
[
(
'slapos'
,
'computer_id'
,
conf
ig
.
computer_id
),
(
'slapos'
,
'master_url'
,
conf
ig
.
master_url
),
(
'slapos'
,
'computer_id'
,
conf
.
computer_id
),
(
'slapos'
,
'master_url'
,
conf
.
master_url
),
(
'slapos'
,
'key_file'
,
key_file
),
(
'slapos'
,
'cert_file'
,
cert_file
),
(
'slapos'
,
'certificate_repository_path'
,
certificate_repository_path
),
(
'slapformat'
,
'interface_name'
,
conf
ig
.
interface_name
),
(
'slapformat'
,
'ipv4_local_network'
,
conf
ig
.
ipv4_local_network
),
(
'slapformat'
,
'partition_amount'
,
conf
ig
.
partition_number
),
(
'slapformat'
,
'create_tap'
,
conf
ig
.
create_tap
)
(
'slapformat'
,
'interface_name'
,
conf
.
interface_name
),
(
'slapformat'
,
'ipv4_local_network'
,
conf
.
ipv4_local_network
),
(
'slapformat'
,
'partition_amount'
,
conf
.
partition_number
),
(
'slapformat'
,
'create_tap'
,
conf
.
create_tap
)
]:
conf_parser
.
set
(
section
,
key
,
value
)
new_configp
.
set
(
section
,
key
,
value
)
if
conf
ig
.
ipv6_interface
:
conf_parser
.
set
(
'slapformat'
,
'ipv6_interface'
,
config
.
ipv6_interface
)
if
conf
.
ipv6_interface
:
new_configp
.
set
(
'slapformat'
,
'ipv6_interface'
,
conf
.
ipv6_interface
)
if
not
dry_run
:
with
open
(
slap_conf_file
,
'w'
)
as
fout
:
conf_parser
.
write
(
fout
)
new_configp
.
write
(
fout
)
conf
ig
.
logger
.
info
(
"SlapOS configuration: DONE"
)
conf
.
logger
.
info
(
"SlapOS configuration: DONE"
)
class
RegisterConfig
(
object
):
...
...
@@ -221,43 +221,43 @@ class RegisterConfig(object):
self
.
logger
.
debug
(
"Ipv6 Interface: %s"
%
self
.
ipv6_interface
)
def
gen_auth
(
conf
ig
):
def
gen_auth
(
conf
):
ask
=
True
if
conf
ig
.
login
:
if
conf
ig
.
password
:
yield
conf
ig
.
login
,
config
.
password
if
conf
.
login
:
if
conf
.
password
:
yield
conf
.
login
,
conf
.
password
ask
=
False
else
:
yield
conf
ig
.
login
,
getpass
.
getpass
()
yield
conf
.
login
,
getpass
.
getpass
()
while
ask
:
yield
raw_input
(
'SlapOS Master Login: '
),
getpass
.
getpass
()
def
do_register
(
conf
ig
):
def
do_register
(
conf
):
"""Register new computer on SlapOS Master and generate slapos.cfg"""
for
login
,
password
in
gen_auth
(
conf
ig
):
if
check_credentials
(
conf
ig
.
master_url_web
,
login
,
password
):
for
login
,
password
in
gen_auth
(
conf
):
if
check_credentials
(
conf
.
master_url_web
,
login
,
password
):
break
conf
ig
.
logger
.
warning
(
'Wrong login/password'
)
conf
.
logger
.
warning
(
'Wrong login/password'
)
else
:
return
1
# Get source code of page having certificate and key
certificate_key
=
get_certificates
(
conf
ig
.
master_url_web
,
config
.
node_name
,
login
,
password
)
certificate_key
=
get_certificates
(
conf
.
master_url_web
,
conf
.
node_name
,
login
,
password
)
# Parse certificate and key and get computer id
certificate
,
key
=
parse_certificates
(
certificate_key
)
COMP
=
get_computer_name
(
certificate
)
# Getting configuration parameters
conf
ig
.
COMPConfig
(
slapos_configuration
=
'/etc/opt/slapos/'
,
computer_id
=
COMP
,
certificate
=
certificate
,
key
=
key
)
conf
.
COMPConfig
(
slapos_configuration
=
'/etc/opt/slapos/'
,
computer_id
=
COMP
,
certificate
=
certificate
,
key
=
key
)
# Save former configuration
if
not
conf
ig
.
dry_run
:
save_former_config
(
conf
ig
)
if
not
conf
.
dry_run
:
save_former_config
(
conf
)
# Prepare Slapos Configuration
slapconfig
(
conf
ig
)
slapconfig
(
conf
)
print
"Node has successfully been configured as %s."
%
COMP
return
0
slapos/tests/entry.py
View file @
d134c8ef
...
...
@@ -126,15 +126,15 @@ class TestCall (BasicMixin, unittest.TestCase):
options
=
[
"--logfile /opt/slapos/logfile"
,
"--pidfile /opt/slapos/pidfile"
]
config
=
'/etc/opt/slapos/slapos.cfg'
config
_path
=
'/etc/opt/slapos/slapos.cfg'
try
:
entry
.
call
(
fun
,
config
=
config
,
option
=
options
)
entry
.
call
(
fun
,
config
_path
=
config_path
,
option
=
options
)
except
SystemExit
,
e
:
self
.
assertEqual
(
e
[
0
],
0
)
self
.
assertNotEqual
(
original_sysargv
,
sys
.
argv
)
for
x
in
options
:
self
.
assertTrue
(
x
in
" "
.
join
(
sys
.
argv
))
self
.
assertEqual
(
config
,
sys
.
argv
[
1
])
self
.
assertEqual
(
config
_path
,
sys
.
argv
[
1
])
def
test_config_and_missing_option_are_added
(
self
):
"""
...
...
@@ -151,16 +151,16 @@ class TestCall (BasicMixin, unittest.TestCase):
return
0
options
=
[
default_present_option
,
missing_option
]
config
=
'/etc/opt/slapos/slapos.cfg'
config
_path
=
'/etc/opt/slapos/slapos.cfg'
try
:
entry
.
call
(
fun
,
config
=
config
,
option
=
options
)
entry
.
call
(
fun
,
config
_path
=
config_path
,
option
=
options
)
except
SystemExit
,
e
:
self
.
assertEqual
(
e
[
0
],
0
)
self
.
assertNotEqual
(
original_sysargv
,
sys
.
argv
)
for
x
in
(
missing_option
,
present_option
):
self
.
assertTrue
(
x
in
" "
.
join
(
sys
.
argv
))
self
.
assertFalse
(
default_present_option
in
" "
.
join
(
sys
.
argv
))
self
.
assertEqual
(
config
,
sys
.
argv
[
1
])
self
.
assertEqual
(
config
_path
,
sys
.
argv
[
1
])
def
test_present_config_and_option_are_not_added
(
self
):
"""
...
...
@@ -178,9 +178,9 @@ class TestCall (BasicMixin, unittest.TestCase):
return
0
options
=
[
default_present_option
]
config
=
'/etc/opt/slapos/slapos.cfg'
config
_path
=
'/etc/opt/slapos/slapos.cfg'
try
:
entry
.
call
(
fun
,
config
=
config
,
option
=
options
)
entry
.
call
(
fun
,
config
_path
=
config_path
,
option
=
options
)
except
SystemExit
,
e
:
self
.
assertEqual
(
e
[
0
],
0
)
...
...
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