pvl.hosts.interface: sub-interfaces for a host, which are not associated with any separate domain/network
--- a/bin/pvl.hosts-forward Mon Mar 09 19:47:10 2015 +0200
+++ b/bin/pvl.hosts-forward Mon Mar 09 19:48:19 2015 +0200
@@ -5,6 +5,7 @@
import os.path
import pvl.args
import pvl.hosts
+import pvl.hosts.interface
import pvl.hosts.zone
def main (argv):
--- a/bin/pvl.hosts-reverse Mon Mar 09 19:47:10 2015 +0200
+++ b/bin/pvl.hosts-reverse Mon Mar 09 19:48:19 2015 +0200
@@ -5,6 +5,7 @@
import os.path
import pvl.args
import pvl.hosts
+import pvl.hosts.interface
import pvl.hosts.zone
def main (argv):
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pvl/hosts/interface.py Mon Mar 09 19:48:19 2015 +0200
@@ -0,0 +1,32 @@
+import ipaddress, ipaddr # XXX: conversion
+import pvl.hosts
+
+def parse_interfaces(interfaces):
+ for interface, value in interfaces.iteritems():
+ if not isinstance(value, dict):
+ yield (interface, 0), ipaddress.ip_interface(value)
+ else:
+ for unit, ip in value.iteritems():
+ yield (interface, int(unit)), ipaddress.ip_interface(value)
+
+@pvl.hosts.extension
+class HostInterface(object):
+ EXTENSION = 'interface'
+
+ @classmethod
+ def build (cls, **interfaces):
+ return cls(dict(parse_interfaces(interfaces)))
+
+ def __init__ (self, interfaces):
+ self.interfaces = interfaces
+
+ def iter_interfaces (self):
+ for (iface, unit), ip in self.interfaces.iteritems():
+ family = {4: 'inet', 6: 'inet6' }[ip.version]
+
+ yield iface, unit, family, ip
+
+ def addresses (self):
+ for (iface, unit), ip in self.interfaces.iteritems():
+ # XXX: ipaddr
+ yield iface, ipaddr.IPAddress(str(ip.ip))