Merge branch 'master' of ssh://git.planet-lab.org/git/plstackapi
diff --git a/planetstack/core/admin.py b/planetstack/core/admin.py
index 3ff973f..1d64d9c 100644
--- a/planetstack/core/admin.py
+++ b/planetstack/core/admin.py
@@ -21,12 +21,12 @@
 def backend_icon(obj): # backend_status, enacted, updated):
     #return "%s %s %s" % (str(obj.updated), str(obj.enacted), str(obj.backend_status))
     if (obj.enacted is not None) and obj.enacted >= obj.updated:
-        return '<img src="/static/admin/img/icon_success.gif">'
+        return '<span style="min-width:16px;"><img src="/static/admin/img/icon_success.gif"></span>'
     else:
         if obj.backend_status == "Provisioning in progress" or obj.backend_status=="":
-            return '<span title="%s"><img src="/static/admin/img/icon_clock.gif"></span>' % obj.backend_status
+            return '<span style="min-width:16px;" title="%s"><img src="/static/admin/img/icon_clock.gif"></span>' % obj.backend_status
         else:
-            return '<span title="%s"><img src="/static/admin/img/icon_error.gif"></span>' % obj.backend_status
+            return '<span style="min-width:16px;" title="%s"><img src="/static/admin/img/icon_error.gif"></span>' % obj.backend_status
 
 def backend_text(obj):
     icon = backend_icon(obj)
@@ -285,41 +285,6 @@
 
         return field
 
-"""
-    SMBAKER: This is the old code that implemented each network type as a
-    separate column in the sliver table.
-
-    def _declared_fieldsets(self):
-        # Return None so django will call get_fieldsets and we can insert our
-        # dynamic fields
-        return None
-
-    def get_readonly_fields(self, request, obj=None):
-        readonly_fields = list(super(SliverInline, self).get_readonly_fields(request, obj))
-
-        # Lookup the networks that are bound to the slivers, and add those
-        # network names to the list of readonly fields.
-
-        for sliver in obj.slivers.all():
-            for nbs in sliver.networksliver_set.all():
-                if nbs.ip:
-                    network_name = nbs.network.name
-                    if network_name not in [str(x) for x in readonly_fields]:
-                        readonly_fields.append(NetworkLookerUpper.get(network_name))
-
-        return readonly_fields
-
-    def get_fieldsets(self, request, obj=None):
-        form = self.get_formset(request, obj).form
-        # fields = the read/write files + the read-only fields
-        fields = list(self.fields)
-        for fieldName in self.get_readonly_fields(request,obj):
-            if not fieldName in fields:
-                fields.append(fieldName)
-
-        return [(None, {'fields': fields})]
-"""
-
 class SiteInline(PlStackTabularInline):
     model = Site
     extra = 0
@@ -764,12 +729,18 @@
             for deployment in flavor.deployments.all():
                 deployment_flavors.append( (deployment.id, flavor.id, flavor.name) )
 
+        deployment_images = []
+        for image in Image.objects.all():
+            for imageDeployment in image.imagedeployments_set.all():
+                deployment_images.append( (imageDeployment.deployment.id, image.id, image.name) )
+
         site_login_bases = []
         for site in Site.objects.all():
-            site_login_bases.append((site.id, site.login_base)) 
-        
+            site_login_bases.append((site.id, site.login_base))
+
         context["deployment_nodes"] = deployment_nodes
         context["deployment_flavors"] = deployment_flavors
+        context["deployment_images"] = deployment_images
         context["site_login_bases"] = site_login_bases
         return super(SliceAdmin, self).render_change_form(request, context, add, change, form_url, obj)
 
diff --git a/planetstack/core/views/legacyapi.py b/planetstack/core/views/legacyapi.py
index fa6ffb8..d7d77e4 100644
--- a/planetstack/core/views/legacyapi.py
+++ b/planetstack/core/views/legacyapi.py
@@ -158,8 +158,19 @@
             node_id = ps_id_to_pl_id(ps_sliver.node_id)
             if node_id in node_ids:
                 ps_node = ps_sliver.node
+
+                ip = socket.gethostbyname(ps_node.name)
+
+                # search for a dedicated public IP address
+                for networkSliver in ps_sliver.networksliver_set.all():
+                    if (not networkSliver.ip):
+                        continue
+                    template = networkSliver.network.template
+                    if (template.visibility=="public") and (template.translation=="none"):
+                        ip=networkSliver.ip
+
                 interface = {"node_id": node_id,
-                             "ip": socket.gethostbyname(ps_node.name),
+                             "ip": ip,
                              "broadcast": None,
                              "mac": "11:22:33:44:55:66",
                              "bwlimit": None,
diff --git a/planetstack/templates/admin/core/slice/change_form.html b/planetstack/templates/admin/core/slice/change_form.html
index 424a41b..31f09c0 100644
--- a/planetstack/templates/admin/core/slice/change_form.html
+++ b/planetstack/templates/admin/core/slice/change_form.html
@@ -14,20 +14,36 @@
 {% endfor %}
 ];
 
+deployment_images = [
+{% for dn in deployment_images %}
+   [{{ dn.0 }}, {{ dn.1 }} , "{{ dn.2 }}"],
+{% endfor %}
+];
+
 site_login_bases = [
 {% for s in site_login_bases %}
   [{{ s.0 }}, "{{ s.1 }}"],
 {% endfor %}
 ];
 
+function option_html(val, text, selected) {
+    if (selected) {
+        return '<option value="' + val + '" selected>' + text + '</option>\n';
+    } else {
+        return '<option value="' + val + '">' + text + '</option>\n';
+    }
+}
+
 function update_nodes(deployment_select, flavor_select, node_select) {
     deployment_id = $(deployment_select).val();
+    node_id = $(node_select).val();
     flavor_name = $(flavor_select).children(":selected").text()
     html="";
     for (i in deployment_nodes) {
+        // this is for EC2, where the node hostnames imply the flavor.
         dn = deployment_nodes[i];
         if ((dn[0] == deployment_id) && (dn[2].lastIndexOf(flavor_name,0) === 0)) {
-            html = html + '<option value="' + dn[1] + '">' + dn[2] + '</option>\n'
+            html = html + option_html(dn[1], dn[2], dn[1]==node_id);
         }
     }
     if (!html) {
@@ -35,28 +51,40 @@
         for (i in deployment_nodes) {
             dn = deployment_nodes[i];
             if (dn[0] == deployment_id) {
-                html = html + '<option value="' + dn[1] + '">' + dn[2] + '</option>\n'
+                html = html + option_html(dn[1], dn[2], dn[1]==node_id);
             }
         }
     }
     html = "<option value=''>---------</option>\n" + html;
-    //console.log(html);
     node_select.empty().append(html);
 }
 
 function update_flavors(deployment_select, flavor_select) {
     deployment_id = $(deployment_select).val();
+    flavor_id = $(flavor_select).val();
     html = "<option value=''>---------</option>\n";
     for (i in deployment_flavors) {
         dn = deployment_flavors[i];
         if (dn[0] == deployment_id) {
-            html = html + '<option value="' + dn[1] + '">' + dn[2] + '</option>\n'
+            html = html + option_html(dn[1], dn[2], dn[1] == flavor_id);
         }
     }
-    //console.log(html);
     flavor_select.empty().append(html);
 }
 
+function update_images(deployment_select, image_select) {
+    deployment_id = $(deployment_select).val();
+    image_id = $(image_select).val();
+    html = "<option value=''>---------</option>\n";
+    for (i in deployment_images) {
+        dn = deployment_images[i];
+        if (dn[0] == deployment_id) {
+            html = html + option_html(dn[1], dn[2], dn[1] == image_id);
+        }
+    }
+    image_select.empty().append(html);
+}
+
 function sliver_deployment_changed(any_control) {
    /* This function handles someone changing the deploymentNetwork control
       in the add-sliver line. It updats the flavors and nodes dialogs
@@ -73,8 +101,10 @@
     deployment_select = $("#" + $($(any_control).closest('tr')[0]).find('.field-deploymentNetwork select')[0].id);
     node_select = $("#" + $($(any_control).closest('tr')[0]).find('.field-node select')[0].id);
     flavor_select = $("#" + $($(any_control).closest('tr')[0]).find('.field-flavor select')[0].id);
+    image_select = $("#" + $($(any_control).closest('tr')[0]).find('.field-image select')[0].id);
     update_nodes(deployment_select, flavor_select, node_select);
     update_flavors(deployment_select, flavor_select);
+    update_images(deployment_select, image_select);
 }
 
 function sliver_flavor_changed(any_control) {