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
0588d597
Commit
0588d597
authored
Oct 27, 2022
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapformat: WIP: Add checkFormat
parent
c44a9e73
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
0 deletions
+35
-0
slapos/format.py
slapos/format.py
+35
-0
No files found.
slapos/format.py
View file @
0588d597
...
...
@@ -37,6 +37,7 @@ import pwd
import
grp
import
subprocess
import
sys
import
time
from
collections
import
defaultdict
from
netifaces
import
AF_INET
,
AF_INET6
...
...
@@ -53,6 +54,8 @@ def do_format(conf):
computer
.
checkConf
()
# format
computer
.
format
()
# check formatting
computer
.
checkFormat
()
# collect some environmental data
computer
.
update
()
# send to master
...
...
@@ -269,6 +272,11 @@ class Computer(object):
for
p
in
self
.
partitions
:
p
.
format
(
self
.
interface
)
def
checkFormat
(
self
):
time
.
sleep
(
2
)
for
p
in
self
.
partitions
:
p
.
checkFormat
(
self
.
interface
)
def
update
(
self
):
pass
...
...
@@ -358,6 +366,27 @@ class Interface(object):
if
not
address
in
(
q
[
'addr'
].
split
(
'%'
)[
0
]
for
q
in
ifaddresses
):
call
([
'ip'
,
'addr'
,
'add'
,
str
(
ip
),
'dev'
,
interface
])
def
checkAddress
(
self
,
ip
,
reason
,
interface
=
None
):
interface
=
interface
or
getattr
(
self
,
'ipv%d_interface'
%
ip
.
version
)
flag
=
str
(
-
ip
.
version
)
_
,
result
=
call
([
'ip'
,
flag
,
'addr'
,
'show'
,
interface
])
address
=
str
(
ip
.
ip
)
for
line
in
result
.
splitlines
():
if
address
in
line
:
for
state
in
(
'tentative'
,
'dadfailed'
):
if
state
in
line
:
call
([
'ip'
,
'addr'
,
'del'
,
address
,
'dev'
,
interface
])
self
.
conf
.
error
(
"Address %s (%s) on %s was in state %s so was removed: %r"
,
address
,
reason
,
interface
,
state
,
line
)
return
report
=
self
.
conf
.
warn
if
self
.
conf
.
dry_run
else
self
.
conf
.
error
report
(
"Address %s (%s) is unexpectedly not present on %s"
,
address
,
reason
,
interface
)
class
Partition
(
object
):
reference
:
str
...
...
@@ -406,6 +435,12 @@ class Partition(object):
for
ip
in
self
.
ipv6_list
:
interface
.
addAddress
(
ip
,
self
.
reference
)
def
checkFormat
(
self
,
interface
):
for
ip
in
self
.
ipv4_list
:
interface
.
checkAddress
(
ip
,
self
.
reference
)
for
ip
in
self
.
ipv6_list
:
interface
.
checkAddress
(
ip
,
self
.
reference
)
def
createPath
(
self
):
if
not
os
.
path
.
exists
(
self
.
path
):
os
.
mkdir
(
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