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

View File

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

View File

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

View File

@ -117,9 +117,6 @@ class UpdateForm(forms.SelfHandlingForm):
name = forms.CharField(label=_("Name"), required=False) name = forms.CharField(label=_("Name"), required=False)
admin_state = forms.BooleanField(label=_("Enable Admin State"), admin_state = forms.BooleanField(label=_("Enable Admin State"),
required=False) required=False)
router_id = forms.CharField(label=_("ID"),
widget=forms.TextInput(
attrs={'readonly': 'readonly'}))
mode = forms.ThemableChoiceField(label=_("Router Type")) mode = forms.ThemableChoiceField(label=_("Router Type"))
ha = forms.BooleanField(label=_("High Availability Mode"), required=False) ha = forms.BooleanField(label=_("High Availability Mode"), required=False)
@ -131,7 +128,7 @@ class UpdateForm(forms.SelfHandlingForm):
"dvr", "update") "dvr", "update")
if not self.dvr_allowed: if not self.dvr_allowed:
del self.fields['mode'] del self.fields['mode']
elif kwargs.get('initial', {}).get('mode') == 'distributed': elif self.initial.get('mode') == 'distributed':
# Neutron supports only changing from centralized to # Neutron supports only changing from centralized to
# distributed now. # distributed now.
mode_choices = [('distributed', _('Distributed'))] mode_choices = [('distributed', _('Distributed'))]
@ -159,13 +156,14 @@ class UpdateForm(forms.SelfHandlingForm):
params['distributed'] = (data['mode'] == 'distributed') params['distributed'] = (data['mode'] == 'distributed')
if self.ha_allowed: if self.ha_allowed:
params['ha'] = data['ha'] params['ha'] = data['ha']
router = api.neutron.router_update(request, data['router_id'], router = api.neutron.router_update(request,
self.initial['router_id'],
**params) **params)
msg = _('Router %s was successfully updated.') % data['name'] msg = _('Router %s was successfully updated.') % data['name']
messages.success(request, msg) messages.success(request, msg)
return router return router
except Exception as exc: except Exception as exc:
LOG.info('Failed to update router %(id)s: %(exc)s', 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'] msg = _('Failed to update router %s') % data['name']
exceptions.handle(request, msg, redirect=self.redirect_url) 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 " help_text=_("Specify an IP address for the interface "
"created (e.g. 192.168.0.254)."), "created (e.g. 192.168.0.254)."),
version=forms.IPv4 | forms.IPv6, mask=False) 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' failure_url = 'horizon:project:routers:detail'
def __init__(self, request, *args, **kwargs): def __init__(self, request, *args, **kwargs):
@ -49,8 +43,7 @@ class AddInterface(forms.SelfHandlingForm):
tenant_id = self.request.user.tenant_id tenant_id = self.request.user.tenant_id
networks = [] networks = []
router_subnet_ids = [] router_subnet_ids = []
router_id = request.GET.get('router_id', router_id = self.initial['router_id']
self.initial.get('router_id'))
try: try:
networks = api.neutron.network_list_for_tenant(request, tenant_id) networks = api.neutron.network_list_for_tenant(request, tenant_id)
@ -96,7 +89,7 @@ class AddInterface(forms.SelfHandlingForm):
return True return True
def _add_interface_by_subnet(self, request, data): def _add_interface_by_subnet(self, request, data):
router_id = data['router_id'] router_id = self.initial['router_id']
try: try:
router_inf = api.neutron.router_add_interface( router_inf = api.neutron.router_add_interface(
request, router_id, subnet_id=data['subnet_id']) request, router_id, subnet_id=data['subnet_id'])
@ -111,7 +104,7 @@ class AddInterface(forms.SelfHandlingForm):
return port return port
def _add_interface_by_port(self, request, data): def _add_interface_by_port(self, request, data):
router_id = data['router_id'] router_id = self.initial['router_id']
subnet_id = data['subnet_id'] subnet_id = data['subnet_id']
try: try:
subnet = api.neutron.subnet_get(request, subnet_id) subnet = api.neutron.subnet_get(request, subnet_id)
@ -152,12 +145,6 @@ class AddInterface(forms.SelfHandlingForm):
class SetGatewayForm(forms.SelfHandlingForm): class SetGatewayForm(forms.SelfHandlingForm):
network_id = forms.ThemableChoiceField(label=_("External Network")) 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' failure_url = 'horizon:project:routers:index'
def __init__(self, request, *args, **kwargs): def __init__(self, request, *args, **kwargs):
@ -187,14 +174,14 @@ class SetGatewayForm(forms.SelfHandlingForm):
def handle(self, request, data): def handle(self, request, data):
try: try:
api.neutron.router_add_gateway(request, api.neutron.router_add_gateway(request,
data['router_id'], self.initial['router_id'],
data['network_id']) data['network_id'])
msg = _('Gateway interface is added') msg = _('Gateway interface is added')
messages.success(request, msg) messages.success(request, msg)
return True return True
except Exception as e: except Exception as e:
LOG.info('Failed to set gateway to router %(id)s: %(exc)s', 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 msg = _('Failed to set gateway: %s') % e
redirect = reverse(self.failure_url) redirect = reverse(self.failure_url)
exceptions.handle(request, msg, redirect=redirect) exceptions.handle(request, msg, redirect=redirect)