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
1
Merge Requests
1
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
Romain Courteaud
slapos.core
Commits
06c91260
Commit
06c91260
authored
Nov 30, 2023
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Plain Diff
format: Support partition capabilities in computer definition file
See merge request
!585
parents
fa1a40dd
266ebf80
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
10 deletions
+36
-10
slapos/format.py
slapos/format.py
+36
-10
No files found.
slapos/format.py
View file @
06c91260
...
@@ -144,6 +144,19 @@ class AddressGenerationError(Exception):
...
@@ -144,6 +144,19 @@ class AddressGenerationError(Exception):
)
)
def
getNormalizedIfaddresses
(
iface
,
inet
):
"""
Keep a single representation for netmasks, to avoid netmasks like
ffff:ffff:ffff:ffff:ffff:ffff::/96
"""
address_list
=
netifaces
.
ifaddresses
(
iface
)[
inet
]
for
q
in
address_list
:
try
:
q
[
'netmask'
]
=
q
[
'netmask'
].
split
(
'/'
)[
0
]
except
KeyError
:
pass
return
address_list
def
getPublicIPv4Address
():
def
getPublicIPv4Address
():
test_list
=
[
test_list
=
[
{
"url"
:
'https://api.ipify.org/?format=json'
,
"json_key"
:
"ip"
},
{
"url"
:
'https://api.ipify.org/?format=json'
,
"json_key"
:
"ip"
},
...
@@ -194,7 +207,7 @@ def getIfaceAddressIPv4(iface):
...
@@ -194,7 +207,7 @@ def getIfaceAddressIPv4(iface):
raise
ValueError
(
'Could not find interface called %s to use as gateway '
\
raise
ValueError
(
'Could not find interface called %s to use as gateway '
\
'for tap network'
%
iface
)
'for tap network'
%
iface
)
try
:
try
:
addresses_list
=
netifaces
.
ifaddresses
(
iface
)[
socket
.
AF_INET
]
addresses_list
=
getNormalizedIfaddresses
(
iface
,
socket
.
AF_INET
)
if
len
(
addresses_list
)
>
0
:
if
len
(
addresses_list
)
>
0
:
addresses
=
addresses_list
[
0
].
copy
()
addresses
=
addresses_list
[
0
].
copy
()
...
@@ -269,7 +282,8 @@ class Computer(object):
...
@@ -269,7 +282,8 @@ class Computer(object):
self
.
interface
=
interface
self
.
interface
=
interface
self
.
partition_list
=
partition_list
or
[]
self
.
partition_list
=
partition_list
or
[]
self
.
address
=
addr
self
.
address
=
addr
self
.
netmask
=
netmask
# Normalize netmask due to netiface netmasks like ffff::/16
self
.
netmask
=
netmask
and
netmask
.
split
(
'/'
)[
0
]
self
.
ipv6_interface
=
ipv6_interface
self
.
ipv6_interface
=
ipv6_interface
self
.
partition_has_ipv6_range
=
partition_has_ipv6_range
self
.
partition_has_ipv6_range
=
partition_has_ipv6_range
self
.
software_user
=
software_user
self
.
software_user
=
software_user
...
@@ -1056,14 +1070,16 @@ class Interface(object):
...
@@ -1056,14 +1070,16 @@ class Interface(object):
Returns currently configured local IPv4 addresses which are in
Returns currently configured local IPv4 addresses which are in
ipv4_local_network
ipv4_local_network
"""
"""
if
not
socket
.
AF_INET
in
netifaces
.
ifaddresses
(
self
.
name
):
try
:
address_list
=
getNormalizedIfaddresses
(
self
.
name
,
socket
.
AF_INET
)
except
KeyError
:
# No entry for socket.AF_INET
return
[]
return
[]
return
[
return
[
{
{
'addr'
:
q
[
'addr'
],
'addr'
:
q
[
'addr'
],
'netmask'
:
q
[
'netmask'
]
'netmask'
:
q
[
'netmask'
]
}
}
for
q
in
netifaces
.
ifaddresses
(
self
.
name
)[
socket
.
AF_INET
]
for
q
in
address_list
if
netaddr
.
IPAddress
(
q
[
'addr'
],
4
)
in
netaddr
.
glob_to_iprange
(
if
netaddr
.
IPAddress
(
q
[
'addr'
],
4
)
in
netaddr
.
glob_to_iprange
(
netaddr
.
cidr_to_glob
(
self
.
ipv4_local_network
))
netaddr
.
cidr_to_glob
(
self
.
ipv4_local_network
))
]
]
...
@@ -1074,7 +1090,7 @@ class Interface(object):
...
@@ -1074,7 +1090,7 @@ class Interface(object):
try
:
try
:
address_list
=
[
address_list
=
[
q
q
for
q
in
netifaces
.
ifaddresses
(
interface_name
)[
socket
.
AF_INET6
]
for
q
in
getNormalizedIfaddresses
(
interface_name
,
socket
.
AF_INET6
)
if
isGlobalScopeAddress
(
q
[
'addr'
].
split
(
'%'
)[
0
])
if
isGlobalScopeAddress
(
q
[
'addr'
].
split
(
'%'
)[
0
])
]
]
except
KeyError
:
except
KeyError
:
...
@@ -1087,7 +1103,7 @@ class Interface(object):
...
@@ -1087,7 +1103,7 @@ class Interface(object):
try
:
try
:
address_list
+=
[
address_list
+=
[
q
q
for
q
in
netifaces
.
ifaddresses
(
tap
.
name
)[
socket
.
AF_INET6
]
for
q
in
getNormalizedIfaddresses
(
tap
.
name
,
socket
.
AF_INET6
)
if
isGlobalScopeAddress
(
q
[
'addr'
].
split
(
'%'
)[
0
])
if
isGlobalScopeAddress
(
q
[
'addr'
].
split
(
'%'
)[
0
])
]
]
except
KeyError
:
except
KeyError
:
...
@@ -1486,6 +1502,15 @@ def parse_computer_definition(conf, definition_path):
...
@@ -1486,6 +1502,15 @@ def parse_computer_definition(conf, definition_path):
address_list
=
address_list
,
address_list
=
address_list
,
ipv6_range
=
ipv6_range
,
ipv6_range
=
ipv6_range
,
tap
=
tap
,
tun
=
tun
)
tap
=
tap
,
tun
=
tun
)
if
computer_definition
.
has_option
(
section
,
'capability_list'
):
# Attribute .capability_list exists only when capabilities are defined
capability_string
=
computer_definition
.
get
(
section
,
'capability_list'
)
capability_list
=
[]
for
c
in
capability_string
.
splitlines
():
c
=
c
.
strip
()
if
c
:
capability_list
.
append
(
c
)
partition
.
capability_list
=
capability_list
partition_list
.
append
(
partition
)
partition_list
.
append
(
partition
)
computer
.
partition_list
=
partition_list
computer
.
partition_list
=
partition_list
return
computer
return
computer
...
@@ -1604,7 +1629,8 @@ def do_format(conf):
...
@@ -1604,7 +1629,8 @@ def do_format(conf):
conf
.
logger
.
info
(
'Updating computer'
)
conf
.
logger
.
info
(
'Updating computer'
)
address
=
computer
.
getAddress
()
address
=
computer
.
getAddress
()
computer
.
address
=
address
[
'addr'
]
computer
.
address
=
address
[
'addr'
]
computer
.
netmask
=
address
[
'netmask'
]
# Normalize netmask due to netiface netmasks like ffff::/16
computer
.
netmask
=
address
[
'netmask'
]
and
address
[
'netmask'
].
split
(
'/'
)[
0
]
if
conf
.
output_definition_file
:
if
conf
.
output_definition_file
:
write_computer_definition
(
conf
,
computer
)
write_computer_definition
(
conf
,
computer
)
...
...
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