# HG changeset patch # User Tero Marttila # Date 1425923299 -7200 # Node ID 008cfe47b194888869deb52f4e5b4a1a359d1d14 # Parent 5770ed34c1f0213ba3587517891b5634d4c93b87 pvl.hosts.interface: sub-interfaces for a host, which are not associated with any separate domain/network diff -r 5770ed34c1f0 -r 008cfe47b194 bin/pvl.hosts-forward --- 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): diff -r 5770ed34c1f0 -r 008cfe47b194 bin/pvl.hosts-reverse --- 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): diff -r 5770ed34c1f0 -r 008cfe47b194 pvl/hosts/interface.py --- /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))