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
Xavier Thompson
slapos.core
Commits
c44a9e73
Commit
c44a9e73
authored
Oct 27, 2022
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapformat: WIP: extend and improve format
parent
e03a89b6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
12 deletions
+21
-12
slapos/format.py
slapos/format.py
+21
-12
No files found.
slapos/format.py
View file @
c44a9e73
...
...
@@ -252,12 +252,22 @@ class Computer(object):
pass
def
format
(
self
):
# Software root path
ensureDir
(
self
.
conf
.
software_root
,
0o755
)
# Software user
self
.
user
.
createUser
()
uid
,
gid
=
self
.
user
.
getIds
()
os
.
chown
(
self
.
conf
.
software_root
,
uid
,
gid
)
# Non local bind for IPv6 ranges
if
self
.
conf
.
ipv6_range
or
any
(
p
.
ipv6_range
for
p
in
self
.
partitions
):
self
.
interface
.
enableIPv6NonLocalBind
()
# Computer address
self
.
interface
.
addAddress
(
self
.
address
,
self
.
reference
)
# Instance root path
ensureDir
(
self
.
conf
.
instance_root
,
0o755
)
# Format each partitions
for
p
in
self
.
partitions
:
p
.
format
()
p
.
format
(
self
.
interface
)
def
update
(
self
):
pass
...
...
@@ -332,24 +342,24 @@ class Interface(object):
if
not
'dev lo'
in
result
:
call
([
'ip'
,
'-6'
,
'route'
,
'add'
,
'local'
,
network
,
'dev'
,
'lo'
])
def
addAddress
(
self
,
ip
,
interface
=
None
):
def
addAddress
(
self
,
ip
,
reason
,
interface
=
None
):
interface
=
interface
or
getattr
(
self
,
'ipv%d_interface'
%
ip
.
version
)
af
=
{
4
:
AF_INET
,
6
:
AF_INET6
}[
ip
.
version
]
address
=
str
(
ip
.
ip
)
for
iface
in
netifaces
.
interfaces
():
if
iface
!=
interface
:
ifaddresses
=
netifaces
.
ifaddresses
(
iface
).
get
(
af
,
())
if
ip
.
ip
in
(
q
[
'addr'
].
split
(
'%'
)[
0
]
for
q
in
ifaddresses
):
if
address
in
(
q
[
'addr'
].
split
(
'%'
)[
0
]
for
q
in
ifaddresses
):
self
.
conf
.
error
(
"Cannot add address %s
to %s as
it already exists on %s"
,
ip
,
interface
,
iface
"Cannot add address %s
(%s) to %s because
it already exists on %s"
,
ip
,
reason
,
interface
,
iface
)
ifaddresses
=
netifaces
.
ifaddresses
(
interface
).
get
(
af
,
())
if
not
ip
.
ip
in
(
q
[
'addr'
].
split
(
'%'
)[
0
]
for
q
in
ifaddresses
):
if
not
address
in
(
q
[
'addr'
].
split
(
'%'
)[
0
]
for
q
in
ifaddresses
):
call
([
'ip'
,
'addr'
,
'add'
,
str
(
ip
),
'dev'
,
interface
])
class
Partition
(
object
):
interface
:
Interface
reference
:
str
index
:
int
path
:
str
...
...
@@ -363,10 +373,9 @@ class Partition(object):
def
__init__
(
self
,
index
,
computer
,
definition
=
None
):
i
=
str
(
index
)
conf
=
computer
.
conf
interface
=
computer
.
interface
section
=
definition
[
'partition_'
+
i
]
options
=
defaultdict
(
type
(
None
),
section
,
**
definition
[
'default'
])
# Interface
self
.
interface
=
interface
=
computer
.
interface
# Reference, path & user
self
.
reference
=
options
[
'pathname'
]
or
conf
.
partition_base_name
+
i
self
.
path
=
os
.
path
.
join
(
conf
.
instance_root
,
self
.
reference
)
...
...
@@ -389,13 +398,13 @@ class Partition(object):
# Tap & Tun
# XXX
def
format
(
self
):
def
format
(
self
,
interface
):
self
.
user
.
createUser
()
self
.
createPath
()
for
ip
in
self
.
ipv4_list
:
self
.
interface
.
addAddress
(
ip
)
interface
.
addAddress
(
ip
,
self
.
reference
)
for
ip
in
self
.
ipv6_list
:
self
.
interface
.
addAddress
(
ip
)
interface
.
addAddress
(
ip
,
self
.
reference
)
def
createPath
(
self
):
if
not
os
.
path
.
exists
(
self
.
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