Commit b0100a77 authored by Vincent Pelletier's avatar Vincent Pelletier

Provide access to partition network settings.

parent 4e295a79
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
############################################################################## ##############################################################################
import slapos.slap import slapos.slap
from ConfigParser import RawConfigParser from ConfigParser import RawConfigParser
from netaddr import valid_ipv4, valid_ipv6
class Recipe(object): class Recipe(object):
""" """
...@@ -33,6 +34,8 @@ class Recipe(object): ...@@ -33,6 +34,8 @@ class Recipe(object):
buildout section in various ways, and in various encodings. buildout section in various ways, and in various encodings.
Populates the buildout section it is used in with all slap partition Populates the buildout section it is used in with all slap partition
parameters. parameters.
Also provides access to partition properties: all IPv4, IPv6 and tap
interfaces it is allowed to use.
Input: Input:
url url
...@@ -57,6 +60,12 @@ class Recipe(object): ...@@ -57,6 +60,12 @@ class Recipe(object):
Output: Output:
slap-software-type slap-software-type
Current partition's software type. Current partition's software type.
ipv4
Set of IPv4 addresses.
ipv6
Set of IPv6 addresses.
tap
Set of TAP interfaces.
configuration configuration
Dict of all parameters. Dict of all parameters.
configuration.<key> configuration.<key>
...@@ -85,7 +94,22 @@ class Recipe(object): ...@@ -85,7 +94,22 @@ class Recipe(object):
# Discard them, and make them available as separate section keys. # Discard them, and make them available as separate section keys.
options['slap-software-type'] = parameter_dict.pop( options['slap-software-type'] = parameter_dict.pop(
'slap_software_type') 'slap_software_type')
del parameter_dict['ip_list'] ipv4_set = set()
v4_add = ipv4_set.add
ipv6_set = set()
v6_add = ipv6_set.add
tap_set = set()
tap_add = tap_set.add
for tap, ip in parameter_dict.pop('ip_list'):
tap_add(tap)
if valid_ipv4(ip):
v4_add(ip)
elif valid_ipv6(ip):
v6_add(ip)
# XXX: emit warning on unknown address type ?
options['ipv4'] = ipv4_set
options['ipv6'] = ipv6_set
options['tap'] = tap_set
options['configuration'] = parameter_dict options['configuration'] = parameter_dict
match = self.OPTCRE_match match = self.OPTCRE_match
for key, value in parameter_dict.iteritems(): for key, value in parameter_dict.iteritems():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment