configurable networks for hpc_watcher
diff --git a/xos/core/xoslib/methods/hpcview.py b/xos/core/xoslib/methods/hpcview.py
index 41f6051..005d7e1 100644
--- a/xos/core/xoslib/methods/hpcview.py
+++ b/xos/core/xoslib/methods/hpcview.py
@@ -67,6 +67,28 @@
return config_run
+# from hpc_watcher.py
+def get_public_ip(service, sliver):
+ network_name = None
+ if "hpc" in sliver.slice.name:
+ network_name = getattr(service, "watcher_hpc_network", None)
+ elif "demux" in sliver.slice.name:
+ network_name = getattr(service, "watcher_dnsdemux_network", None)
+ elif "redir" in sliver.slice.name:
+ network_name = getattr(service, "watcher_dnsredir_network", None)
+
+ if network_name and network_name.lower()=="nat":
+ return None
+
+ if (network_name is None) or (network_name=="") or (network_name.lower()=="public"):
+ return sliver.get_public_ip()
+
+ for ns in sliver.networkslivers.all():
+ if (ns.ip) and (ns.network.name==network_name):
+ return ns.ip
+
+ raise ValueError("Couldn't find network %s" % str(network_name))
+
def getHpcDict(user, pk):
hpc = HpcService.objects.get(pk=pk)
slices = get_service_slices(hpc)
@@ -106,10 +128,10 @@
print "no dnsdemux slice"
return
- dnsdemux_has_public_network = False
- for network in dnsdemux_slice.networks.all():
- if (network.template) and (network.template.visibility=="public") and (network.template.translation=="none"):
- dnsdemux_has_public_network = True
+ #dnsdemux_has_public_network = False
+ #for network in dnsdemux_slice.networks.all():
+ # if (network.template) and (network.template.visibility=="public") and (network.template.translation=="none"):
+ # dnsdemux_has_public_network = True
nameservers = {}
for nameserver in NAMESERVERS:
@@ -120,9 +142,12 @@
dnsdemux=[]
for sliver in dnsdemux_slice.slivers.all():
- if dnsdemux_has_public_network:
- ip = sliver.get_public_ip()
- else:
+ ip=None
+ try:
+ ip = get_public_ip(dnsdemux_service, sliver)
+ except Exception, e:
+ ip = "Exception: " + str(e)
+ if not ip:
try:
ip = socket.gethostbyname(sliver.node.name)
except:
diff --git a/xos/observers/hpc/hpc_watcher.py b/xos/observers/hpc/hpc_watcher.py
index 59d104a..177d17f 100644
--- a/xos/observers/hpc/hpc_watcher.py
+++ b/xos/observers/hpc/hpc_watcher.py
@@ -347,6 +347,27 @@
Thread.__init__(self)
self.daemon = True
+ def get_public_ip(self, service, sliver):
+ network_name = None
+ if "hpc" in sliver.slice.name:
+ network_name = getattr(service, "watcher_hpc_network", None)
+ elif "demux" in sliver.slice.name:
+ network_name = getattr(service, "watcher_dnsdemux_network", None)
+ elif "redir" in sliver.slice.name:
+ network_name = getattr(service, "watcher_dnsredir_network", None)
+
+ if network_name and network_name.lower()=="nat":
+ return None
+
+ if (network_name is None) or (network_name=="") or (network_name.lower()=="public"):
+ return sliver.get_public_ip()
+
+ for ns in sliver.networkslivers.all():
+ if (ns.ip) and (ns.network.name==network_name):
+ return ns.ip
+
+ raise ValueError("Couldn't find network %s" % str(network_name))
+
def set_status(self, sliver, service, kind, msg):
#print sliver.node.name, kind, msg
sliver.has_error = (msg!="success")
@@ -394,7 +415,11 @@
for sliver in slivers:
sliver.has_error = False
- ip = sliver.get_public_ip()
+ try:
+ ip = self.get_public_ip(service, sliver)
+ except Exception, e:
+ self.set_status(sliver, service, "watcher.DNS", "exception: %s" % str(e))
+ continue
if not ip:
try:
ip = socket.gethostbyname(sliver.node.name)
@@ -526,16 +551,20 @@
def fetch_watcher(self, service, slivers):
for sliver in slivers:
- ip = sliver.get_public_ip()
+ try:
+ ip = self.get_public_ip(service, sliver)
+ except Exception, e:
+ self.set_status(sliver, service, "watcher.watcher", json.dumps({"status": "exception: %s" % str(e)}) )
+ continue
if not ip:
try:
ip = socket.gethostbyname(sliver.node.name)
except:
- self.set_status(sliver, service, "watcher.watcher", "dns resolution failure")
+ self.set_status(sliver, service, "watcher.watcher", json.dumps({"status": "dns resolution failure"}) )
continue
if not ip:
- self.set_status(sliver, service, "watcher.watcher", "no IP address")
+ self.set_status(sliver, service, "watcher.watcher", json.dumps({"status": "no IP address"}) )
continue
port = 8015