Merge branch 'master' of github.com:open-cloud/xos
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/hpc/admin.py b/xos/hpc/admin.py
index d171beb..9664d07 100644
--- a/xos/hpc/admin.py
+++ b/xos/hpc/admin.py
@@ -191,7 +191,7 @@
     verbose_name_plural = "HPC Service"
     list_display = ("backend_status_icon", "name","enabled")
     list_display_links = ('backend_status_icon', 'name', )
-    fieldsets = [(None, {'fields': ['backend_status_text', 'name','scale','enabled','versionNumber', 'description', "cmi_hostname"], 'classes':['suit-tab suit-tab-general']})]
+    fieldsets = [(None, {'fields': ['backend_status_text', 'name','scale','enabled','versionNumber', 'description', "cmi_hostname", "hpc_port80", "watcher_hpc_network", "watcher_dnsredir_network", "watcher_dnsdemux_network"], 'classes':['suit-tab suit-tab-general']})]
     readonly_fields = ('backend_status_text', )
     inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline]
     form = HpcServiceForm
diff --git a/xos/hpc/models.py b/xos/hpc/models.py
index 7ba0b34..c0f7ba9 100644
--- a/xos/hpc/models.py
+++ b/xos/hpc/models.py
@@ -17,6 +17,11 @@
 
     cmi_hostname = StrippedCharField(max_length=254, null=True, blank=True)
 
+    hpc_port80 = models.BooleanField(default=True, help_text="Enable port 80 for HPC")
+    watcher_hpc_network = StrippedCharField(max_length=254, null=True, blank=True, help_text="Network for hpc_watcher to contact hpc sliver")
+    watcher_dnsdemux_network = StrippedCharField(max_length=254, null=True, blank=True, help_text="Network for hpc_watcher to contact dnsdemux sliver")
+    watcher_dnsredir_network = StrippedCharField(max_length=254, null=True, blank=True, help_text="Network for hpc_watcher to contact dnsredir sliver")
+
     @property
     def scale(self):
         hpc_slices = [x for x in self.slices.all() if "hpc" in x.name]
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