diff options
author | Rob Austein <sra@hactrn.net> | 2007-12-19 20:50:52 +0000 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2007-12-19 20:50:52 +0000 |
commit | bbfc95dcdfa3533e2ade77827a9fbd873e84cae5 (patch) | |
tree | 0a534327ed52bff00529a1cb3ff696f6dcedb324 /scripts | |
parent | 12770ee4c157cf898353bfb5d71d672ae7041aa2 (diff) |
Add delta computation to config generator
svn path=/scripts/testdb.py; revision=1395
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/testdb.py | 103 | ||||
-rw-r--r-- | scripts/testdb2.yaml | 7 |
2 files changed, 92 insertions, 18 deletions
diff --git a/scripts/testdb.py b/scripts/testdb.py index 82be644d..01781d39 100644 --- a/scripts/testdb.py +++ b/scripts/testdb.py @@ -5,17 +5,20 @@ import rpki.resource_set, os, yaml class allocation_db(list): def __init__(self, yaml): - allocation(yaml, self).closure() + self.root = allocation(yaml, self) + assert self.root.is_root() + self.root.closure() + self.map = dict((a.name, a) for a in self) for i, a in zip(range(len(self)), self): a.number = i - @classmethod - def from_file(cls, filename): - return cls(yaml.safe_load(open(filename))) + def get(self, name, default = None): + return self.map.get(name, default) - def dict_iter(self): - for a in self: - yield a.make_dict() + def apply_delta(self, delta): + for d in delta: + self.map[d["name"]].apply_delta(d) + self.root.closure() class allocation(object): @@ -39,14 +42,35 @@ class allocation(object): self.resources = resources return resources - def make_dict(self): + def apply_delta(self, yaml): + for k,v in yaml.items(): + if k != "name": + getattr(self, "apply_" + k)(v) + + def apply_add_as(self, text): + self.base.as = self.base.as.union(rpki.resource_set.resource_set_as(text)) + + def apply_add_v4(self, text): + self.base.v4 = self.base.v4.union(rpki.resource_set.resource_set_ipv4(text)) + + def apply_add_v6(self, text): + self.base.v6 = self.base.v6.union(rpki.resource_set.resource_set_ipv6(text)) + + def apply_sub_as(self, text): + self.base.as = self.base.as.difference(rpki.resource_set.resource_set_as(text)) + + def apply_sub_v4(self, text): + self.base.v4 = self.base.v4.difference(rpki.resource_set.resource_set_ipv4(text)) + + def apply_sub_v6(self, text): + self.base.v6 = self.base.v6.difference(rpki.resource_set.resource_set_ipv6(text)) + + def dict(self): return { "name" : self.name, - "parent" : None if self.parent is None else self.parent.name, - "kids" : [k.name for k in self.kids], "as" : self.resources.as, "v4" : self.resources.v4, "v6" : self.resources.v6, - "number" : self.number } + "number" : str(self.number) } def is_leaf(self): return not self.kids @@ -54,14 +78,57 @@ class allocation(object): def is_root(self): return self.parent is None -if __name__ == "__main__": - for d in allocation_db.from_file("testdb2.yaml").dict_iter(): - print ''' + def is_twig(self): + return self.parent is not None and self.kids + + def write_conf(self): + if self.is_twig(): + f = open(self.name + ".conf", "w") + f.write(conf_fmt % self.dict()) + f.close() + + def write_yaml(self): + if self.is_leaf(): + f = open(self.name + ".yaml", "w") + f.write(yaml_fmt % self.dict()) + f.close() + +dump_fmt = '''\ + #: %(number)s Name: %(name)s ASN: %(as)s IPv4: %(v4)s IPv6: %(v6)s -Rent: %(parent)s -Kids: %(kids)s - Num: %(number)s -''' % d +''' + +def dump(): + for a in db: + print dump_fmt % a.dict() + +y = [y for y in yaml.safe_load_all(open("testdb2.yaml"))] + +print "Loading", str(y[0]), "\n" + +db = allocation_db(y[0]) +dump() + +for delta in y[1:]: + print "Applying delta", str(delta), "\n" + db.apply_delta(delta) + dump() + +# Steps we need to take here +# +# 1: Construct config files for RPKId and IRDB instances +# 2: Initialize sql for RPKI and IRDB instances +# 3: Construct biz keys and certs for RPKI and IRDB instances +# 4: Populate IRDB(s) +# 5: Start RPKI and IRDB instances +# 6: Create objects in RPKI engines +# 7: Write YAML files for leaves +# 8: Start cycle: +# 8a: Run cron in all RPKI instances +# 8b: Run all YAML clients +# 8c: Read and apply next deltas from master YAML +# +# This is going to be ugly diff --git a/scripts/testdb2.yaml b/scripts/testdb2.yaml index c3b16901..88e4867f 100644 --- a/scripts/testdb2.yaml +++ b/scripts/testdb2.yaml @@ -66,3 +66,10 @@ kids: asn: 555-566 - name: Thad asn: 577-588 +--- +- name: Alice + add_as: 33 +--- +- name: Alice + sub_as: 33 + |