Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.package
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Nicolas Wavrant
slapos.package
Commits
4884a05a
Commit
4884a05a
authored
Jun 28, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
prepare: general, light cleanup
parent
74ef042c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
37 deletions
+35
-37
slapprepare/slapprepare/slapprepare.py
slapprepare/slapprepare/slapprepare.py
+35
-37
No files found.
slapprepare/slapprepare/slapprepare.py
View file @
4884a05a
...
...
@@ -62,8 +62,7 @@ class Parser(OptionParser):
help
=
"Simulate the execution steps"
,
default
=
False
,
action
=
"store_true"
),
]
)
])
def
check_args
(
self
):
"""
...
...
@@ -122,15 +121,14 @@ def get_yes_no(prompt, default=None):
if
answer
.
upper
()
in
[
'N'
,
'NO'
]:
return
False
if
not
answer
and
default
is
not
None
:
return
default
return
default
def
getSlaposConfiguration
(
slapos_configuration_file_path
=
None
):
for
path
in
[
slapos_configuration_file_path
,
'/etc/opt/slapos/slapos.cfg'
,
'/etc/slapos/slapos.cfg'
]:
'/etc/slapos/slapos.cfg'
]:
if
path
and
os
.
path
.
isfile
(
path
):
config
=
ConfigParser
.
RawConfigParser
()
config
.
read
(
path
)
...
...
@@ -176,17 +174,16 @@ def get_ssh(temp_dir):
# Downloading ssh_key
count
=
10
gotten
=
True
while
count
>
0
:
while
count
:
try
:
print
"Enter the url of your public ssh key"
ssh_web
=
raw_input
(
'--> '
)
try
:
ssh_key_all
=
urllib2
.
urlopen
(
''
.
join
(
ssh_web
)
)
ssh_key_all
=
urllib2
.
urlopen
(
ssh_web
)
gotten
=
True
except
ValueError
:
# add http:// if it is missing (needed by urllib2)
ssh_web
=
"""http://"""
+
ssh_web
ssh_key_all
=
urllib2
.
urlopen
(
''
.
join
(
ssh_web
))
# add http:// if it is missing (needed by urllib2)
ssh_key_all
=
urllib2
.
urlopen
(
'http://%s'
%
ssh_web
)
gotten
=
True
except
urllib2
.
URLError
:
print
" URL ERROR"
...
...
@@ -241,8 +238,9 @@ def slapserver(config):
if
not
dry_run
:
open
(
host_path
,
'w'
).
write
(
pkg_resources
.
resource_stream
(
__name__
,
'template/hosts.in'
).
read
()
%
dict
(
computer_id
=
config
.
computer_id
))
'template/hosts.in'
).
read
()
%
{
'computer_id'
:
config
.
computer_id
})
# Creating safe sshd_config
sshd_path
=
os
.
path
.
normpath
(
'/'
.
join
([
mount_dir_path
,
'etc'
,
'ssh'
,
...
...
@@ -252,7 +250,7 @@ def slapserver(config):
open
(
sshd_path
,
'w'
).
write
(
pkg_resources
.
resource_stream
(
__name__
,
'template/sshd_config.in'
).
read
())
os
.
chmod
(
sshd_path
,
0600
)
os
.
chmod
(
sshd_path
,
0
o
600
)
# Creating default bridge config
br0_path
=
os
.
path
.
normpath
(
'/'
.
join
([
mount_dir_path
,
'etc'
,
...
...
@@ -288,16 +286,16 @@ def slapserver(config):
if
not
dry_run
:
print
"Setting uid:gid of %r to %s:%s"
%
(
ssh_key_directory
,
uid
,
gid
)
os
.
chown
(
ssh_key_directory
,
uid
,
gid
)
os
.
chmod
(
ssh_key_directory
,
0700
)
os
.
chmod
(
ssh_key_directory
,
0
o
700
)
print
"Creating file: %s"
%
ssh_key_path
if
not
dry_run
:
open
(
ssh_key_path
,
'a'
).
write
(
''
.
join
(
open
(
config
.
key_path
,
'r'
).
read
()))
open
(
ssh_key_path
,
'a'
).
write
(
''
.
join
(
open
(
config
.
key_path
).
read
()))
if
not
dry_run
:
print
"Setting uid:gid of %r to %s:%s"
%
(
ssh_key_path
,
uid
,
gid
)
os
.
chown
(
ssh_key_path
,
uid
,
gid
)
os
.
chmod
(
ssh_key_path
,
0600
)
os
.
chmod
(
ssh_key_path
,
0
o
600
)
# Put file to force VPN if user asked
if
config
.
force_slapcontainer
:
...
...
@@ -312,7 +310,7 @@ def slapserver(config):
if
not
dry_run
:
open
(
path
,
'w'
).
write
(
pkg_resources
.
resource_stream
(
__name__
,
'script/%s'
%
script
).
read
())
os
.
chmod
(
path
,
0755
)
os
.
chmod
(
path
,
0
o
755
)
else
:
for
script
in
[
'slapos_firstboot'
]:
path
=
os
.
path
.
join
(
mount_dir_path
,
'etc'
,
'init.d'
,
script
)
...
...
@@ -346,34 +344,34 @@ def prepare_scripts(config):
slapos_configuration
=
'/etc/opt/slapos/'
# Creating boot script
path
=
os
.
path
.
join
(
'/'
,
'usr'
,
'sbin'
,
'slapos-boot-dedicated'
)
path
=
'/usr/sbin/slapos-boot-dedicated'
print
"Creating %r"
%
path
if
not
dry_run
:
open
(
path
,
'w'
).
write
(
pkg_resources
.
resource_stream
(
__name__
,
'script/%s'
%
'slapos'
).
read
()
%
{
'slapos_configuration'
:
slapos_configuration
})
os
.
chmod
(
path
,
0755
)
'script/%s'
%
'slapos'
).
read
()
%
{
'slapos_configuration'
:
slapos_configuration
})
os
.
chmod
(
path
,
0o755
)
path
=
os
.
path
.
join
(
'/'
,
'etc'
,
'systemd'
,
'system'
,
'slapos-boot-dedicated.service'
)
path
=
'/etc/systemd/system/slapos-boot-dedicated.service'
print
"Creating %r"
%
path
if
not
dry_run
:
open
(
path
,
'w'
).
write
(
pkg_resources
.
resource_stream
(
__name__
,
'script/%s'
%
'slapos.service'
).
read
()
%
dict
(
slapos_configuration
=
slapos_configuration
))
os
.
chmod
(
path
,
0755
)
'script/%s'
%
'slapos.service'
).
read
()
%
{
'slapos_configuration'
:
slapos_configuration
})
os
.
chmod
(
path
,
0o755
)
# add clientipv4
path
=
os
.
path
.
join
(
'/'
,
'etc'
,
'openvpn'
,
'clientipv4.conf'
)
path
=
'/etc/openvpn/clientipv4.conf'
print
"Creating %r"
%
path
if
not
dry_run
:
open
(
path
,
'w'
).
write
(
pkg_resources
.
resource_stream
(
__name__
,
'template/%s'
%
'clientipv4.conf.in'
).
read
())
os
.
chmod
(
path
,
0755
)
os
.
chmod
(
path
,
0
o
755
)
# Remove old-timers scripts
remove_former_scripts
(
slapos_configuration
)
...
...
@@ -382,7 +380,7 @@ def prepare_scripts(config):
def
configureNtp
():
"""Configures NTP daemon"""
server
=
"server pool.ntp.org"
old_ntp
=
open
(
'/etc/ntp.conf'
,
'r'
).
readlines
()
old_ntp
=
open
(
'/etc/ntp.conf'
).
readlines
()
new_ntp
=
open
(
'/etc/ntp.conf'
,
'w'
)
for
line
in
old_ntp
:
if
line
.
startswith
(
'server'
):
...
...
@@ -439,13 +437,13 @@ class Config:
if
not
get_yes_no
(
"A SlapOS Node configuration has been found. Do you want to overwrite it?"
,
False
):
print
"Okay, let's start from scratch."
return
False
self
.
master_url
=
raw_input
(
"
""SlapOS Master URL? Empty answer will make it use slapos.org Master: ""
"
)
self
.
master_url
=
raw_input
(
"
SlapOS Master URL? Empty answer will make it use slapos.org Master:
"
)
if
self
.
master_url
:
self
.
master_url_web
=
raw_input
(
"""SlapOS Master "web" URL?: """
)
self
.
master_url_web
=
raw_input
(
'SlapOS Master "web" URL?: '
)
else
:
self
.
master_url_web
=
''
self
.
computer_name
=
raw_input
(
"Define a unique name for this computer: "
)
self
.
partition_amount
=
raw_input
(
"
""Number of SlapOS partitions for this computer? Default is 20: ""
"
)
self
.
partition_amount
=
raw_input
(
"
Number of SlapOS partitions for this computer? Default is 20:
"
)
if
self
.
partition_amount
==
''
:
self
.
partition_amount
=
'20'
elif
not
already_configured
:
...
...
@@ -484,10 +482,10 @@ class Config:
def
prepare_from_scratch
(
config
):
try
:
temp_directory
=
os
.
path
.
join
(
'/tmp/slaptemp/'
)
temp_directory
=
'/tmp/slaptemp/'
if
not
os
.
path
.
exists
(
temp_directory
):
print
"Creating directory: %s"
%
temp_directory
os
.
mkdir
(
temp_directory
,
0711
)
os
.
mkdir
(
temp_directory
,
0
o
711
)
while
True
:
if
config
.
userConfig
():
...
...
@@ -534,7 +532,7 @@ def prepare_from_scratch(config):
print
'Warning: impossible to set up bridge because slapos configuration doesn
\
'
t exist.'
computer_id
=
get_computer_name
(
os
.
path
.
join
(
'/'
,
slapos_configuration
,
'slapos.cfg'
))
os
.
path
.
join
(
slapos_configuration
,
'slapos.cfg'
))
print
"Your Computer is : %s"
%
computer_id
...
...
@@ -543,7 +541,7 @@ def prepare_from_scratch(config):
hostname_path
=
'/etc/HOSTNAME'
,
host_path
=
'/etc/hosts'
,
key_path
=
os
.
path
.
join
(
temp_directory
,
'authorized_keys'
),
master_url
=
"""https://slap.vifib.com"""
,
master_url
=
'https://slap.vifib.com'
,
temp_dir
=
temp_directory
,
computer_id
=
computer_id
)
...
...
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