[MediaWiki-commits] [Gerrit] operations/puppet[production]: Puppet Panel: Actually populate the prefix panel with prefi...
Andrew Bogott has submitted this change and it was merged. Change subject: Puppet Panel: Actually populate the prefix panel with prefixes. .. Puppet Panel: Actually populate the prefix panel with prefixes. Bug: T91990 Change-Id: I1a22aa6cad93da0bfe3c4f41748fd0a7566a1f61 --- M modules/openstack/files/liberty/horizon/puppettab/prefixpanel/plustab.py M modules/openstack/files/liberty/horizon/puppettab/prefixpanel/prefixpanel.py M modules/openstack/files/liberty/horizon/puppettab/puppet_config.py M modules/openstack/files/liberty/horizon/puppettab/tab.py M modules/openstack/files/liberty/horizon/puppettab/templates/puppet/plus_tab.html 5 files changed, 73 insertions(+), 43 deletions(-) Approvals: Andrew Bogott: Looks good to me, approved jenkins-bot: Verified diff --git a/modules/openstack/files/liberty/horizon/puppettab/prefixpanel/plustab.py b/modules/openstack/files/liberty/horizon/puppettab/prefixpanel/plustab.py index f4fdc4f..73b1776 100644 --- a/modules/openstack/files/liberty/horizon/puppettab/prefixpanel/plustab.py +++ b/modules/openstack/files/liberty/horizon/puppettab/prefixpanel/plustab.py @@ -14,11 +14,15 @@ #under the License. import logging +import re from django import template from django.template.loader import render_to_string from django.utils.translation import ugettext_lazy as _ +from wikimediapuppettab.puppet_config import puppet_config + +from horizon import exceptions from horizon import tabs logging.basicConfig() @@ -39,12 +43,22 @@ super(PlusTab, self).__init__(*args, **kwargs) def render(self): -LOG.warning("rendering, and logging is working") context = template.RequestContext(self.request) context['prefix_name'] = self.prefix_name return render_to_string(self.get_template_name(self.request), self.data, context_instance=context) def post(self, request, *args, **kwargs): -LOG.warning("We've got POST!") + +pattern = re.compile("^[A-Za-z][A-Za-z0-9_-]*$") +if not pattern.match(request.POST["prefix_name"]): +raise exceptions.BadRequest('Prefix must begin with a ' +'letter and contain only letters, ' +'numbers, _ or -.') + self.prefix_name = request.POST["prefix_name"] + +# set an empty role list for this prefix, to force a +# record creation on the back end. +config = puppet_config(self.prefix_name, self.tenant_id) +config.set_role_list([]) diff --git a/modules/openstack/files/liberty/horizon/puppettab/prefixpanel/prefixpanel.py b/modules/openstack/files/liberty/horizon/puppettab/prefixpanel/prefixpanel.py index 4bb05b4..eb4e7dc 100644 --- a/modules/openstack/files/liberty/horizon/puppettab/prefixpanel/prefixpanel.py +++ b/modules/openstack/files/liberty/horizon/puppettab/prefixpanel/prefixpanel.py @@ -24,6 +24,7 @@ from wikimediapuppettab.tab import PuppetTab from wikimediapuppettab.prefixpanel.plustab import PlusTab +from wikimediapuppettab.puppet_config import puppet_config logging.basicConfig() LOG = logging.getLogger(__name__) @@ -32,9 +33,6 @@ class PrefixPuppetPanel(horizon.Panel): name = _("Prefix Puppet") slug = "prefixpuppet" - -def handle(self, request, data): -LOG.warning('PrefixPuppetPanel is handling') class PrefixTabs(tabs.TabGroup): @@ -47,42 +45,44 @@ self.request = request self.kwargs = kwargs self._data = None -tab_instances = [] +self.request = request -tenant_id = self.request.user.tenant_id - -# demo #1 -prefix = 'prefixone' -tab_instances.append(("puppet-%s" % prefix, - PuppetTab(self, -request, -prefix=prefix, -tenant_id=tenant_id))) -# demo #2 -prefix = 'prefixtwo' -tab_instances.append(("puppet-%s" % prefix, - PuppetTab(self, -request, -prefix=prefix, -tenant_id=tenant_id))) -# + tab -tab_instances.append(('puppetprefixplus', - PlusTab(self, request, tenant_id=tenant_id))) - -self._tabs = OrderedDict(tab_instances) +self.tenant_id = self.request.user.tenant_id +self._tabs = OrderedDict(self.get_dynamic_tab_list()) if self.sticky: self.attrs['data-sticky-tabs'] = 'sticky' if not self._set_active_tab(): self.tabs_not_available() -def handle(self, request, data): -LOG.warning('PrefixTabs is handling') +def get_dynamic_tab_list(self): +prefixlist =
[MediaWiki-commits] [Gerrit] operations/puppet[production]: Puppet Panel: Actually populate the prefix panel with prefi...
Andrew Bogott has uploaded a new change for review. https://gerrit.wikimedia.org/r/310718 Change subject: Puppet Panel: Actually populate the prefix panel with prefixes. .. Puppet Panel: Actually populate the prefix panel with prefixes. Bug: T91990 Change-Id: I1a22aa6cad93da0bfe3c4f41748fd0a7566a1f61 --- M modules/openstack/files/liberty/horizon/puppettab/prefixpanel/plustab.py M modules/openstack/files/liberty/horizon/puppettab/prefixpanel/prefixpanel.py M modules/openstack/files/liberty/horizon/puppettab/puppet_config.py M modules/openstack/files/liberty/horizon/puppettab/tab.py M modules/openstack/files/liberty/horizon/puppettab/templates/puppet/plus_tab.html 5 files changed, 54 insertions(+), 36 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/operations/puppet refs/changes/18/310718/1 diff --git a/modules/openstack/files/liberty/horizon/puppettab/prefixpanel/plustab.py b/modules/openstack/files/liberty/horizon/puppettab/prefixpanel/plustab.py index f4fdc4f..c9f5640 100644 --- a/modules/openstack/files/liberty/horizon/puppettab/prefixpanel/plustab.py +++ b/modules/openstack/files/liberty/horizon/puppettab/prefixpanel/plustab.py @@ -14,11 +14,15 @@ #under the License. import logging +import re from django import template from django.template.loader import render_to_string from django.utils.translation import ugettext_lazy as _ +from wikimediapuppettab.puppet_config import puppet_config + +from horizon import exceptions from horizon import tabs logging.basicConfig() @@ -39,12 +43,20 @@ super(PlusTab, self).__init__(*args, **kwargs) def render(self): -LOG.warning("rendering, and logging is working") context = template.RequestContext(self.request) context['prefix_name'] = self.prefix_name return render_to_string(self.get_template_name(self.request), self.data, context_instance=context) def post(self, request, *args, **kwargs): -LOG.warning("We've got POST!") + +pattern = re.compile("^[A-Za-z][A-Za-z0-9_-]*$") +if not pattern.match(request.POST["prefix_name"]): +raise exceptions.BadRequest('Prefix must begin with a ' +'letter and contain only letters, ' +'numbers, _ or -.') + self.prefix_name = request.POST["prefix_name"] + +config = puppet_config(self.prefix_name, self.tenant_id) +config.set_hiera("") diff --git a/modules/openstack/files/liberty/horizon/puppettab/prefixpanel/prefixpanel.py b/modules/openstack/files/liberty/horizon/puppettab/prefixpanel/prefixpanel.py index 4bb05b4..5b60eec 100644 --- a/modules/openstack/files/liberty/horizon/puppettab/prefixpanel/prefixpanel.py +++ b/modules/openstack/files/liberty/horizon/puppettab/prefixpanel/prefixpanel.py @@ -24,6 +24,7 @@ from wikimediapuppettab.tab import PuppetTab from wikimediapuppettab.prefixpanel.plustab import PlusTab +from wikimediapuppettab.puppet_config import puppet_config logging.basicConfig() LOG = logging.getLogger(__name__) @@ -32,9 +33,6 @@ class PrefixPuppetPanel(horizon.Panel): name = _("Prefix Puppet") slug = "prefixpuppet" - -def handle(self, request, data): -LOG.warning('PrefixPuppetPanel is handling') class PrefixTabs(tabs.TabGroup): @@ -50,21 +48,19 @@ tab_instances = [] tenant_id = self.request.user.tenant_id +prefixlist = puppet_config.get_prefixes(tenant_id) +LOG.warning("prefixlist: %s" % prefixlist) -# demo #1 -prefix = 'prefixone' -tab_instances.append(("puppet-%s" % prefix, - PuppetTab(self, -request, -prefix=prefix, -tenant_id=tenant_id))) -# demo #2 -prefix = 'prefixtwo' -tab_instances.append(("puppet-%s" % prefix, - PuppetTab(self, -request, -prefix=prefix, -tenant_id=tenant_id))) +# One tab per prefix +for prefix in prefixlist: +# exclude anything with a '.' as those are instance names +if '.' not in prefix: +tab_instances.append(("puppet-%s" % prefix, + PuppetTab(self, +request, +prefix=prefix, +tenant_id=tenant_id))) + # + tab tab_instances.append(('puppetprefixplus', PlusTab(self, request, tenant_id=tenant_id))) @@ -75,14 +71,8 @@ if not self._set_active_tab():