+""" % (myname, strftime("%Y-%m-%d %H:%M:%S"), myname, password))
+ return
+
+
+"""
+Network used by OpenVPN on this node
+"""
+def openvpn_net(myid):
+ return "10.%s.0.0/16" % myid
+
+
+"""
+IP address of NAT gateway to outside world
+"""
+def nat_gw(key, myid):
+ return "10.%s.%s.1" % (key, myid)
+
+
+"""
+Write zebra.conf file for Quagga
+"""
+def write_zebra(filename, myname, ifaces, myid, key):
+ f = open(filename, 'w')
+ password = "zebra"
+ write_header(f, myname, password)
+
+ f.write ("enable password %s\n" % password)
+
+ for name in ifaces:
+ f.write ("""!
+interface %s
+link-detect
+""" % name)
+
+ f.write ("""!
+ip route %s %s
+!
+access-list vty permit 127.0.0.1/32
+!
+line vty
+!
+""" % (openvpn_net(myid), nat_gw(key, myid)))
+ f.close()
+ return
+
+
+"""
+Write ospfd.conf file for Quagga.
+"""
+def write_ospf(filename, myname, ifaces):
+ f = open(filename, 'w')
+ password = "zebra"
+ write_header(f, myname, password)
+
+ for name in ifaces:
+ f.write ("""!
+ interface %s
+ ip ospf cost 10
+ ip ospf hello-interval 5
+ ip ospf dead-interval 10
+ ip ospf network non-broadcast
+""" % name)
+
+ f.write ("""!
+ router ospf
+ ospf router-id %s
+""" % ifaces[name]['local-ip'])
+
+ for name in ifaces:
+ f.write (" neighbor %s\n" % ifaces[name]['remote-ip'])
+
+ for name in ifaces:
+ net = ifaces[name]['network']
+ f.write (" network %s area 0\n" % net)
+
+ f.write(""" redistribute static
+!
+access-list vty permit 127.0.0.1/32
+!
+line vty
+""")
+ return
+
+
+"""
+Write config files directly into the slice's file system.
+"""
+def update_quagga_configs(slicename, hostname, myid, topo, key, netns):
+ ifaces = get_ifaces(hostname, myid, topo, key)
+
+ quagga_dir = "/vservers/%s/etc/quagga/" % slicename
+ if not os.path.exists(quagga_dir):
+ try:
+ # Quagga not installed. Install it here? Chkconfig, sym links.
+ os.mkdir(quagga_dir)
+ except os.error:
+ logger.log("topo: could not create %s\n" % quagga_dir)
+ return
+
+ write_zebra(quagga_dir + "zebra.conf.generated", hostname, ifaces,
+ myid, key)
+ write_ospf(quagga_dir + "ospfd.conf.generated", hostname, ifaces)
+
+ # Start up Quagga if we installed it earlier and netns = 1.
+
+ return
+
+
+"""
+Write /etc/hosts in the sliver
+"""
+def update_hosts(slicename, hosts):
+ hosts_file = "/vservers/%s/etc/hosts" % slicename
+ f = open(hosts_file, 'w')
+ f.write(hosts)
+ f.close()
+ return