aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2011-04-25 19:03:58 +0000
committerRob Austein <sra@hactrn.net>2011-04-25 19:03:58 +0000
commit67007f9fbc049757190d6ce51a3f30256de0296c (patch)
treeeffc72bf3a6e286285b42b5f15c5aaca272a3ad2
parentfd3a615ddb621d82fc65278f1819444f0b1ce61b (diff)
Add renew_children command.
svn path=/rpkid/rpki/myrpki.py; revision=3788
-rw-r--r--rpkid/rpki/myrpki.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/rpkid/rpki/myrpki.py b/rpkid/rpki/myrpki.py
index ca8955e0..8951992e 100644
--- a/rpkid/rpki/myrpki.py
+++ b/rpkid/rpki/myrpki.py
@@ -1514,6 +1514,57 @@ class main(rpki.cli.Cmd):
def complete_delete_repository(self, *args):
return self.entitydb_complete("repositories", *args)
+
+ def renew_children_common(self, arg, plural):
+ """
+ Common code for renew_child and renew_all_children commands.
+ """
+
+ valid_until = None
+
+ opts, argv = getopt.getopt(arg.split(), "", ["valid_until"])
+ for o, a in opts:
+ if o == "--valid_until":
+ valid_until = a
+
+ if plural:
+ if len(argv) != 0:
+ raise RuntimeError, "Unexpected arguments"
+ children_glob = "*.xml"
+ else:
+ if len(argv) != 1:
+ raise RuntimeError, "Need to specify child handle"
+ children_glob = argv[0] + ".xml"
+
+ if valid_until is None:
+ valid_until = rpki.sundial.now() + rpki.sundial.timedelta(days = 365)
+ else:
+ valid_until = rpki.sundial.fromXMLtime(valid_until)
+ if valid_until < rpki.sundial.now():
+ raise RuntimeError, "Specified new expiration time %s has passed" % valid_until
+
+ print "New validity date", valid_until
+
+ for f in self.entitydb.iterate("children", children_glob):
+ c = etree_read(f)
+ c.set("valid_until", str(valid_until))
+ etree_write(c, f)
+
+ def do_renew_child(self, arg):
+ """
+ Update validity period for one child entity.
+ """
+ return self.renew_children_common(arg, False)
+
+ def complete_renew_child(self, *args):
+ return self.entitydb_complete("children", *args)
+
+ def do_renew_all_children(self, arg):
+ """
+ Update validity period for all child entities.
+ """
+ return self.renew_children_common(arg, True)
+