Edit instance name feature implementation
Change-Id: I29afd16c74087256788b3dc9f88d4e8eec4cba85
This commit is contained in:
parent
540b3e99d1
commit
88b1dc128f
4
releasenotes/notes/rename-instance-2bd17bdec7e1a488.yaml
Normal file
4
releasenotes/notes/rename-instance-2bd17bdec7e1a488.yaml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
Users can rename database instances via dashboard.
|
@ -192,6 +192,10 @@ def instance_restart(request, instance_id):
|
|||||||
return troveclient(request).instances.restart(instance_id)
|
return troveclient(request).instances.restart(instance_id)
|
||||||
|
|
||||||
|
|
||||||
|
def instance_rename(request, instance_id, name):
|
||||||
|
return troveclient(request).instances.update(instance_id, name=name)
|
||||||
|
|
||||||
|
|
||||||
def instance_detach_replica(request, instance_id):
|
def instance_detach_replica(request, instance_id):
|
||||||
return troveclient(request).instances.edit(instance_id,
|
return troveclient(request).instances.edit(instance_id,
|
||||||
detach_replica_source=True)
|
detach_replica_source=True)
|
||||||
|
@ -281,3 +281,28 @@ class AttachConfigurationForm(forms.SelfHandlingForm):
|
|||||||
'group.'),
|
'group.'),
|
||||||
redirect=redirect)
|
redirect=redirect)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
class RenameInstanceForm(forms.SelfHandlingForm):
|
||||||
|
instance_id = forms.CharField(widget=forms.HiddenInput())
|
||||||
|
instance_name = forms.CharField(label=_("Name"))
|
||||||
|
|
||||||
|
def __init__(self, request, *args, **kwargs):
|
||||||
|
super(RenameInstanceForm, self).__init__(request, *args, **kwargs)
|
||||||
|
instance_id = kwargs.get('initial', {}).get('instance_id')
|
||||||
|
self.fields['instance_id'].initial = instance_id
|
||||||
|
|
||||||
|
def handle(self, request, data):
|
||||||
|
instance_id = data.get('instance_id')
|
||||||
|
instance_name = data.get('instance_name')
|
||||||
|
try:
|
||||||
|
api.trove.instance_rename(request, instance_id, instance_name)
|
||||||
|
|
||||||
|
messages.success(request, _('Instance "%s" successfully renamed.')
|
||||||
|
% instance_name)
|
||||||
|
except Exception:
|
||||||
|
redirect = reverse("horizon:project:databases:index")
|
||||||
|
exceptions.handle(request, _('Unable to rename instance "%s".'
|
||||||
|
% instance_id),
|
||||||
|
redirect=redirect)
|
||||||
|
return True
|
||||||
|
@ -629,6 +629,17 @@ class StopDatabase(tables.BatchAction):
|
|||||||
return request.user.is_superuser and instance.status in ACTIVE_STATES
|
return request.user.is_superuser and instance.status in ACTIVE_STATES
|
||||||
|
|
||||||
|
|
||||||
|
class RenameInstance(tables.LinkAction):
|
||||||
|
name = "edit_instance"
|
||||||
|
verbose_name = _("Rename Instance")
|
||||||
|
url = "horizon:project:databases:edit_instance"
|
||||||
|
classes = ("btn-attach-config", "ajax-modal")
|
||||||
|
|
||||||
|
def allowed(self, request, instance=None):
|
||||||
|
return (instance.status in ACTIVE_STATES and
|
||||||
|
not hasattr(instance, 'configuration'))
|
||||||
|
|
||||||
|
|
||||||
class InstancesTable(tables.DataTable):
|
class InstancesTable(tables.DataTable):
|
||||||
STATUS_CHOICES = (
|
STATUS_CHOICES = (
|
||||||
("ACTIVE", True),
|
("ACTIVE", True),
|
||||||
@ -695,6 +706,7 @@ class InstancesTable(tables.DataTable):
|
|||||||
row_class = UpdateRow
|
row_class = UpdateRow
|
||||||
table_actions = (LaunchLink, DeleteInstance)
|
table_actions = (LaunchLink, DeleteInstance)
|
||||||
row_actions = (CreateBackup,
|
row_actions = (CreateBackup,
|
||||||
|
RenameInstance,
|
||||||
ResizeVolume,
|
ResizeVolume,
|
||||||
ResizeInstance,
|
ResizeInstance,
|
||||||
PromoteToReplicaSource,
|
PromoteToReplicaSource,
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
{% extends "horizon/common/_modal_form.html" %}
|
||||||
|
{% load i18n %}
|
||||||
|
|
||||||
|
{% block modal-body-right %}
|
||||||
|
<p>{% trans "Update instance name." %}</p>
|
||||||
|
{% endblock %}
|
@ -0,0 +1,5 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block main %}
|
||||||
|
{% include "project/databases/_rename_instance.html" %}
|
||||||
|
{% endblock %}
|
@ -28,6 +28,8 @@ urlpatterns = [
|
|||||||
url(r'^$', views.IndexView.as_view(), name='index'),
|
url(r'^$', views.IndexView.as_view(), name='index'),
|
||||||
url(r'^launch$', views.LaunchInstanceView.as_view(), name='launch'),
|
url(r'^launch$', views.LaunchInstanceView.as_view(), name='launch'),
|
||||||
url(INSTANCES % '', views.DetailView.as_view(), name='detail'),
|
url(INSTANCES % '', views.DetailView.as_view(), name='detail'),
|
||||||
|
url(INSTANCES % 'edit_instance', views.RenameInstanceView.as_view(),
|
||||||
|
name='edit_instance'),
|
||||||
url(INSTANCES % 'resize_volume', views.ResizeVolumeView.as_view(),
|
url(INSTANCES % 'resize_volume', views.ResizeVolumeView.as_view(),
|
||||||
name='resize_volume'),
|
name='resize_volume'),
|
||||||
url(INSTANCES % 'resize_instance', views.ResizeInstanceView.as_view(),
|
url(INSTANCES % 'resize_instance', views.ResizeInstanceView.as_view(),
|
||||||
|
@ -95,6 +95,41 @@ class LaunchInstanceView(horizon_workflows.WorkflowView):
|
|||||||
return initial
|
return initial
|
||||||
|
|
||||||
|
|
||||||
|
class RenameInstanceView(horizon_forms.ModalFormView):
|
||||||
|
form_class = forms.RenameInstanceForm
|
||||||
|
form_id = "attach_config_form"
|
||||||
|
modal_header = _("Rename Instance")
|
||||||
|
modal_id = "edit_instance_modal"
|
||||||
|
template_name = "project/databases/rename_instance.html"
|
||||||
|
submit_label = "Update"
|
||||||
|
submit_url = 'horizon:project:databases:edit_instance'
|
||||||
|
success_url = reverse_lazy('horizon:project:databases:index')
|
||||||
|
|
||||||
|
@memoized.memoized_method
|
||||||
|
def get_object(self, *args, **kwargs):
|
||||||
|
instance_id = self.kwargs['instance_id']
|
||||||
|
try:
|
||||||
|
return api.trove.instance_get(self.request, instance_id)
|
||||||
|
except Exception:
|
||||||
|
msg = _('Unable to retrieve instance details.')
|
||||||
|
redirect = reverse('horizon:project:databases:index')
|
||||||
|
exceptions.handle(self.request, msg, redirect=redirect)
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = (super(RenameInstanceView, self)
|
||||||
|
.get_context_data(**kwargs))
|
||||||
|
context['instance_id'] = self.kwargs['instance_id']
|
||||||
|
args = (self.kwargs['instance_id'],)
|
||||||
|
context['submit_url'] = reverse(self.submit_url, args=args)
|
||||||
|
return context
|
||||||
|
|
||||||
|
def get_initial(self):
|
||||||
|
instance = self.get_object()
|
||||||
|
return {'instance_id': self.kwargs['instance_id'],
|
||||||
|
'instance_name': instance.name,
|
||||||
|
'datastore_version': instance.datastore.get('version', '')}
|
||||||
|
|
||||||
|
|
||||||
class DBAccess(object):
|
class DBAccess(object):
|
||||||
def __init__(self, name, access):
|
def __init__(self, name, access):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
Loading…
x
Reference in New Issue
Block a user