summaryrefslogtreecommitdiff
path: root/extensions/hosts.configure
diff options
context:
space:
mode:
authorAdam Coldrick <adam.coldrick@codethink.co.uk>2015-06-04 15:17:44 +0000
committerAdam Coldrick <adam.coldrick@codethink.co.uk>2015-06-10 08:04:53 +0000
commitab90762d9a695118e7a89690c2f3b8c15e247a76 (patch)
treeb4227a6977d6e85a1830d1d97fa8087d9140dc94 /extensions/hosts.configure
parent20dfa465dd7a06c41947002b82ebb318168c18b2 (diff)
downloaddefinitions-ab90762d9a695118e7a89690c2f3b8c15e247a76.tar.gz
Remove dependencies on morphlib and cliapp from deployment extensionsbaserock/adamcoldrick/remove-dependencies
This is done by either copying or reimplementing relevant parts of morphlib/cliapp in extensions/writeexts.py, or by using functionality from the Python standard library instead where appropriate. Note that this means that these extensions will require "$definitions_checkout/extensions" in PYTHONPATH when they are run. This commit also updates VERSION to 6, since the PYTHONPATH requirement means that this change is incompatible with old versions of morph. Change-Id: Iec6fa7e3c7219619ce55e18493e5c37c36e97816
Diffstat (limited to 'extensions/hosts.configure')
-rwxr-xr-xextensions/hosts.configure12
1 files changed, 7 insertions, 5 deletions
diff --git a/extensions/hosts.configure b/extensions/hosts.configure
index 6b068d04..11fcf573 100755
--- a/extensions/hosts.configure
+++ b/extensions/hosts.configure
@@ -22,27 +22,29 @@ import os
import sys
import socket
-import morphlib
+import writeexts
def validate(var, line):
xs = line.split()
if len(xs) == 0:
- raise morphlib.Error("`%s: %s': line is empty" % (var, line))
+ raise writeexts.ExtensionError(
+ "`%s: %s': line is empty" % (var, line))
ip = xs[0]
hostnames = xs[1:]
if len(hostnames) == 0:
- raise morphlib.Error("`%s: %s': missing hostname" % (var, line))
+ raise writeexts.ExtensionError(
+ "`%s: %s': missing hostname" % (var, line))
family = socket.AF_INET6 if ':' in ip else socket.AF_INET
try:
socket.inet_pton(family, ip)
except socket.error:
- raise morphlib.Error("`%s: %s' invalid ip" % (var, ip))
+ raise writeexts.ExtensionError("`%s: %s' invalid ip" % (var, ip))
envvars = {k: v for (k, v) in os.environ.iteritems() if k.startswith('HOSTS_')}
conf_file = os.path.join(sys.argv[1], 'etc/hosts')
-morphlib.util.write_from_dict(conf_file, envvars, validate)
+writeexts.write_from_dict(conf_file, envvars, validate)