xen-ips: silently ignore already-present IPs
authorGreg Price <price@mit.edu>
Sat, 2 May 2009 22:53:48 +0000 (18:53 -0400)
committerGreg Price <price@mit.edu>
Sat, 2 May 2009 22:53:48 +0000 (18:53 -0400)
Also from the first hours of April.  You all can imagine
how happy I was to be running this code. =)

svn path=/trunk/packages/invirt-web/; revision=2322

code/xen-ips

index 58f3078..b0b8fed 100755 (executable)
@@ -1,6 +1,7 @@
 #!/usr/bin/python
 import random
 from invirt import database
+import sqlalchemy.exceptions
 import sys
 
 # stolen directly from xend/server/netif.py
@@ -37,9 +38,12 @@ def usage():
     print >> sys.stderr, "USAGE: " + sys.argv[0] + " <ip>"
 
 def addip(ip):
-    n = database.NIC(machine=None, mac_addr=randomMAC(), ip=ip, hostname=None)
-    database.session.save(n)
-    database.session.flush()
+    try:
+        n = database.NIC(machine=None, mac_addr=randomMAC(), ip=ip, hostname=None)
+        database.session.save(n)
+        database.session.flush()
+    except sqlalchemy.exceptions.IntegrityError:
+        pass
 
 
 if __name__ == '__main__':