import ovs.unixctl.server
import ovs.vlog
from six.moves import range
+import six
vlog = ovs.vlog.Vlog("ovs-monitor-ipsec")
root_prefix = '' # Prefix for absolute file names, for testing.
# Class to configure the racoon daemon, which handles IKE negotiation
-class Racoon:
+class Racoon(object):
# Default locations for files
conf_file = "/etc/racoon/racoon.conf"
cert_dir = "/etc/racoon/certs"
conf_file = open(root_prefix + self.conf_file, 'w')
conf_file.write(Racoon.conf_header % (self.psk_file, self.cert_dir))
- for host, vals in self.cert_hosts.iteritems():
+ for host, vals in six.iteritems(self.cert_hosts):
conf_file.write(Racoon.cert_entry % (host, vals["certificate"],
vals["private_key"], vals["peer_cert_file"]))
conf_file.close()
# Rewrite the pre-shared keys file; it must only be readable by root.
- orig_umask = os.umask(0077)
+ orig_umask = os.umask(0o077)
psk_file = open(root_prefix + Racoon.psk_file, 'w')
os.umask(orig_umask)
psk_file.write("# Generated by Open vSwitch...do not modify by hand!")
psk_file.write("\n\n")
- for host, vals in self.psk_hosts.iteritems():
+ for host, vals in six.iteritems(self.psk_hosts):
psk_file.write("%s %s\n" % (host, vals["psk"]))
psk_file.close()
# Class to configure IPsec on a system using racoon for IKE and setkey
# for maintaining the Security Association Database (SAD) and Security
# Policy Database (SPD). Only policies for GRE are supported.
-class IPsec:
+class IPsec(object):
def __init__(self):
self.sad_flush()
self.spd_flush()
def update_ipsec(ipsec, interfaces, new_interfaces):
- for name, vals in interfaces.iteritems():
+ for name, vals in six.iteritems(interfaces):
if name not in new_interfaces:
ipsec.del_entry(vals["local_ip"], vals["remote_ip"])
- for name, vals in new_interfaces.iteritems():
+ for name, vals in six.iteritems(new_interfaces):
orig_vals = interfaces.get(name)
if orig_vals:
# Configuration for this host already exists. Check if it's
def get_ssl_cert(data):
- for ovs_rec in data["Open_vSwitch"].rows.itervalues():
+ for ovs_rec in data["Open_vSwitch"].rows.values():
if ovs_rec.ssl:
ssl = ovs_rec.ssl[0]
if ssl.certificate and ssl.private_key:
ssl_cert = get_ssl_cert(idl.tables)
new_interfaces = {}
- for rec in idl.tables["Interface"].rows.itervalues():
+ for rec in six.itervalues(idl.tables["Interface"].rows):
if rec.type == "ipsec_gre":
name = rec.name
options = rec.options