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
Jérome Perrin
slapos.core
Commits
3aa3a2c4
Commit
3aa3a2c4
authored
Jun 28, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/token-auth'
Conflicts: slapos/cli/register.py
parents
12e59791
14edfde9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
39 deletions
+23
-39
slapos/cli/register.py
slapos/cli/register.py
+23
-39
No files found.
slapos/cli/register.py
View file @
3aa3a2c4
...
@@ -2,10 +2,10 @@
...
@@ -2,10 +2,10 @@
import
getpass
import
getpass
import
os
import
os
import
re
import
shutil
import
shutil
import
stat
import
stat
import
sys
import
sys
import
tempfile
import
subprocess
import
subprocess
import
iniparse
import
iniparse
...
@@ -174,23 +174,10 @@ def save_former_config(conf):
...
@@ -174,23 +174,10 @@ def save_former_config(conf):
shutil
.
move
(
former
,
saved
)
shutil
.
move
(
former
,
saved
)
def
get_slapos_conf_example
(
logger
):
def
fetch_configuration_template
():
"""
req
=
requests
.
get
(
'http://git.erp5.org/gitweb/slapos.core.git/blob_plain/HEAD:/slapos.cfg.example'
)
Get slapos.cfg.example and return its path
req
.
raise_for_status
()
"""
return
req
.
text
_
,
path
=
tempfile
.
mkstemp
()
with
open
(
path
,
'wb'
)
as
fout
:
req
=
requests
.
get
(
'http://git.erp5.org/gitweb/slapos.core.git/blob_plain/HEAD:/slapos.cfg.example'
)
try
:
req
.
content
.
decode
(
'ascii'
)
except
UnicodeDecodeError
:
# we have to reject the file because iniparse chokes on non-ascii,
# and similar packages (cfgparse, INITools etc) have issues with
# multiline values, like certificates, or do not retain comments (ConfigParser).
logger
.
critical
(
'Cannot create configuration file (bad template).'
)
sys
.
exit
(
1
)
fout
.
write
(
req
.
content
)
return
path
def
slapconfig
(
conf
):
def
slapconfig
(
conf
):
...
@@ -240,31 +227,28 @@ def slapconfig(conf):
...
@@ -240,31 +227,28 @@ def slapconfig(conf):
# Put slapos configuration file
# Put slapos configuration file
config_path
=
os
.
path
.
join
(
slap_conf_dir
,
'slapos.cfg'
)
config_path
=
os
.
path
.
join
(
slap_conf_dir
,
'slapos.cfg'
)
# Get example configuration file
cfg
=
fetch_configuration_template
()
slapos_cfg_example
=
get_slapos_conf_example
(
conf
.
logger
)
new_configp
=
iniparse
.
RawConfigParser
()
to_replace
=
[
new_configp
.
read
(
slapos_cfg_example
)
(
'computer_id'
,
conf
.
computer_id
),
os
.
remove
(
slapos_cfg_example
)
(
'master_url'
,
conf
.
master_url
),
(
'key_file'
,
key_file
),
for
section
,
key
,
value
in
[
(
'cert_file'
,
cert_file
),
(
'slapos'
,
'computer_id'
,
conf
.
computer_id
),
(
'certificate_repository_path'
,
certificate_repository_path
),
(
'slapos'
,
'master_url'
,
conf
.
master_url
),
(
'interface_name'
,
conf
.
interface_name
),
(
'slapos'
,
'key_file'
,
key_file
),
(
'ipv4_local_network'
,
conf
.
ipv4_local_network
),
(
'slapos'
,
'cert_file'
,
cert_file
),
(
'partition_amount'
,
conf
.
partition_number
),
(
'slapos'
,
'certificate_repository_path'
,
certificate_repository_path
),
(
'create_tap'
,
conf
.
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
)
]:
new_configp
.
set
(
section
,
key
,
value
)
if
conf
.
ipv6_interface
:
if
conf
.
ipv6_interface
:
new_configp
.
set
(
'slapformat'
,
'ipv6_interface'
,
conf
.
ipv6_interface
)
to_replace
.
append
([(
'ipv6_interface'
,
conf
.
ipv6_interface
)])
for
key
,
value
in
to_replace
:
cfg
=
re
.
sub
(
'%s
\
s+=.*
'
% key, '
%
s
=
%
s
' % (key, value), cfg)
if not dry_run:
if not dry_run:
with open(config_path, '
w
') as fout:
with open(config_path, '
w
') as fout:
new_configp
.
write
(
fout
)
fout.write(cfg.encode('
utf8
')
)
conf.logger.info('
SlapOS
configuration
written
to
%
s
', config_path)
conf.logger.info('
SlapOS
configuration
written
to
%
s
', config_path)
...
...
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