From 2f06d536df1533ddcdf5ba29c0f13ca4e6e1c864 Mon Sep 17 00:00:00 2001
From: Henrik Thostrup Jensen <htj@nordu.net>
Date: Tue, 20 Dec 2011 12:48:42 +0100
Subject: [PATCH] add config.py module (forgot to add previously)

---
 opennsa/config.py | 56 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)
 create mode 100644 opennsa/config.py

diff --git a/opennsa/config.py b/opennsa/config.py
new file mode 100644
index 00000000..04da24e8
--- /dev/null
+++ b/opennsa/config.py
@@ -0,0 +1,56 @@
+"""
+Configuration reader and defaults.
+
+Author: Henrik Thostrup Jensen <htj@nordu.net>
+Copyright: NORDUnet (2011)
+"""
+
+import ConfigParser
+
+
+
+# defaults
+DEFAULT_CONFIG_FILE     = '/etc/opennsa.conf'
+DEFAULT_LOG_FILE        = '/var/log/opennsa.log'
+DEFAULT_TOPOLOGY_FILE   = '/usr/share/nsi/topology.owl'
+DEFAULT_WSDL_DIRECTORY  = '/usr/share/nsi/wsdl'
+DEFAULT_TCP_PORT        = 9080
+DEFAULT_TLS_PORT        = 9443
+DEFAULT_VERIFY          = 'true'
+
+
+# config blocks and options
+BLOCK_SERVICE    = 'service'
+BLOCK_DUD        = 'dud'
+BLOCK_JUNOS      = 'junos'
+BLOCK_ARGIA      = 'argia'
+
+# service block
+CONFIG_NETWORK_NAME     = 'network'     # mandatory
+CONFIG_HOST             = 'host'
+CONFIG_PORT             = 'port'
+CONFIG_TOPOLOGY_FILE    = 'topology'
+CONFIG_WSDL_DIRECTORY   = 'wsdl'
+
+CONFIG_HOSTKEY          = 'hostkey'     # mandatory
+CONFIG_HOSTCERT         = 'hostcert'    # mandatory
+CONFIG_CERTIFICATE_DIR  = 'certdir'     # mandatory (but dir can be empty)
+CONFIG_VERIFY           = 'verify'
+
+
+
+def readConfig(filename):
+
+    cfg = ConfigParser.SafeConfigParser()
+
+    # add defaults, only section so far
+    cfg.add_section(BLOCK_SERVICE)
+    cfg.set(BLOCK_SERVICE, CONFIG_LOG_FILE,         DEFAULT_LOG_FILE)
+    cfg.set(BLOCK_SERVICE, CONFIG_TOPOLOGY_FILE,    DEFAULT_TOPOLOGY_FILE)
+    cfg.set(BLOCK_SERVICE, CONFIG_WSDL_DIRECTORY,   DEFAULT_WSDL_DIRECTORY)
+    cfg.set(BLOCK_SERVICE, CONFIG_VERIFY,           DEFAULT_VERIFY)
+
+    cfg.read( [ filename ] )
+
+    return cfg
+
-- 
GitLab