Fixes on saas.wordpress service

This commit is contained in:
Marc Aymerich 2015-10-09 12:54:30 +00:00
parent 38a46b5983
commit ab43b6dfe7
6 changed files with 23 additions and 9 deletions

View File

@ -425,3 +425,5 @@ mkhomedir_helper or create ssh homes with bash.rc and such
# wordpressmu custom_url: set blog.domain # wordpressmu custom_url: set blog.domain
# validate_user on saas.wordpress to detect if username already exists before attempting to create a blog

View File

@ -13,12 +13,15 @@ class ApacheTrafficByHost(ServiceMonitor):
Compatible log format: Compatible log format:
<tt>LogFormat "%h %l %u %t \"%r\" %>s %O %{Host}i" host</tt> <tt>LogFormat "%h %l %u %t \"%r\" %>s %O %{Host}i" host</tt>
or if include_received_bytes:
<tt>LogFormat "%h %l %u %t \"%r\" %>s %I %O %{Host}i" host</tt>
<tt>CustomLog /home/pangea/logs/apache/host_blog.pangea.org.log host</tt> <tt>CustomLog /home/pangea/logs/apache/host_blog.pangea.org.log host</tt>
""" """
model = 'saas.SaaS' model = 'saas.SaaS'
script_executable = '/usr/bin/python' script_executable = '/usr/bin/python'
monthly_sum_old_values = True monthly_sum_old_values = True
abstract = True abstract = True
include_received_bytes = False
def prepare(self): def prepare(self):
access_log = self.log_path access_log = self.log_path
@ -26,6 +29,7 @@ class ApacheTrafficByHost(ServiceMonitor):
'access_logs': str((access_log, access_log+'.1')), 'access_logs': str((access_log, access_log+'.1')),
'current_date': self.current_date.strftime("%Y-%m-%d %H:%M:%S %Z"), 'current_date': self.current_date.strftime("%Y-%m-%d %H:%M:%S %Z"),
'ignore_hosts': str(settings.SAAS_TRAFFIC_IGNORE_HOSTS), 'ignore_hosts': str(settings.SAAS_TRAFFIC_IGNORE_HOSTS),
'include_received_bytes': str(self.include_received_bytes),
} }
self.append(textwrap.dedent("""\ self.append(textwrap.dedent("""\
import sys import sys
@ -65,6 +69,7 @@ class ApacheTrafficByHost(ServiceMonitor):
sites[site_domain] = [ini_date, object_id, 0] sites[site_domain] = [ini_date, object_id, 0]
def monitor(sites, end_date, months, access_logs): def monitor(sites, end_date, months, access_logs):
include_received = {include_received_bytes}
for access_log in access_logs: for access_log in access_logs:
try: try:
with open(access_log, 'r') as handler: with open(access_log, 'r') as handler:
@ -74,6 +79,9 @@ class ApacheTrafficByHost(ServiceMonitor):
if host in {ignore_hosts}: if host in {ignore_hosts}:
continue continue
size, hostname = line[-2:] size, hostname = line[-2:]
size = int(size)
if include_received:
size += int(line[-3])
try: try:
site = sites[hostname] site = sites[hostname]
except KeyError: except KeyError:
@ -84,7 +92,7 @@ class ApacheTrafficByHost(ServiceMonitor):
year, hour, min, sec = date.split(':') year, hour, min, sec = date.split(':')
date = year + months[month] + day + hour + min + sec date = year + months[month] + day + hour + min + sec
if site[0] < int(date) < end_date: if site[0] < int(date) < end_date:
site[2] += int(size) site[2] += size
except IOError as e: except IOError as e:
sys.stderr.write(str(e)+'\\n') sys.stderr.write(str(e)+'\\n')
for opts in sites.values(): for opts in sites.values():

View File

@ -16,12 +16,12 @@ class GitLabForm(SaaSPasswordForm):
class GitLaChangeForm(GitLabForm): class GitLaChangeForm(GitLabForm):
user_id = forms.IntegerField(label=("User ID"), widget=widgets.SpanWidget, user_id = forms.IntegerField(label=("User ID"), widget=widgets.SpanWidget,
help_text=_("ID of this user on the GitLab server, the only attribute that not changes.")) help_text=_("ID of this user used by GitLab, the only attribute that doesn't change."))
class GitLabSerializer(serializers.Serializer): class GitLabSerializer(serializers.Serializer):
email = serializers.EmailField(label=_("Email")) email = serializers.EmailField(label=_("Email"))
user_id = serializers.IntegerField(label=_("User ID"), required=False) user_id = serializers.IntegerField(label=_("User ID"), allow_null=True, required=False)
class GitLabService(SoftwareService): class GitLabService(SoftwareService):

View File

@ -11,11 +11,9 @@ from ..forms import SaaSBaseForm
class WordPressForm(SaaSBaseForm): class WordPressForm(SaaSBaseForm):
email = forms.EmailField(label=_("Email"), widget=forms.TextInput(attrs={'size':'40'}), email = forms.EmailField(label=_("Email"),
help_text=_("A new user will be created if the above email address is not in the database.<br>" help_text=_("A new user will be created if the above email address is not in the database.<br>"
"The username and password will be mailed to this email address.")) "The username and password will be mailed to this email address."))
blog_id = forms.IntegerField(label=("Blog ID"), widget=widgets.SpanWidget, required=False,
help_text=_("ID of this user on the GitLab server, the only attribute that not changes."))
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(WordPressForm, self).__init__(*args, **kwargs) super(WordPressForm, self).__init__(*args, **kwargs)
@ -25,15 +23,21 @@ class WordPressForm(SaaSBaseForm):
self.fields['site_url'].help_text = mark_safe(help_text) self.fields['site_url'].help_text = mark_safe(help_text)
class WordPressChangeForm(WordPressForm):
blog_id = forms.IntegerField(label=("Blog ID"), widget=widgets.SpanWidget, required=False,
help_text=_("ID of this blog used by WordPress, the only attribute that doesn't change."))
class WordPressDataSerializer(serializers.Serializer): class WordPressDataSerializer(serializers.Serializer):
email = serializers.EmailField(label=_("Email")) email = serializers.EmailField(label=_("Email"))
blog_id = serializers.IntegerField(label=_("Blog ID"), required=False) blog_id = serializers.IntegerField(label=_("Blog ID"), allow_null=True, required=False)
class WordPressService(SoftwareService): class WordPressService(SoftwareService):
name = 'wordpress' name = 'wordpress'
verbose_name = "WordPress" verbose_name = "WordPress"
form = WordPressForm form = WordPressForm
change_form = WordPressChangeForm
serializer = WordPressDataSerializer serializer = WordPressDataSerializer
icon = 'orchestra/icons/apps/WordPress.png' icon = 'orchestra/icons/apps/WordPress.png'
change_readonly_fileds = ('email', 'blog_id') change_readonly_fileds = ('email', 'blog_id')

View File

@ -28,7 +28,7 @@ class PluginDataForm(forms.ModelForm):
self.plugin_field: plugin_help_text or model_help_text self.plugin_field: plugin_help_text or model_help_text
} }
for field in self.plugin.get_change_readonly_fileds(): for field in self.plugin.get_change_readonly_fileds():
value = getattr(self.instance, field, None) or self.instance.data[field] value = getattr(self.instance, field, None) or self.instance.data.get(field)
display = value display = value
foo_display = getattr(self.instance, 'get_%s_display' % field, None) foo_display = getattr(self.instance, 'get_%s_display' % field, None)
if foo_display: if foo_display: