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
# 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:
<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>
"""
model = 'saas.SaaS'
script_executable = '/usr/bin/python'
monthly_sum_old_values = True
abstract = True
include_received_bytes = False
def prepare(self):
access_log = self.log_path
@ -26,6 +29,7 @@ class ApacheTrafficByHost(ServiceMonitor):
'access_logs': str((access_log, access_log+'.1')),
'current_date': self.current_date.strftime("%Y-%m-%d %H:%M:%S %Z"),
'ignore_hosts': str(settings.SAAS_TRAFFIC_IGNORE_HOSTS),
'include_received_bytes': str(self.include_received_bytes),
}
self.append(textwrap.dedent("""\
import sys
@ -65,6 +69,7 @@ class ApacheTrafficByHost(ServiceMonitor):
sites[site_domain] = [ini_date, object_id, 0]
def monitor(sites, end_date, months, access_logs):
include_received = {include_received_bytes}
for access_log in access_logs:
try:
with open(access_log, 'r') as handler:
@ -74,6 +79,9 @@ class ApacheTrafficByHost(ServiceMonitor):
if host in {ignore_hosts}:
continue
size, hostname = line[-2:]
size = int(size)
if include_received:
size += int(line[-3])
try:
site = sites[hostname]
except KeyError:
@ -84,7 +92,7 @@ class ApacheTrafficByHost(ServiceMonitor):
year, hour, min, sec = date.split(':')
date = year + months[month] + day + hour + min + sec
if site[0] < int(date) < end_date:
site[2] += int(size)
site[2] += size
except IOError as e:
sys.stderr.write(str(e)+'\\n')
for opts in sites.values():

View File

@ -16,12 +16,12 @@ class GitLabForm(SaaSPasswordForm):
class GitLaChangeForm(GitLabForm):
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):
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):

View File

@ -11,11 +11,9 @@ from ..forms import 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>"
"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):
super(WordPressForm, self).__init__(*args, **kwargs)
@ -25,15 +23,21 @@ class WordPressForm(SaaSBaseForm):
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):
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):
name = 'wordpress'
verbose_name = "WordPress"
form = WordPressForm
change_form = WordPressChangeForm
serializer = WordPressDataSerializer
icon = 'orchestra/icons/apps/WordPress.png'
change_readonly_fileds = ('email', 'blog_id')

View File

@ -72,7 +72,7 @@ class ProxmoxOVZ(ServiceController):
context['password'] = vps.password.replace('$', '\\$')
ssh_commands.append(textwrap.dedent("""\
echo 'root:%(password)s' \\
| chroot /var/lib/vz/private/${info[0]} chpasswd -e""") % context
| chroot /var/lib/vz/private/${info[0]} chpasswd -e""") % context
)
self.run_ssh_commands(ssh_commands)

View File

@ -28,7 +28,7 @@ class PluginDataForm(forms.ModelForm):
self.plugin_field: plugin_help_text or model_help_text
}
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
foo_display = getattr(self.instance, 'get_%s_display' % field, None)
if foo_display: