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