From 40695e188aa372bc00c02b83e49547d3875ad43d Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Thu, 13 Mar 2014 22:50:45 -0700 Subject: [PATCH] support for uploading files and serving them back via apache --- planetstack/planetstack/settings.py | 6 +++--- planetstack/planetstack/urls.py | 7 +++++++ planetstack/requestrouter/admin.py | 9 ++++++++- planetstack/requestrouter/models.py | 27 +++++++++++++++++++-------- 4 files changed, 37 insertions(+), 12 deletions(-) diff --git a/planetstack/planetstack/settings.py b/planetstack/planetstack/settings.py index c8da725..a19c591 100644 --- a/planetstack/planetstack/settings.py +++ b/planetstack/planetstack/settings.py @@ -3,7 +3,7 @@ from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS as TCP # Django settings for planetstack project. from config import Config config = Config() - + DEBUG = True TEMPLATE_DEBUG = DEBUG @@ -59,12 +59,12 @@ USE_TZ = True # Absolute filesystem path to the directory that will hold user-uploaded files. # Example: "/var/www/example.com/media/" -MEDIA_ROOT = '' +MEDIA_ROOT = '/var/www/html/files/' # URL that handles the media served from MEDIA_ROOT. Make sure to use a # trailing slash. # Examples: "http://example.com/media/", "http://media.example.com/" -MEDIA_URL = '' +MEDIA_URL = '/files/' # Absolute path to the directory static files should be collected to. # Don't put anything in this directory yourself; store your static files diff --git a/planetstack/planetstack/urls.py b/planetstack/planetstack/urls.py index 6c9acfa..99119e2 100644 --- a/planetstack/planetstack/urls.py +++ b/planetstack/planetstack/urls.py @@ -22,10 +22,16 @@ from core.models import * from core.api_root import api_root from rest_framework import generics from core.plus.sites import SitePlus +from django.http import HttpResponseRedirect admin.site = SitePlus() admin.autodiscover() +def redirect_to_apache(request): + """ bounce a request back to the apache server that is running on the machine """ + apache_url = "http://%s%s" % (request.META['HOSTNAME'], request.path) + return HttpResponseRedirect(apache_url) + urlpatterns = patterns('', # Examples: # url(r'^$', 'planetstack.views.home', name='home'), @@ -89,6 +95,7 @@ urlpatterns = patterns('', url(r'^legacyapi/$', 'core.views.legacyapi.LegacyXMLRPC', name='xmlrpc'), + url(r'^files/', redirect_to_apache), #Adding in rest_framework urls url(r'^plstackapi/', include('rest_framework.urls', namespace='rest_framework')), diff --git a/planetstack/requestrouter/admin.py b/planetstack/requestrouter/admin.py index 30b7fad..0036c4a 100644 --- a/planetstack/requestrouter/admin.py +++ b/planetstack/requestrouter/admin.py @@ -25,7 +25,14 @@ class RequestRouterServiceAdmin(SingletonAdmin): ('serviceattrs','Additional Attributes'), ) +class ServiceMapAdmin(SingletonAdmin): + model = ServiceMap + verbose_name = "Service Map" + verbose_name_plural = "Service Map" + list_display = ("name", "owner", "slice", "prefix") + #readonly_fields = ["name"] + admin.site.register(RequestRouterService, RequestRouterServiceAdmin) -admin.site.register(ClientMap) +admin.site.register(ServiceMap, ServiceMapAdmin) diff --git a/planetstack/requestrouter/models.py b/planetstack/requestrouter/models.py index 4350030..ced91cf 100644 --- a/planetstack/requestrouter/models.py +++ b/planetstack/requestrouter/models.py @@ -1,4 +1,4 @@ -from core.models import User,Site,Service,SingletonModel,PlCoreBase +from core.models import User,Site,Service,SingletonModel,PlCoreBase, Slice import os from django.db import models from django.forms.models import model_to_dict @@ -15,13 +15,24 @@ class RequestRouterService(SingletonModel,Service): defaultAction = models.CharField(max_length=30, default = "best", help_text="Review if this should be enum") lastResortAction = models.CharField(max_length=30, default = "random", help_text="Review if this should be enum") maxAnswers = models.PositiveIntegerField(default=3, help_text="Maximum number of answers in DNS response.") - + def __unicode__(self): return u'RequestRouterService' -class ClientMap(models.Model): - site = models.OneToOneField(Site, unique=True) - name = models.CharField(max_length=64, help_text="Name of the Client Map") - description = models.TextField(null=True, blank=True,max_length=130) +class ServiceMap(models.Model): + name = models.SlugField(max_length=50, unique=True, blank=False, null=False, help_text="name of this service map") + owner = models.ForeignKey(Service, help_text="service which owns this map") + slice = models.ForeignKey(Slice, help_text="slice that implements this service") + prefix = models.CharField(max_length=256, help_text="FQDN of the region of URI space managed by RR on behalf of this service") + siteMap = models.FileField(upload_to="maps/", help_text="maps client requests to service instances") + accessMap = models.FileField(upload_to="maps/", help_text="specifies which client requests are allowed") + + def siteMapName(self): + return self.name + ".site" + + def accessMapName(self): + return self.name + ".access" + + def __unicode__(self): return u'%s' % self.name + + - def __unicode__(self): return self.name - -- 2.43.0