Merge "Do not display UUID in network/rotuer forms"

This commit is contained in:
Jenkins 2017-06-13 10:52:20 +00:00 committed by Gerrit Code Review
commit b20a85deb2
6 changed files with 33 additions and 66 deletions

View File

@ -307,10 +307,6 @@ class CreateNetwork(forms.SelfHandlingForm):
class UpdateNetwork(forms.SelfHandlingForm):
name = forms.CharField(label=_("Name"), required=False)
tenant_id = forms.CharField(widget=forms.HiddenInput)
network_id = forms.CharField(label=_("ID"),
widget=forms.TextInput(
attrs={'readonly': 'readonly'}))
admin_state = forms.BooleanField(label=_("Enable Admin State"),
required=False)
shared = forms.BooleanField(label=_("Shared"), required=False)

View File

@ -95,13 +95,14 @@ class CreatePort(project_forms.CreatePort):
exceptions.handle(self.request, msg)
def handle(self, request, data):
network_id = self.initial['network_id']
try:
# We must specify tenant_id of the network which a subnet is
# created for if admin user does not belong to the tenant.
network = api.neutron.network_get(request, data['network_id'])
network = api.neutron.network_get(request, network_id)
params = {
'tenant_id': network.tenant_id,
'network_id': data['network_id'],
'network_id': network_id,
'admin_state_up': data['admin_state'],
'name': data['name'],
'device_id': data['device_id'],
@ -130,12 +131,10 @@ class CreatePort(project_forms.CreatePort):
messages.success(request, msg)
return port
except Exception as e:
net_id = data['network_id']
LOG.info('Failed to create a port for network %(id)s: %(exc)s',
{'id': net_id, 'exc': e})
msg = _('Failed to create a port for network %s') % net_id
redirect = reverse(self.failure_url,
args=(net_id,))
{'id': network_id, 'exc': e})
msg = _('Failed to create a port for network %s') % network_id
redirect = reverse(self.failure_url, args=(network_id,))
exceptions.handle(request, msg, redirect=redirect)
@ -162,6 +161,7 @@ class UpdatePort(project_forms.UpdatePort):
failure_url = 'horizon:admin:networks:detail'
def handle(self, request, data):
port_id = self.initial['port_id']
try:
LOG.debug('params = %s', data)
extension_kwargs = {}
@ -177,7 +177,7 @@ class UpdatePort(project_forms.UpdatePort):
data['port_security_enabled']
port = api.neutron.port_update(request,
data['port_id'],
port_id,
name=data['name'],
admin_state_up=data['admin_state'],
device_id=data['device_id'],
@ -186,13 +186,13 @@ class UpdatePort(project_forms.UpdatePort):
['binding__host_id'],
mac_address=data['mac_address'],
**extension_kwargs)
msg = _('Port %s was successfully updated.') % data['port_id']
msg = _('Port %s was successfully updated.') % port_id
messages.success(request, msg)
return port
except Exception as e:
LOG.info('Failed to update port %(id)s: %(exc)s',
{'id': data['port_id'], 'exc': e})
msg = _('Failed to update port %s') % data['port_id']
{'id': port_id, 'exc': e})
msg = _('Failed to update port %s') % port_id
redirect = reverse(self.failure_url,
args=[data['network_id']])
args=[self.initial['network_id']])
exceptions.handle(request, msg, redirect=redirect)

View File

@ -34,10 +34,6 @@ LOG = logging.getLogger(__name__)
class UpdateNetwork(forms.SelfHandlingForm):
name = forms.CharField(label=_("Name"), required=False)
tenant_id = forms.CharField(widget=forms.HiddenInput)
network_id = forms.CharField(label=_("ID"),
widget=forms.TextInput(
attrs={'readonly': 'readonly'}))
admin_state = forms.BooleanField(label=_("Enable Admin State"),
required=False)
shared = forms.BooleanField(label=_("Shared"), required=False)
@ -59,14 +55,14 @@ class UpdateNetwork(forms.SelfHandlingForm):
if policy.check((("network", "update_network:shared"),), request):
params['shared'] = data['shared']
network = api.neutron.network_update(request,
data['network_id'],
self.initial['network_id'],
**params)
msg = _('Network %s was successfully updated.') % data['name']
messages.success(request, msg)
return network
except Exception as e:
LOG.info('Failed to update network %(id)s: %(exc)s',
{'id': data['network_id'], 'exc': e})
{'id': self.initial['network_id'], 'exc': e})
msg = _('Failed to update network %s') % data['name']
redirect = reverse(self.failure_url)
exceptions.handle(request, msg, redirect=redirect)

View File

@ -34,13 +34,6 @@ VNIC_TYPES = [('normal', _('Normal')),
class CreatePort(forms.SelfHandlingForm):
network_name = forms.CharField(label=_("Network Name"),
widget=forms.TextInput(
attrs={'readonly': 'readonly'}),
required=False)
network_id = forms.CharField(label=_("Network ID"),
widget=forms.TextInput(
attrs={'readonly': 'readonly'}))
name = forms.CharField(max_length=255,
label=_("Name"),
required=False)
@ -131,7 +124,7 @@ class CreatePort(forms.SelfHandlingForm):
def handle(self, request, data):
try:
params = {
'network_id': data['network_id'],
'network_id': self.initial['network_id'],
'admin_state_up': data['admin_state'],
'name': data['name'],
'device_id': data['device_id'],
@ -163,19 +156,15 @@ class CreatePort(forms.SelfHandlingForm):
return port
except Exception as e:
LOG.info('Failed to create a port for network %(id)s: %(exc)s',
{'id': data['network_id'], 'exc': e})
{'id': self.initial['network_id'], 'exc': e})
msg = (_('Failed to create a port for network %s')
% data['network_id'])
% self.initial['network_id'])
redirect = reverse(self.failure_url,
args=(data['network_id'],))
args=(self.initial['network_id'],))
exceptions.handle(request, msg, redirect=redirect)
class UpdatePort(forms.SelfHandlingForm):
network_id = forms.CharField(widget=forms.HiddenInput())
port_id = forms.CharField(label=_("ID"),
widget=forms.TextInput(
attrs={'readonly': 'readonly'}))
name = forms.CharField(max_length=255,
label=_("Name"),
required=False)
@ -230,6 +219,7 @@ class UpdatePort(forms.SelfHandlingForm):
exceptions.handle(self.request, msg)
def handle(self, request, data):
port_id = self.initial['port_id']
try:
LOG.debug('params = %s', data)
extension_kwargs = {}
@ -243,17 +233,17 @@ class UpdatePort(forms.SelfHandlingForm):
data['port_security_enabled']
port = api.neutron.port_update(request,
data['port_id'],
port_id,
name=data['name'],
admin_state_up=data['admin_state'],
**extension_kwargs)
msg = _('Port %s was successfully updated.') % data['port_id']
msg = _('Port %s was successfully updated.') % port_id
messages.success(request, msg)
return port
except Exception as e:
LOG.info('Failed to update port %(id)s: %(exc)s',
{'id': data['port_id'], 'exc': e})
msg = _('Failed to update port %s') % data['port_id']
{'id': port_id, 'exc': e})
msg = _('Failed to update port %s') % port_id
redirect = reverse(self.failure_url,
args=[data['network_id']])
args=[self.initial['network_id']])
exceptions.handle(request, msg, redirect=redirect)

View File

@ -117,9 +117,6 @@ class UpdateForm(forms.SelfHandlingForm):
name = forms.CharField(label=_("Name"), required=False)
admin_state = forms.BooleanField(label=_("Enable Admin State"),
required=False)
router_id = forms.CharField(label=_("ID"),
widget=forms.TextInput(
attrs={'readonly': 'readonly'}))
mode = forms.ThemableChoiceField(label=_("Router Type"))
ha = forms.BooleanField(label=_("High Availability Mode"), required=False)
@ -131,7 +128,7 @@ class UpdateForm(forms.SelfHandlingForm):
"dvr", "update")
if not self.dvr_allowed:
del self.fields['mode']
elif kwargs.get('initial', {}).get('mode') == 'distributed':
elif self.initial.get('mode') == 'distributed':
# Neutron supports only changing from centralized to
# distributed now.
mode_choices = [('distributed', _('Distributed'))]
@ -159,13 +156,14 @@ class UpdateForm(forms.SelfHandlingForm):
params['distributed'] = (data['mode'] == 'distributed')
if self.ha_allowed:
params['ha'] = data['ha']
router = api.neutron.router_update(request, data['router_id'],
router = api.neutron.router_update(request,
self.initial['router_id'],
**params)
msg = _('Router %s was successfully updated.') % data['name']
messages.success(request, msg)
return router
except Exception as exc:
LOG.info('Failed to update router %(id)s: %(exc)s',
{'id': data['router_id'], 'exc': exc})
{'id': self.initial['router_id'], 'exc': exc})
msg = _('Failed to update router %s') % data['name']
exceptions.handle(request, msg, redirect=self.redirect_url)

View File

@ -32,12 +32,6 @@ class AddInterface(forms.SelfHandlingForm):
help_text=_("Specify an IP address for the interface "
"created (e.g. 192.168.0.254)."),
version=forms.IPv4 | forms.IPv6, mask=False)
router_name = forms.CharField(label=_("Router Name"),
widget=forms.TextInput(
attrs={'readonly': 'readonly'}))
router_id = forms.CharField(label=_("Router ID"),
widget=forms.TextInput(
attrs={'readonly': 'readonly'}))
failure_url = 'horizon:project:routers:detail'
def __init__(self, request, *args, **kwargs):
@ -49,8 +43,7 @@ class AddInterface(forms.SelfHandlingForm):
tenant_id = self.request.user.tenant_id
networks = []
router_subnet_ids = []
router_id = request.GET.get('router_id',
self.initial.get('router_id'))
router_id = self.initial['router_id']
try:
networks = api.neutron.network_list_for_tenant(request, tenant_id)
@ -96,7 +89,7 @@ class AddInterface(forms.SelfHandlingForm):
return True
def _add_interface_by_subnet(self, request, data):
router_id = data['router_id']
router_id = self.initial['router_id']
try:
router_inf = api.neutron.router_add_interface(
request, router_id, subnet_id=data['subnet_id'])
@ -111,7 +104,7 @@ class AddInterface(forms.SelfHandlingForm):
return port
def _add_interface_by_port(self, request, data):
router_id = data['router_id']
router_id = self.initial['router_id']
subnet_id = data['subnet_id']
try:
subnet = api.neutron.subnet_get(request, subnet_id)
@ -152,12 +145,6 @@ class AddInterface(forms.SelfHandlingForm):
class SetGatewayForm(forms.SelfHandlingForm):
network_id = forms.ThemableChoiceField(label=_("External Network"))
router_name = forms.CharField(label=_("Router Name"),
widget=forms.TextInput(
attrs={'readonly': 'readonly'}))
router_id = forms.CharField(label=_("Router ID"),
widget=forms.TextInput(
attrs={'readonly': 'readonly'}))
failure_url = 'horizon:project:routers:index'
def __init__(self, request, *args, **kwargs):
@ -187,14 +174,14 @@ class SetGatewayForm(forms.SelfHandlingForm):
def handle(self, request, data):
try:
api.neutron.router_add_gateway(request,
data['router_id'],
self.initial['router_id'],
data['network_id'])
msg = _('Gateway interface is added')
messages.success(request, msg)
return True
except Exception as e:
LOG.info('Failed to set gateway to router %(id)s: %(exc)s',
{'id': data['router_id'], 'exc': e})
{'id': self.initial['router_id'], 'exc': e})
msg = _('Failed to set gateway: %s') % e
redirect = reverse(self.failure_url)
exceptions.handle(request, msg, redirect=redirect)