Andrew Bogott has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/310962

Change subject: puppet panel:  Add a button to remove prefixes.
......................................................................

puppet panel:  Add a button to remove prefixes.

Bug: T91990
Change-Id: I6364cd347dcbb1e319c9acee65ac6affafb5a9f2
---
M modules/openstack/files/liberty/horizon/puppettab/prefixpanel/prefixpanel.py
M modules/openstack/files/liberty/horizon/puppettab/prefixpanel/urls.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/_detail_puppet.html
A 
modules/openstack/files/liberty/horizon/puppettab/templates/puppet/_removeprefix.html
A 
modules/openstack/files/liberty/horizon/puppettab/templates/puppet/removeprefix.html
M modules/openstack/files/liberty/horizon/puppettab/urls.py
M modules/openstack/files/liberty/horizon/puppettab/views.py
9 files changed, 135 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/62/310962/1

diff --git 
a/modules/openstack/files/liberty/horizon/puppettab/prefixpanel/prefixpanel.py 
b/modules/openstack/files/liberty/horizon/puppettab/prefixpanel/prefixpanel.py
index eb4e7dc..40b2fd6 100644
--- 
a/modules/openstack/files/liberty/horizon/puppettab/prefixpanel/prefixpanel.py
+++ 
b/modules/openstack/files/liberty/horizon/puppettab/prefixpanel/prefixpanel.py
@@ -63,12 +63,15 @@
         for prefix in prefixlist:
             # exclude anything with a '.' as those are instance names
             #  handled on a different UI
-            if '.' not in prefix:
-                tab_instances.append(("puppet-%s" % prefix,
-                                      PuppetTab(self,
-                                                self.request,
-                                                prefix=prefix,
-                                                tenant_id=self.tenant_id)))
+            if '.' in prefix:
+                continue
+            if prefix == '_':
+                continue
+            tab_instances.append(("puppet-%s" % prefix,
+                                  PuppetTab(self,
+                                            self.request,
+                                            prefix=prefix,
+                                            tenant_id=self.tenant_id)))
 
         # + tab
         tab_instances.append(('puppetprefixplus',
diff --git 
a/modules/openstack/files/liberty/horizon/puppettab/prefixpanel/urls.py 
b/modules/openstack/files/liberty/horizon/puppettab/prefixpanel/urls.py
index 1ec0683..7786188 100644
--- a/modules/openstack/files/liberty/horizon/puppettab/prefixpanel/urls.py
+++ b/modules/openstack/files/liberty/horizon/puppettab/prefixpanel/urls.py
@@ -32,4 +32,7 @@
     url(r'^(?P<tenantid>[^/]+)/'
         'newprefix$',
         prefixpanel.IndexView.as_view(), name='newprefix'),
+    url(r'^(?P<prefix>[^/]+)/(?P<tenantid>[^/]+)/'
+        'removepuppetprefix$',
+        views.RemovePrefixView.as_view(), name='removepuppetprefix'),
 )
diff --git a/modules/openstack/files/liberty/horizon/puppettab/puppet_config.py 
b/modules/openstack/files/liberty/horizon/puppettab/puppet_config.py
index 0fce354..deb078f 100644
--- a/modules/openstack/files/liberty/horizon/puppettab/puppet_config.py
+++ b/modules/openstack/files/liberty/horizon/puppettab/puppet_config.py
@@ -158,6 +158,15 @@
         self.refresh()
 
     @staticmethod
+    def delete_prefix(tenant_id, prefix):
+        apiurl = getattr(settings,
+                         "PUPPET_CONFIG_BACKEND",
+                         "http://labcontrol1001.wikimedia.org:8100/v1";)
+        prefixurl = "%s/%s/prefix/%s" % (apiurl, tenant_id, prefix)
+        req = requests.delete(prefixurl, verify=False)
+        req.raise_for_status()
+
+    @staticmethod
     def get_prefixes(tenant_id):
         apiurl = getattr(settings,
                          "PUPPET_CONFIG_BACKEND",
diff --git a/modules/openstack/files/liberty/horizon/puppettab/tab.py 
b/modules/openstack/files/liberty/horizon/puppettab/tab.py
index 9f880ac..e4591fc 100644
--- a/modules/openstack/files/liberty/horizon/puppettab/tab.py
+++ b/modules/openstack/files/liberty/horizon/puppettab/tab.py
@@ -36,6 +36,11 @@
     preload = False
 
     def __init__(self, *args, **kwargs):
+
+        # if prefix_tab is true we're going to display a
+        #  'delete prefix' button.
+        self.prefix_tab = False
+
         # For some reason our parent class can't deal with these
         #  args, so extract them now if they're present
         if 'prefix' in kwargs:
@@ -49,8 +54,9 @@
             del kwargs['tenant_id']
 
         if hasattr(self, 'tenant_id') and hasattr(self, 'prefix'):
+            self.prefix_tab = True
             self.caption = _("These puppet settings will affect all VMs in the"
-                             " %s project whose names begin with \'%s\'") % (
+                             " %s project whose names begin with \'%s\'.") % (
                 self.tenant_id, self.prefix)
 
         super(PuppetTab, self).__init__(*args, **kwargs)
@@ -67,7 +73,7 @@
             self.tenant_id = self.tab_group.kwargs['tenant_id']
             self.prefix = self.tab_group.kwargs['prefix']
             self.caption = _("These puppet settings will affect all VMs"
-                             " in the %s project") % self.tenant_id
+                             " in the %s project.") % self.tenant_id
 
         self.config = puppet_config(self.prefix, self.tenant_id)
 
@@ -75,6 +81,7 @@
         context = super(PuppetTab, self).get_context_data(request, **kwargs)
         context['prefix'] = self.prefix
         context['config'] = self.config
+        context['prefix_tab'] = self.prefix_tab
 
         if hasattr(self, 'caption'):
             context['caption'] = self.caption
@@ -88,6 +95,10 @@
         }
         context['edithieraurl'] = urlresolvers.reverse(url, kwargs=kwargs)
 
+        url = "horizon:project:puppet:removepuppetprefix"
+        context['removepuppetprefixurl'] = urlresolvers.reverse(url,
+                                                                kwargs=kwargs)
+
         return context
 
     def get_puppet_data(self):
diff --git 
a/modules/openstack/files/liberty/horizon/puppettab/templates/puppet/_detail_puppet.html
 
b/modules/openstack/files/liberty/horizon/puppettab/templates/puppet/_detail_puppet.html
index 1c0afa8..e0dfb39 100644
--- 
a/modules/openstack/files/liberty/horizon/puppettab/templates/puppet/_detail_puppet.html
+++ 
b/modules/openstack/files/liberty/horizon/puppettab/templates/puppet/_detail_puppet.html
@@ -1,6 +1,11 @@
 {% load i18n %}
 
+<br>
 {{ caption }}
+{% if prefix_tab %}
+<br>
+<a href="{{ removepuppetprefixurl }}" class="btn btn-primary ajax-modal">{% 
trans "Remove prefix" %}</a>
+{% endif %}
 
 <div class="row-fluid">
   <div class="span12">
@@ -9,3 +14,18 @@
   </div>
   {% include 'project/puppet/_hiera.html' %}
 </div>
+
+
+
+
+
+{% load i18n %}
+
+<div class="row-fluid">
+   <h3>{% trans "Hiera Config" %}</h3>
+   <p>
+     <pre>{{ config.hiera }}</pre>
+   </p>
+   <a href="{{ edithieraurl }}" class="btn btn-primary ajax-modal">{% trans 
"Edit" %}</a>
+</div>
+
diff --git 
a/modules/openstack/files/liberty/horizon/puppettab/templates/puppet/_removeprefix.html
 
b/modules/openstack/files/liberty/horizon/puppettab/templates/puppet/_removeprefix.html
new file mode 100644
index 0000000..00413aa
--- /dev/null
+++ 
b/modules/openstack/files/liberty/horizon/puppettab/templates/puppet/_removeprefix.html
@@ -0,0 +1,15 @@
+{% extends "horizon/common/_modal_form.html" %}
+{% load i18n horizon humanize %}
+
+{% block form_attrs %}enctype="multipart/form-data"{% endblock %}
+
+{% block modal-header %}{% trans "Remove" %} {{ prefix }} {% endblock %}
+
+{% block modal-body %}
+<div class="row">
+ <div class="col-sm-6" style="width: 100%">
+  <h3>{% trans "Are you sure you want to remove this prefix?" %}</h3>
+  {% trans "All hiera and puppet roles associated with this prefix will be 
discarded." %}
+ </div>
+</div>
+{% endblock %}
diff --git 
a/modules/openstack/files/liberty/horizon/puppettab/templates/puppet/removeprefix.html
 
b/modules/openstack/files/liberty/horizon/puppettab/templates/puppet/removeprefix.html
new file mode 100644
index 0000000..4ab70e4
--- /dev/null
+++ 
b/modules/openstack/files/liberty/horizon/puppettab/templates/puppet/removeprefix.html
@@ -0,0 +1,8 @@
+{% extends 'base.html' %}
+{% load i18n %}
+{% block title %}{% trans "Remove A Puppet Rule Prefix" %}{% endblock %}
+
+{% block main %}
+  {% include 'project/puppet/_remove.html' %}
+{% endblock %}
+
diff --git a/modules/openstack/files/liberty/horizon/puppettab/urls.py 
b/modules/openstack/files/liberty/horizon/puppettab/urls.py
index 0ef6456..0bacf79 100644
--- a/modules/openstack/files/liberty/horizon/puppettab/urls.py
+++ b/modules/openstack/files/liberty/horizon/puppettab/urls.py
@@ -29,4 +29,7 @@
     url(r'^(?P<prefix>[^/]+)/(?P<tenantid>[^/]+)/'
         'edithiera$',
         views.EditHieraView.as_view(), name='edithiera'),
+    url(r'^(?P<prefix>[^/]+)/(?P<tenantid>[^/]+)/'
+        'removepuppetprefix$',
+        views.RemovePrefixView.as_view(), name='removepuppetprefix'),
 )
diff --git a/modules/openstack/files/liberty/horizon/puppettab/views.py 
b/modules/openstack/files/liberty/horizon/puppettab/views.py
index b7115f0..a8b4222 100644
--- a/modules/openstack/files/liberty/horizon/puppettab/views.py
+++ b/modules/openstack/files/liberty/horizon/puppettab/views.py
@@ -201,4 +201,58 @@
     modal_header = _("Remove Role")
     submit_label = _("Remove")
     submit_url = "horizon:project:puppet:removepuppetrole"
-    template_name = "project/puppet/remove.html"
+    template_name = "project/puppet/removeprefix.html"
+
+
+class RemovePrefixForm(forms.SelfHandlingForm):
+    def __init__(self, request, *args, **kwargs):
+        super(RemovePrefixForm, self).__init__(request, *args, **kwargs)
+        initial = kwargs.get('initial', {})
+        self.tenant_id = initial['tenant_id']
+        self.prefix = initial['prefix']
+
+    def handle(self, request, data):
+        puppet_config.delete_prefix(self.tenant_id, self.prefix)
+        return True
+
+
+class RemovePrefixView(forms.ModalFormView):
+    form_class = RemovePrefixForm
+    form_id = "remove_prefix_form"
+    modal_header = _("Remove Prefix")
+    submit_label = _("Remove")
+    submit_url = "horizon:project:puppet:removepuppetprefix"
+    template_name = "project/puppet/removeprefix.html"
+
+    def get_prefix(self):
+        return self.kwargs['prefix']
+
+    def get_tenant_id(self):
+        return self.kwargs['tenantid']
+
+    def get_initial(self):
+        initial = {}
+        self.prefix = self.get_prefix()
+        self.tenant_id = self.get_tenant_id()
+        initial['prefix'] = self.prefix
+        initial['tenant_id'] = self.tenant_id
+
+        return initial
+
+    def get_context_data(self, **kwargs):
+        context = super(RemovePrefixView, self).get_context_data(**kwargs)
+        context['prefix'] = self.prefix
+        urlkwargs = {
+            'prefix': self.prefix,
+            'tenantid': self.tenant_id,
+        }
+        context['prefix'] = self.prefix
+        context['submit_url'] = urlresolvers.reverse(self.submit_url,
+                                                     kwargs=urlkwargs)
+        return context
+
+    def get_success_url(self):
+        validate = URLValidator()
+        refer = self.request.META.get('HTTP_REFERER', '/')
+        validate(refer)
+        return refer

-- 
To view, visit https://gerrit.wikimedia.org/r/310962
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6364cd347dcbb1e319c9acee65ac6affafb5a9f2
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Andrew Bogott <abog...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to