summaryrefslogtreecommitdiffstats
path: root/mirrors
diff options
context:
space:
mode:
authorPyroPeter <abi1789@googlemail.com>2010-10-10 19:23:51 +0200
committerDan McGee <dan@archlinux.org>2010-10-14 01:42:51 +0200
commit28cc96af28bfb1318f97f37ab05b09dc9e5d11c5 (patch)
tree5faaea920d53cd7442553d2a6e1d5a2cbdd2186b /mirrors
parentc057b079c72a2329d8f365e07a0dce506c80e26b (diff)
downloadarchweb-28cc96af28bfb1318f97f37ab05b09dc9e5d11c5.tar.gz
archweb-28cc96af28bfb1318f97f37ab05b09dc9e5d11c5.tar.xz
Add mirrorresolv manage.py command
Dan: * Fix up some style issues such as spacing between operators * Ensure one failed lookup doesn't crash the whole script * Be silent out of the box if there are no errors, just like mirrorcheck Signed-off-by: PyroPeter <abi1789@googlemail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'mirrors')
-rw-r--r--mirrors/management/commands/mirrorresolv.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/mirrors/management/commands/mirrorresolv.py b/mirrors/management/commands/mirrorresolv.py
new file mode 100644
index 0000000..bcb24a5
--- /dev/null
+++ b/mirrors/management/commands/mirrorresolv.py
@@ -0,0 +1,55 @@
+# -*- coding: utf-8 -*-
+"""
+mirrorresolv command
+
+Poll all mirror URLs and determine whether they have IPv4 and/or IPv6 addresses
+available.
+
+Usage: ./manage.py mirrorresolv
+"""
+
+from django.core.management.base import NoArgsCommand
+
+import sys
+import logging
+from urlparse import urlparse
+import socket
+
+from mirrors.models import MirrorUrl
+
+logging.basicConfig(
+ level=logging.WARNING,
+ format='%(asctime)s -> %(levelname)s: %(message)s',
+ datefmt='%Y-%m-%d %H:%M:%S',
+ stream=sys.stderr)
+logger = logging.getLogger()
+
+class Command(NoArgsCommand):
+ help = "Runs a check on all active mirror URLs to determine if they are reachable via IPv4 and/or v6."
+
+ def handle_noargs(self, **options):
+ v = int(options.get('verbosity', 0))
+ if v == 0:
+ logger.level = logging.ERROR
+ elif v == 1:
+ logger.level = logging.WARNING
+ elif v == 2:
+ logger.level = logging.DEBUG
+
+ return resolve_mirrors()
+
+def resolve_mirrors():
+ logger.debug("requesting list of mirror URLs")
+ for mirrorurl in MirrorUrl.objects.filter(mirror__active=True):
+ try:
+ hostname = urlparse(mirrorurl.url).hostname
+ logger.debug("resolving %3i (%s)" % (mirrorurl.id, hostname))
+ info = socket.getaddrinfo(hostname, None, 0, socket.SOCK_STREAM)
+ families = [x[0] for x in info]
+ mirrorurl.has_ipv4 = socket.AF_INET in families
+ mirrorurl.has_ipv6 = socket.AF_INET6 in families
+ mirrorurl.save()
+ except socket.error, e:
+ logger.warn("error resolving %s: %s" % (hostname, e))
+
+# vim: set ts=4 sw=4 et: