+# post processing for gre mode
+if opt_gre:
+ if not opt_pointopoint:
+ print >>sys.stderr, "GRE tunnels need a pointopoint address"
+ sys.exit(1)
+ if not opt_gre_remote:
+ print >>sys.stderr, "GRE tunnels need a pointopoint address"
+ sys.exit(1)
+
+ if vif.startswith('tun'):
+ opt_gre_type = 'gre'
+ else:
+ opt_gre_type = 'gretap'
+
+ opt_gre=opt_gre.lower()
+ # helper - keys are expected between 0 and 2**32-1
+ def gre_hash (string):
+ return hash(string) & 0xffffffff
+ # compute gre_key according to option format
+ if opt_gre in ('yes','true','name'):
+ gre_key=gre_hash(slicename)
+ elif opt_gre in ('id','sliceid'):
+ # use slice_id as the key - this is the one from myplc - won't work across federation
+ gre_key = int(open("/etc/vservers/%s/slice_id" % (slicename,),"r").read().strip())
+ elif opt_gre.isdigit():
+ # use as-is
+ gre_key=int(opt_gre)
+ else:
+ # hash the provided string
+ gre_key=gre_hash(opt_gre)
+ ### temporary - debug
+ ### use ip tunnel show to obtain the key, but it only works with IP over GRE
+ #open('/tmp/%s.key'%vif,'w').write('%s\n'%gre_key)
+