Add ability to update allowed_cidr for an existing instance.

Change-Id: I5e471554b30568bd96cb78d922767e644549c873
This commit is contained in:
Sam Morrison 2021-02-23 11:19:24 +11:00 committed by Lingxian Kong
parent 42d6638d3b
commit 26a40acc6e
4 changed files with 23 additions and 3 deletions

View File

@ -0,0 +1,4 @@
---
features:
- |
Added ability to update allowed_cidr for an existing instance.

View File

@ -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):

View File

@ -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)

View File

@ -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', '')}