From 26a40acc6e641e449db1913edf46e899ecb13d09 Mon Sep 17 00:00:00 2001 From: Sam Morrison Date: Tue, 23 Feb 2021 11:19:24 +1100 Subject: [PATCH] Add ability to update allowed_cidr for an existing instance. Change-Id: I5e471554b30568bd96cb78d922767e644549c873 --- ...pdating-of-allowed-cidr-18d04641909ec3e3.yaml | 4 ++++ trove_dashboard/api/trove.py | 4 ++-- trove_dashboard/content/databases/forms.py | 16 +++++++++++++++- trove_dashboard/content/databases/views.py | 2 ++ 4 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/allow-updating-of-allowed-cidr-18d04641909ec3e3.yaml diff --git a/releasenotes/notes/allow-updating-of-allowed-cidr-18d04641909ec3e3.yaml b/releasenotes/notes/allow-updating-of-allowed-cidr-18d04641909ec3e3.yaml new file mode 100644 index 0000000..f005f0e --- /dev/null +++ b/releasenotes/notes/allow-updating-of-allowed-cidr-18d04641909ec3e3.yaml @@ -0,0 +1,4 @@ +--- +features: + - | + Added ability to update allowed_cidr for an existing instance. diff --git a/trove_dashboard/api/trove.py b/trove_dashboard/api/trove.py index 3ff20af..5fddaeb 100644 --- a/trove_dashboard/api/trove.py +++ b/trove_dashboard/api/trove.py @@ -200,8 +200,8 @@ def instance_restart(request, instance_id): return troveclient(request).instances.restart(instance_id) -def instance_update(request, instance_id, name=None): - return troveclient(request).instances.update(instance_id, name=name) +def instance_update(request, instance_id, **kwargs): + return troveclient(request).instances.update(instance_id, **kwargs) def instance_detach_replica(request, instance_id): diff --git a/trove_dashboard/content/databases/forms.py b/trove_dashboard/content/databases/forms.py index 74690cb..be376d4 100644 --- a/trove_dashboard/content/databases/forms.py +++ b/trove_dashboard/content/databases/forms.py @@ -286,6 +286,16 @@ class AttachConfigurationForm(forms.SelfHandlingForm): class UpdateInstanceForm(forms.SelfHandlingForm): instance_id = forms.CharField(widget=forms.HiddenInput()) instance_name = forms.CharField(label=_("Name")) + allowed_cidrs = forms.MultiIPField( + label=_("Allowed CIDRs"), + required=False, + help_text=_("Classless Inter-Domain Routing " + "(e.g. 192.168.0.0/24, or " + "2001:db8::/128). Can enter multiple values separating" + "by a comma"), + version=forms.IPv4 | forms.IPv6, + mask=True, + widget=forms.TextInput()) def __init__(self, request, *args, **kwargs): super(UpdateInstanceForm, self).__init__(request, *args, **kwargs) @@ -294,9 +304,13 @@ class UpdateInstanceForm(forms.SelfHandlingForm): def handle(self, request, data): instance_id = data.get('instance_id') + allowed_cidrs = data.get('allowed_cidrs') instance_name = data.get('instance_name') + update_kwargs = {'name': instance_name} + if allowed_cidrs: + update_kwargs['allowed_cidrs'] = allowed_cidrs.split(',') try: - api.trove.instance_update(request, instance_id, instance_name) + api.trove.instance_update(request, instance_id, **update_kwargs) messages.success(request, _('Instance "%s" successfully updated.') % instance_name) diff --git a/trove_dashboard/content/databases/views.py b/trove_dashboard/content/databases/views.py index 097dff9..3ed6fed 100644 --- a/trove_dashboard/content/databases/views.py +++ b/trove_dashboard/content/databases/views.py @@ -125,8 +125,10 @@ class UpdateInstanceView(horizon_forms.ModalFormView): def get_initial(self): instance = self.get_object() + allowed_cidrs = instance.access.get('allowed_cidrs', ['0.0.0.0/0']) return {'instance_id': self.kwargs['instance_id'], 'instance_name': instance.name, + 'allowed_cidrs': ','.join(allowed_cidrs), 'datastore_version': instance.datastore.get('version', '')}