Skip to content

Commit

Permalink
portmapping admin so one can see the open ports; should fix container…
Browse files Browse the repository at this point in the history
… cloning2
  • Loading branch information
Michel Käser committed Aug 9, 2015
1 parent 237abf5 commit 27f4365
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
32 changes: 32 additions & 0 deletions ipynbsrv/admin/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,37 @@ def get_readonly_fields(self, request, obj=None):
return []


class PortMappingAdmin(admin.ModelAdmin):

"""
Admin model for the `PortMapping` model.
"""

list_display = ['container', 'external_port', 'internal_port']
list_filter = [
('container', admin.RelatedOnlyFieldListFilter),
'external_port',
'internal_port',
('server', admin.RelatedOnlyFieldListFilter),
]

fieldsets = [
('Server Properties', {
'fields': ['server', 'external_port']
}),
('Container Properties', {
'fields': ['container', 'internal_port']
})
]
readonly_fields = ['container', 'external_port', 'internal_port', 'server']

def has_add_permission(self, request):
"""
:inherit.
"""
return False


class ServerAdmin(admin.ModelAdmin):

"""
Expand Down Expand Up @@ -606,6 +637,7 @@ def has_add_permission(self, request):
admin_site.register(ContainerSnapshot, ContainerSnapshotAdmin)
admin_site.register(Group, GroupAdmin)
admin_site.register(Notification, NotificationAdmin)
admin_site.register(PortMapping, PortMappingAdmin)
admin_site.register(Server, ServerAdmin)
admin_site.register(Share, ShareAdmin)
admin_site.register(Tag, TagAdmin)
Expand Down
14 changes: 12 additions & 2 deletions ipynbsrv/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,8 +613,13 @@ def get_backend_base_url(self):
"""
base_url = None
if self.has_protected_port():
image = None
if self.is_image_based():
image = self.image
else:
image = self.clone_of.image
for port_mapping in self.port_mappings.all():
if port_mapping.internal_port == self.image.protected_port:
if port_mapping.internal_port == image.protected_port:
ip_and_port = port_mapping.server.internal_ip + ':' + str(port_mapping.external_port)
base_url = settings.CONTAINER_ACCESS_BASE_URI + ip_and_port.encode('hex') + '/'
break
Expand Down Expand Up @@ -649,7 +654,12 @@ def has_protected_port(self):
"""
Return `True` if the container is exposing a protected port.
"""
return self.image.protected_port is not None
has_protected_port = False
if self.is_image_based():
has_protected_port = self.image.protected_port is not None
elif self.is_clone() and self.clone_of.is_image_based():
has_protected_port = self.clone_of.image.protected_port is not None
return has_protected_port
has_protected_port.boolean = True

def is_clone(self):
Expand Down
1 change: 0 additions & 1 deletion ipynbsrv/core/signals/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ def create_on_server(sender, container, **kwargs):
elif container.is_clone() and container.clone_of.is_image_based():
clone_of = container.clone_of.backend_pk
cmd = container.clone_of.image.command
image = container.clone_of.image.backend_pk

result = None
try:
Expand Down

0 comments on commit 27f4365

Please sign in to comment.