Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
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
Xiaowu Zhang
slapos.toolbox
Commits
35b9ed2c
Commit
35b9ed2c
authored
Jul 23, 2012
by
Antoine Catton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update container configuration during preparation
parent
9ff3e2af
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
100 additions
and
1 deletion
+100
-1
slapos/container/config.py
slapos/container/config.py
+83
-0
slapos/container/prepare.py
slapos/container/prepare.py
+17
-1
No files found.
slapos/container/config.py
0 → 100644
View file @
35b9ed2c
# -*- coding: utf-8 -*-
import
collections
import
StringIO
class
LXCConfig
(
object
):
"""LXC Configuration file parser
"""
class
_Sub
(
object
):
"""Subobject to go throught
LXC COnfiguration"""
def
__init__
(
self
,
parent
,
namespace
):
self
.
_parent
=
parent
self
.
_namespace
=
namespace
def
__getattr__
(
self
,
name
):
if
name
.
startswith
(
'_'
):
return
self
.
__dict__
[
name
]
return
self
.
_parent
.
_get
(
'%s.%s'
%
(
self
.
_namespace
,
name
))
def
__setattr__
(
self
,
name
,
value
):
if
name
.
startswith
(
'_'
):
self
.
__dict__
[
name
]
=
value
else
:
self
.
_parent
.
_set
(
'%s.%s'
%
(
self
.
_namespace
,
name
),
value
)
def
__init__
(
self
,
filename
):
"""LXCConfig init method. filename should be a string
of the path to the filename.
"""
self
.
_filename
=
filename
with
open
(
filename
,
'r'
)
as
lxcconf_file
:
self
.
_values
=
self
.
_load
(
lxcconf_file
.
read
())
def
__getattr__
(
self
,
name
):
return
self
.
_get
(
name
)
def
__setattr__
(
self
,
name
,
value
):
if
name
.
startswith
(
'_'
):
self
.
__dict__
[
name
]
=
value
else
:
self
.
_set
(
name
,
value
)
def
_load
(
self
,
config_string
):
result
=
collections
.
OrderedDict
()
for
line
in
config_string
.
split
(
'
\
n
'
):
if
not
line
.
strip
().
startswith
(
'#'
)
and
line
.
strip
()
!=
''
:
if
'='
not
in
line
:
raise
ValueError
(
"Not a valid LXCFile"
)
key
,
value
=
[
i
.
strip
()
for
i
in
line
.
split
(
'='
,
1
)]
if
key
in
result
:
if
isinstance
(
result
[
key
],
basestring
):
result
[
key
]
=
[
result
[
key
],
value
]
else
:
result
[
key
].
append
(
value
)
else
:
result
[
key
]
=
value
return
result
def
_set
(
self
,
key
,
value
):
self
.
_values
[
'lxc.%s'
%
key
]
=
value
def
_get
(
self
,
key
):
try
:
return
self
.
_values
[
'lxc.%s'
%
key
]
except
KeyError
:
return
self
.
_Sub
(
self
,
key
)
def
__str__
(
self
):
result
=
StringIO
.
StringIO
()
for
key
,
value
in
self
.
_values
.
iteritems
():
if
isinstance
(
value
,
basestring
):
print
>>
result
,
key
,
'='
,
value
else
:
for
item
in
value
:
print
>>
result
,
key
,
'='
,
item
return
result
.
getvalue
()
slapos/container/prepare.py
View file @
35b9ed2c
...
@@ -6,6 +6,8 @@ import subprocess
...
@@ -6,6 +6,8 @@ import subprocess
import
lockfile
import
lockfile
from
.config
import
LXCConfig
class
SlapContainerError
(
Exception
):
class
SlapContainerError
(
Exception
):
"""This exception is thrown, if there is
"""This exception is thrown, if there is
any failure during slapcontainer preparation,
any failure during slapcontainer preparation,
...
@@ -82,7 +84,21 @@ def stop(sr_directory, partition_path, conf):
...
@@ -82,7 +84,21 @@ def stop(sr_directory, partition_path, conf):
def
create
(
sr_directory
,
partition_path
,
conf
):
def
create
(
sr_directory
,
partition_path
,
conf
):
lxc_debian
=
os
.
path
.
join
(
sr_directory
,
lxc_debian
=
os
.
path
.
join
(
sr_directory
,
'parts/lxc/lib/lxc/templates/lxc-debian'
)
'parts/lxc/lib/lxc/templates/lxc-debian'
)
return
call
([
lxc_debian
,
'-p'
,
partition_path
])
call
([
lxc_debian
,
'-p'
,
partition_path
])
lxc_filename
=
os
.
path
.
join
(
partition_path
,
'config'
)
lxc
=
LXCConfig
(
lxc_filename
)
lxc
.
utsname
=
os
.
path
.
basename
(
partition_path
)
lxc
.
network
.
vlan
.
type
=
'vlan'
lxc
.
network
.
link
=
conf
.
get
(
'information'
,
'interface'
)
lxc
.
network
.
name
=
'eth0'
# XXX: Hardcoded netmasks
lxc
.
network
.
ipv4
=
'%s/32'
%
conf
.
get
(
'information'
,
'ipv4'
)
lxc
.
network
.
ipv6
=
'%s/128'
%
conf
.
get
(
'information'
,
'ipv6'
)
lxc
.
network
.
flags
=
'up'
with
open
(
lxc_filename
,
'w'
)
as
lxc_file
:
lxc_file
.
write
(
str
(
lxc
))
def
destroy
(
partition_path
,
conf
):
def
destroy
(
partition_path
,
conf
):
...
...
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