aboutsummaryrefslogtreecommitdiff
path: root/scripts/resource-set.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/resource-set.py')
-rw-r--r--scripts/resource-set.py63
1 files changed, 55 insertions, 8 deletions
diff --git a/scripts/resource-set.py b/scripts/resource-set.py
index 49b6fc9b..60f4afc3 100644
--- a/scripts/resource-set.py
+++ b/scripts/resource-set.py
@@ -1,19 +1,66 @@
# $Id$
+import socket
+import re
+
+class ip_address(object):
+
+ def __init__(self, text):
+ self.addr = socket.inet_pton(self.af, text)
+
+ def __str__(self):
+ return socket.inet_ntop(self.af, self.addr)
+
+ def __eq__(self, other):
+ return self.addr == other.addr
+
+ def __hash__(self):
+ return self.addr.__hash__()
+
+class ipv4_address(ip_address):
+ re = "[0-9.]+"
+ af = socket.AF_INET
+
+class ipv6_address(ip_address):
+ re = "[0-9:a-fA-F]+"
+ af = socket.AF_INET6
+
class resource(object):
+ pass
+
+class asn(resource, long):
+ pass
+
+class ip_prefix(resource):
+
+ def __init__(self, addr, prefixlen):
+ self.addr = addr
+ self.prefixlen = prefixlen
+
+ def __str__(self):
+ return str(self.addr) + "/" + str(self.prefixlen)
+
+ def __eq__(self, other):
+ return self.addr == other.addr and self.prefixlen == other.prefixlen
+
+ def __hash__(self):
+ return self.addr.__hash__() + self.prefixlen.__hash__()
+
+class resource_range(resource):
- def __init__(self, car, cdr):
- self.car = car
- self.cdr = cdr
+ def __init__(self, min, max):
+ assert isinstance(min, resource) and isinstance(max, resource)
+ self.min = min
+ self.max = max
def __str__(self):
- return "(" + str(self.car) + " . " + str(self.cdr) + ")"
+ return str(self.min) + "-" + str(self.max)
def __eq__(self, other):
- return self.car == other.car and self.cdr == other.cdr
+ return self.min == other.min and self.max == other.max
def __hash__(self):
- return self.car.__hash__() + self.cdr.__hash__()
+ return self.min.__hash__() + self.max.__hash__()
class resource_set(set):
@@ -23,9 +70,9 @@ class resource_set(set):
set.__init__(self, elts)
def __str__(self):
- return "(" + " ".join(map(str, self)) + ")"
+ return "{" + ", ".join(map(str, self)) + "}"
-s = resource_set(resource("a", "b"), resource("c", "d"), resource("a", "b"))
+s = resource_set(ip_prefix(ipv6_address("fe80::"), 16), ip_prefix(ipv4_address("10.0.0.44"), 32))
print s