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
Hide 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):
...
@@ -252,12 +252,22 @@ class Computer(object):
pass
pass
def
format
(
self
):
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
# Non local bind for IPv6 ranges
if
self
.
conf
.
ipv6_range
or
any
(
p
.
ipv6_range
for
p
in
self
.
partitions
):
if
self
.
conf
.
ipv6_range
or
any
(
p
.
ipv6_range
for
p
in
self
.
partitions
):
self
.
interface
.
enableIPv6NonLocalBind
()
self
.
interface
.
enableIPv6NonLocalBind
()
# Computer address
self
.
interface
.
addAddress
(
self
.
address
,
self
.
reference
)
# Instance root path
ensureDir
(
self
.
conf
.
instance_root
,
0o755
)
# Format each partitions
# Format each partitions
for
p
in
self
.
partitions
:
for
p
in
self
.
partitions
:
p
.
format
()
p
.
format
(
self
.
interface
)
def
update
(
self
):
def
update
(
self
):
pass
pass
...
@@ -332,24 +342,24 @@ class Interface(object):
...
@@ -332,24 +342,24 @@ class Interface(object):
if
not
'dev lo'
in
result
:
if
not
'dev lo'
in
result
:
call
([
'ip'
,
'-6'
,
'route'
,
'add'
,
'local'
,
network
,
'dev'
,
'lo'
])
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
)
interface
=
interface
or
getattr
(
self
,
'ipv%d_interface'
%
ip
.
version
)
af
=
{
4
:
AF_INET
,
6
:
AF_INET6
}[
ip
.
version
]
af
=
{
4
:
AF_INET
,
6
:
AF_INET6
}[
ip
.
version
]
address
=
str
(
ip
.
ip
)
for
iface
in
netifaces
.
interfaces
():
for
iface
in
netifaces
.
interfaces
():
if
iface
!=
interface
:
if
iface
!=
interface
:
ifaddresses
=
netifaces
.
ifaddresses
(
iface
).
get
(
af
,
())
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
(
self
.
conf
.
error
(
"Cannot add address %s
to %s as
it already exists on %s"
,
"Cannot add address %s
(%s) to %s because
it already exists on %s"
,
ip
,
interface
,
iface
ip
,
reason
,
interface
,
iface
)
)
ifaddresses
=
netifaces
.
ifaddresses
(
interface
).
get
(
af
,
())
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
])
call
([
'ip'
,
'addr'
,
'add'
,
str
(
ip
),
'dev'
,
interface
])
class
Partition
(
object
):
class
Partition
(
object
):
interface
:
Interface
reference
:
str
reference
:
str
index
:
int
index
:
int
path
:
str
path
:
str
...
@@ -363,10 +373,9 @@ class Partition(object):
...
@@ -363,10 +373,9 @@ class Partition(object):
def
__init__
(
self
,
index
,
computer
,
definition
=
None
):
def
__init__
(
self
,
index
,
computer
,
definition
=
None
):
i
=
str
(
index
)
i
=
str
(
index
)
conf
=
computer
.
conf
conf
=
computer
.
conf
interface
=
computer
.
interface
section
=
definition
[
'partition_'
+
i
]
section
=
definition
[
'partition_'
+
i
]
options
=
defaultdict
(
type
(
None
),
section
,
**
definition
[
'default'
])
options
=
defaultdict
(
type
(
None
),
section
,
**
definition
[
'default'
])
# Interface
self
.
interface
=
interface
=
computer
.
interface
# Reference, path & user
# Reference, path & user
self
.
reference
=
options
[
'pathname'
]
or
conf
.
partition_base_name
+
i
self
.
reference
=
options
[
'pathname'
]
or
conf
.
partition_base_name
+
i
self
.
path
=
os
.
path
.
join
(
conf
.
instance_root
,
self
.
reference
)
self
.
path
=
os
.
path
.
join
(
conf
.
instance_root
,
self
.
reference
)
...
@@ -389,13 +398,13 @@ class Partition(object):
...
@@ -389,13 +398,13 @@ class Partition(object):
# Tap & Tun
# Tap & Tun
# XXX
# XXX
def
format
(
self
):
def
format
(
self
,
interface
):
self
.
user
.
createUser
()
self
.
user
.
createUser
()
self
.
createPath
()
self
.
createPath
()
for
ip
in
self
.
ipv4_list
:
for
ip
in
self
.
ipv4_list
:
self
.
interface
.
addAddress
(
ip
)
interface
.
addAddress
(
ip
,
self
.
reference
)
for
ip
in
self
.
ipv6_list
:
for
ip
in
self
.
ipv6_list
:
self
.
interface
.
addAddress
(
ip
)
interface
.
addAddress
(
ip
,
self
.
reference
)
def
createPath
(
self
):
def
createPath
(
self
):
if
not
os
.
path
.
exists
(
self
.
path
):
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