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
Paul Graydon
slapos.core
Commits
3f49f908
Commit
3f49f908
authored
Feb 01, 2012
by
Cédric de Saint Martin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Refactor to use 'interface' name where 'bridge' was used"
This reverts commit
c7083252
.
parent
f60d77d6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
61 deletions
+60
-61
slapos.cfg.example
slapos.cfg.example
+1
-1
slapos/format.py
slapos/format.py
+59
-60
No files found.
slapos.cfg.example
View file @
3f49f908
...
...
@@ -9,7 +9,7 @@ buildout = /path/to/buildout/binary
computer_xml = /opt/slapos/slapos.xml
log_file = /opt/slapos/slapformat.log
partition_amount = 200
interfac
e_name = br0
bridg
e_name = br0
partition_base_name = slappart
user_base_name = slapuser
tap_base_name = slaptap
...
...
slapos/format.py
View file @
3f49f908
...
...
@@ -144,22 +144,22 @@ class Error(Exception):
def
__str__
(
self
):
return
self
.
message
class
NoAddressOn
Interfac
e
(
Error
):
class
NoAddressOn
Bridg
e
(
Error
):
"""
Exception raised if there's not address on the
interfac
e to construct IPv6
Exception raised if there's not address on the
bridg
e to construct IPv6
address with.
Attributes:
brige: String, the name of the
interfac
e.
brige: String, the name of the
bridg
e.
"""
def
__init__
(
self
,
interfac
e
):
self
.
message
=
'No IPv6 found on
interface %s to construct IPv6 with.'
%
interfac
e
def
__init__
(
self
,
bridg
e
):
self
.
message
=
'No IPv6 found on
bridge %s to construct IPv6 with.'
%
bridg
e
class
AddressGenerationError
(
Error
):
"""
Exception raised if the generation of an IPv6 based on the prefix obtained
from the
interfac
e failed.
from the
bridg
e failed.
Attributes:
addr: String, the invalid address the exception is raised for.
...
...
@@ -170,32 +170,32 @@ class AddressGenerationError(Error):
class
Computer
:
"Object representing the computer"
def
__init__
(
self
,
reference
,
interfac
e
=
None
,
addr
=
None
,
netmask
=
None
,
def
__init__
(
self
,
reference
,
bridg
e
=
None
,
addr
=
None
,
netmask
=
None
,
ipv6_interface
=
None
):
"""
Attributes:
reference: String, the reference of the computer.
interface: String, if it has one, the name of the interface to be used
.
bridge: String, if it has one, the name of the computer's bridge
.
"""
self
.
reference
=
str
(
reference
)
self
.
interface
=
interfac
e
self
.
bridge
=
bridg
e
self
.
partition_list
=
[]
self
.
address
=
addr
self
.
netmask
=
netmask
self
.
ipv6_interface
=
ipv6_interface
def
__getinitargs__
(
self
):
return
(
self
.
reference
,
self
.
interfac
e
)
return
(
self
.
reference
,
self
.
bridg
e
)
def
getAddress
(
self
):
"""
Return a list of the
interfac
e address not attributed to any partition, (which
Return a list of the
bridg
e address not attributed to any partition, (which
are therefore free for the computer itself).
Returns:
False if the
interfac
e isn't available, else the list of the free addresses.
False if the
bridg
e isn't available, else the list of the free addresses.
"""
if
self
.
interfac
e
is
None
:
if
self
.
bridg
e
is
None
:
return
dict
(
addr
=
self
.
address
,
netmask
=
self
.
netmask
)
computer_partition_address_list
=
[]
...
...
@@ -203,8 +203,8 @@ class Computer:
for
address
in
partition
.
address_list
:
if
netaddr
.
valid_ipv6
(
address
[
'addr'
]):
computer_partition_address_list
.
append
(
address
[
'addr'
])
# Going through addresses of the interface
for
address_dict
in
self
.
interfac
e
.
getGlobalScopeAddressList
():
# Going through addresses of the
computer's bridge
interface
for
address_dict
in
self
.
bridg
e
.
getGlobalScopeAddressList
():
# Comparing with computer's partition addresses
if
address_dict
[
'addr'
]
not
in
computer_partition_address_list
:
return
address_dict
...
...
@@ -212,8 +212,8 @@ class Computer:
# all addresses on interface are for partition, so lets add new one
computer_tap
=
Tap
(
'compdummy'
)
computer_tap
.
createWithOwner
(
User
(
'root'
),
attach_to_tap
=
True
)
self
.
interfac
e
.
addTap
(
computer_tap
)
return
self
.
interfac
e
.
addAddr
()
self
.
bridg
e
.
addTap
(
computer_tap
)
return
self
.
bridg
e
.
addAddr
()
def
send
(
self
,
config
):
"""
...
...
@@ -304,7 +304,7 @@ class Computer:
Construct the computer object as it is.
"""
if
alter_network
and
self
.
address
is
not
None
:
self
.
interfac
e
.
addAddr
(
self
.
address
,
self
.
netmask
)
self
.
bridg
e
.
addAddr
(
self
.
address
,
self
.
netmask
)
for
path
in
self
.
instance_root
,
self
.
software_root
:
if
not
os
.
path
.
exists
(
path
):
...
...
@@ -338,13 +338,13 @@ class Computer:
if
alter_network
:
# In case it has to be attached to the TAP network device, only one
# is necessary for the
interfac
e to assert carrier
if
self
.
interfac
e
.
attach_to_tap
and
partition_index
==
0
:
# is necessary for the
bridg
e to assert carrier
if
self
.
bridg
e
.
attach_to_tap
and
partition_index
==
0
:
partition
.
tap
.
createWithOwner
(
owner
,
attach_to_tap
=
True
)
else
:
partition
.
tap
.
createWithOwner
(
owner
)
self
.
interfac
e
.
addTap
(
partition
.
tap
)
self
.
bridg
e
.
addTap
(
partition
.
tap
)
# Reconstructing partition's directory
partition
.
createPath
(
alter_user
)
...
...
@@ -355,8 +355,8 @@ class Computer:
# * local IPv4, took from slapformat:ipv4_local_network
if
len
(
partition
.
address_list
)
==
0
:
# regenerate
partition
.
address_list
.
append
(
self
.
interfac
e
.
addIPv4LocalAddress
())
partition
.
address_list
.
append
(
self
.
interfac
e
.
addAddr
())
partition
.
address_list
.
append
(
self
.
bridg
e
.
addIPv4LocalAddress
())
partition
.
address_list
.
append
(
self
.
bridg
e
.
addAddr
())
elif
alter_network
:
# regenerate list of addresses
old_partition_address_list
=
partition
.
address_list
...
...
@@ -369,14 +369,14 @@ class Computer:
raise
ValueError
(
'Not valid ipv6 addresses loaded'
)
for
address
in
old_partition_address_list
:
if
netaddr
.
valid_ipv6
(
address
[
'addr'
]):
partition
.
address_list
.
append
(
self
.
interfac
e
.
addAddr
(
address
[
'addr'
],
partition
.
address_list
.
append
(
self
.
bridg
e
.
addAddr
(
address
[
'addr'
],
address
[
'netmask'
]))
elif
netaddr
.
valid_ipv4
(
address
[
'addr'
]):
partition
.
address_list
.
append
(
self
.
interfac
e
.
addIPv4LocalAddress
(
address
[
'addr'
]))
partition
.
address_list
.
append
(
self
.
bridg
e
.
addIPv4LocalAddress
(
address
[
'addr'
]))
else
:
raise
ValueError
(
'Address %r is incorrect'
%
address
[
'addr'
])
finally
:
if
alter_network
and
self
.
interfac
e
.
attach_to_tap
:
if
alter_network
and
self
.
bridg
e
.
attach_to_tap
:
try
:
self
.
partition_list
[
0
].
tap
.
detach
()
except
IndexError
:
...
...
@@ -516,7 +516,6 @@ class Tap:
there is carrier, e.g. the network cable is plugged into a switch for
example).
In case of bridge :
In order to be able to check the uniqueness of IPv6 address assigned to
the bridge, the network interface must be up from an administrative *and*
operational point of view.
...
...
@@ -582,13 +581,13 @@ class Tap:
return
True
class
Interfac
e
:
"
Interface represent a interfac
e on the system"
class
Bridg
e
:
"
Bridge represent a bridg
e on the system"
def
__init__
(
self
,
name
,
ipv4_local_network
,
ipv6_interface
=
None
):
"""
Attributes:
name: String, the name of the
interfac
e
name: String, the name of the
bridg
e
"""
self
.
name
=
str
(
name
)
...
...
@@ -634,19 +633,19 @@ class Interface:
return
address_list
def
getInterfaceList
(
self
):
"""Returns list of interfaces already present on
interfac
e"""
"""Returns list of interfaces already present on
bridg
e"""
interface_list
=
[]
returncode
,
result
=
callAndRead
([
'brctl'
,
'show'
])
in_
interfac
e
=
False
in_
bridg
e
=
False
for
line
in
result
.
split
(
'
\
n
'
):
if
len
(
line
.
split
())
>
1
:
if
self
.
name
in
line
:
interface_list
.
append
(
line
.
split
()[
-
1
])
in_
interfac
e
=
True
in_
bridg
e
=
True
continue
if
in_
interfac
e
:
if
in_
bridg
e
:
break
elif
in_
interfac
e
:
elif
in_
bridg
e
:
if
line
.
strip
():
interface_list
.
append
(
line
.
strip
())
...
...
@@ -663,7 +662,7 @@ class Interface:
callAndRead
([
'brctl'
,
'addif'
,
self
.
name
,
tap
.
name
])
def
_addSystemAddress
(
self
,
address
,
netmask
,
ipv6
=
True
):
"""Adds system address to
interfac
e
"""Adds system address to
bridg
e
Returns True if address was added successfully.
...
...
@@ -740,15 +739,15 @@ class Interface:
def
addAddr
(
self
,
addr
=
None
,
netmask
=
None
):
"""
Adds IP address to
interfac
e.
Adds IP address to
bridg
e.
If addr is specified and exists already on
interfac
e does nothing.
If addr is specified and exists already on
bridg
e does nothing.
If addr is specified and does not exists on
interfac
e, tries to add given address.
If addr is specified and does not exists on
bridg
e, tries to add given address.
In case if it is not possible (ex. because network changed) calculates new address.
Args:
addr: Wished address to be added to
interfac
e.
addr: Wished address to be added to
bridg
e.
netmask: Wished netmask to be used.
Returns:
...
...
@@ -756,32 +755,32 @@ class Interface:
Raises:
AddressGenerationError: Couldn't construct valid address with existing
one's on the
interfac
e.
NoAddressOn
Interface: There's no address on the interfac
e to construct
one's on the
bridg
e.
NoAddressOn
Bridge: There's no address on the bridg
e to construct
an address with.
"""
# Getting one address of the
interfac
e as base of the next addresses
# Getting one address of the
bridg
e as base of the next addresses
if
self
.
ipv6_interface
:
interface_name
=
self
.
ipv6_interface
else
:
interface_name
=
self
.
name
interfac
e_addr_list
=
self
.
getGlobalScopeAddressList
()
bridg
e_addr_list
=
self
.
getGlobalScopeAddressList
()
# No address found
if
len
(
interfac
e_addr_list
)
==
0
:
raise
NoAddressOn
Interfac
e
(
interface_name
)
address_dict
=
interfac
e_addr_list
[
0
]
if
len
(
bridg
e_addr_list
)
==
0
:
raise
NoAddressOn
Bridg
e
(
interface_name
)
address_dict
=
bridg
e_addr_list
[
0
]
if
addr
is
not
None
:
if
dict
(
addr
=
addr
,
netmask
=
netmask
)
in
interfac
e_addr_list
:
if
dict
(
addr
=
addr
,
netmask
=
netmask
)
in
bridg
e_addr_list
:
# confirmed to be configured
return
dict
(
addr
=
addr
,
netmask
=
netmask
)
if
netmask
==
address_dict
[
'netmask'
]:
# same netmask, so there is a chance to add good one
interfac
e_network
=
netaddr
.
ip
.
IPNetwork
(
'%s/%s'
%
(
address_dict
[
'addr'
],
bridg
e_network
=
netaddr
.
ip
.
IPNetwork
(
'%s/%s'
%
(
address_dict
[
'addr'
],
netmaskToPrefixIPv6
(
address_dict
[
'netmask'
])))
requested_network
=
netaddr
.
ip
.
IPNetwork
(
'%s/%s'
%
(
addr
,
netmaskToPrefixIPv6
(
netmask
)))
if
interfac
e_network
.
network
==
requested_network
.
network
:
if
bridg
e_network
.
network
==
requested_network
.
network
:
# same network, try to add
if
self
.
_addSystemAddress
(
addr
,
netmask
):
# succeed, return it
...
...
@@ -867,18 +866,18 @@ def run(config):
config
.
logger
.
info
(
'Using definition file %r'
%
filepath
)
computer_definition
=
ConfigParser
.
RawConfigParser
()
computer_definition
.
read
(
filepath
)
interfac
e
=
None
bridg
e
=
None
address
=
None
netmask
=
None
if
computer_definition
.
has_option
(
'computer'
,
'address'
):
address
,
netmask
=
computer_definition
.
get
(
'computer'
,
'address'
).
split
(
'/'
)
if
config
.
alter_network
and
config
.
interfac
e_name
is
not
None
\
if
config
.
alter_network
and
config
.
bridg
e_name
is
not
None
\
and
config
.
ipv4_local_network
is
not
None
:
interface
=
Interface
(
config
.
interfac
e_name
,
config
.
ipv4_local_network
,
bridge
=
Bridge
(
config
.
bridg
e_name
,
config
.
ipv4_local_network
,
config
.
ipv6_interface
)
computer
=
Computer
(
reference
=
config
.
computer_id
,
interface
=
interfac
e
,
bridge
=
bridg
e
,
addr
=
address
,
netmask
=
netmask
,
ipv6_interface
=
config
.
ipv6_interface
...
...
@@ -904,15 +903,15 @@ def run(config):
if
os
.
path
.
exists
(
config
.
computer_xml
):
config
.
logger
.
info
(
'Loading previous computer data from %r'
%
config
.
computer_xml
)
computer
=
Computer
.
load
(
config
.
computer_xml
,
reference
=
config
.
computer_id
,
ipv6_interface
=
config
.
ipv6_interface
)
# Connect to the
interfac
e interface defined by the configuration
computer
.
interface
=
Interface
(
config
.
interfac
e_name
,
config
.
ipv4_local_network
,
# Connect to the
bridg
e interface defined by the configuration
computer
.
bridge
=
Bridge
(
config
.
bridg
e_name
,
config
.
ipv4_local_network
,
config
.
ipv6_interface
)
else
:
# If no pre-existent configuration found, creating a new computer object
config
.
logger
.
warning
(
'Creating new data computer with id %r'
%
config
.
computer_id
)
computer
=
Computer
(
reference
=
config
.
computer_id
,
interface
=
Interface
(
config
.
interfac
e_name
,
config
.
ipv4_local_network
,
bridge
=
Bridge
(
config
.
bridg
e_name
,
config
.
ipv4_local_network
,
config
.
ipv6_interface
),
addr
=
None
,
netmask
=
None
,
...
...
@@ -1020,7 +1019,7 @@ class Config:
setattr
(
self
,
key
,
configuration_dict
[
key
])
# setup some nones
for
parameter
in
[
'
interfac
e_name'
,
'partition_base_name'
,
'user_base_name'
,
for
parameter
in
[
'
bridg
e_name'
,
'partition_base_name'
,
'user_base_name'
,
'tap_base_name'
,
'ipv4_local_network'
,
'ipv6_interface'
]:
if
getattr
(
self
,
parameter
,
None
)
is
None
:
setattr
(
self
,
parameter
,
None
)
...
...
@@ -1118,12 +1117,12 @@ def main(*args):
else
:
return
0
,
''
callAndRead
=
dry_callAndRead
real_addSystemAddress
=
Interfac
e
.
_addSystemAddress
real_addSystemAddress
=
Bridg
e
.
_addSystemAddress
def
fake_addSystemAddress
(
*
args
,
**
kw
):
real_addSystemAddress
(
*
args
,
**
kw
)
# Fake success
return
True
Interfac
e
.
_addSystemAddress
=
fake_addSystemAddress
Bridg
e
.
_addSystemAddress
=
fake_addSystemAddress
def
fake_getpwnam
(
user
):
class
result
:
pw_uid
=
12345
...
...
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